OmniSciDB  f632821e96
DateTruncExpr Class Reference

#include <DateTimeTranslator.h>

+ Inheritance diagram for DateTruncExpr:
+ Collaboration diagram for DateTruncExpr:

Public Member Functions

 DateTruncExpr (const std::shared_ptr< Analyzer::Expr > expr, const DatetruncField &field)
 
 DateTruncExpr (const std::shared_ptr< Analyzer::Expr > expr, const std::string &field)
 
const std::shared_ptr< Analyzer::Exprgenerate () const
 

Static Public Member Functions

static std::shared_ptr< Analyzer::Exprgenerate (const std::shared_ptr< Analyzer::Expr >, const std::string &)
 
static std::shared_ptr< Analyzer::Exprgenerate (const std::shared_ptr< Analyzer::Expr >, const DatetruncField &)
 

Static Private Member Functions

static DatetruncField to_datetrunc_field (const std::string &field)
 

Private Attributes

std::shared_ptr< Analyzer::Exprfrom_expr_
 
DatetruncField field_
 

Additional Inherited Members

- Static Protected Member Functions inherited from DateTimeTranslator
static std::shared_ptr< Analyzer::ConstantgetNumericConstant (const int64_t scale)
 
static int64_t getExtractFromTimeConstantValue (const int64_t &timeval, const ExtractField &field, const SQLTypeInfo &ti)
 
static int64_t getDateTruncConstantValue (const int64_t &timeval, const DatetruncField &field, const SQLTypeInfo &ti)
 

Detailed Description

Definition at line 105 of file DateTimeTranslator.h.

Constructor & Destructor Documentation

◆ DateTruncExpr() [1/2]

DateTruncExpr::DateTruncExpr ( const std::shared_ptr< Analyzer::Expr expr,
const DatetruncField field 
)
inline

Definition at line 107 of file DateTimeTranslator.h.

108  : from_expr_(expr), field_(field) {}
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
std::shared_ptr< Analyzer::Expr > from_expr_
DatetruncField field_

◆ DateTruncExpr() [2/2]

DateTruncExpr::DateTruncExpr ( const std::shared_ptr< Analyzer::Expr expr,
const std::string &  field 
)
inline

Definition at line 109 of file DateTimeTranslator.h.

References generate_loop_ref::generate().

const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
std::shared_ptr< Analyzer::Expr > from_expr_
DatetruncField field_
static DatetruncField to_datetrunc_field(const std::string &field)
+ Here is the call graph for this function:

Member Function Documentation

◆ generate() [1/3]

std::shared_ptr< Analyzer::Expr > DateTruncExpr::generate ( const std::shared_ptr< Analyzer::Expr from_expr,
const std::string &  field_name 
)
static

Definition at line 223 of file DateTimeTranslator.cpp.

References field(), and generate().

225  {
226  const auto field = to_datetrunc_field(field_name);
227  return DateTruncExpr::generate(from_expr, field);
228 }
const std::shared_ptr< Analyzer::Expr > generate() const
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
static DatetruncField to_datetrunc_field(const std::string &field)
+ Here is the call graph for this function:

◆ generate() [2/3]

std::shared_ptr< Analyzer::Expr > DateTruncExpr::generate ( const std::shared_ptr< Analyzer::Expr from_expr,
const DatetruncField field 
)
static

Definition at line 230 of file DateTimeTranslator.cpp.

References Datum::bigintval, dtHOUR, dtMINUTE, dtSECOND, field(), anonymous_namespace{DateTimeTranslator.cpp}::from_datetrunc_field(), kTIME, and kTIMESTAMP.

232  {
233  const auto& expr_ti = from_expr->get_type_info();
234  if (!expr_ti.is_time()) {
235  throw std::runtime_error(
236  "Only TIME, TIMESTAMP and DATE types can be in DATE_TRUNC function.");
237  }
238  if (from_expr->get_type_info().get_type() == kTIME && field != dtHOUR &&
239  field != dtMINUTE && field != dtSECOND) {
240  throw std::runtime_error("Cannot DATE_TRUNC " + from_datetrunc_field(field) +
241  " from TIME.");
242  }
243  SQLTypeInfo ti(kTIMESTAMP, expr_ti.get_dimension(), 0, expr_ti.get_notnull());
244  auto constant = std::dynamic_pointer_cast<Analyzer::Constant>(from_expr);
245  if (constant) {
246  Datum d{0};
247  d.bigintval =
248  getDateTruncConstantValue(constant->get_constval().bigintval, field, expr_ti);
249  constant->set_constval(d);
250  constant->set_type_info(ti);
251  return constant;
252  }
253  return makeExpr<Analyzer::DatetruncExpr>(
254  ti, from_expr->get_contains_agg(), field, from_expr->decompress());
255 }
Definition: sqltypes.h:51
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
int64_t bigintval
Definition: sqltypes.h:138
std::string from_datetrunc_field(const DatetruncField &fieldno)
static int64_t getDateTruncConstantValue(const int64_t &timeval, const DatetruncField &field, const SQLTypeInfo &ti)
+ Here is the call graph for this function:

◆ generate() [3/3]

const std::shared_ptr<Analyzer::Expr> DateTruncExpr::generate ( ) const
inline

Definition at line 117 of file DateTimeTranslator.h.

References field(), and generate_loop_ref::generate().

Referenced by generate(), rewrite_to_date_trunc(), and RelAlgTranslator::translateExtract().

117  {
118  return generate(from_expr_, field_);
119  }
const std::shared_ptr< Analyzer::Expr > generate() const
std::shared_ptr< Analyzer::Expr > from_expr_
DatetruncField field_
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ to_datetrunc_field()

DatetruncField DateTruncExpr::to_datetrunc_field ( const std::string &  field)
staticprivate

Definition at line 185 of file DateTimeTranslator.cpp.

References dtCENTURY, dtDAY, dtDECADE, dtHOUR, dtMICROSECOND, dtMILLENNIUM, dtMILLISECOND, dtMINUTE, dtMONTH, dtNANOSECOND, dtQUARTER, dtQUARTERDAY, dtSECOND, dtWEEK, and dtYEAR.

185  {
186  DatetruncField fieldno;
187  if (boost::iequals(field, "year")) {
188  fieldno = dtYEAR;
189  } else if (boost::iequals(field, "quarter")) {
190  fieldno = dtQUARTER;
191  } else if (boost::iequals(field, "month")) {
192  fieldno = dtMONTH;
193  } else if (boost::iequals(field, "quarterday")) {
194  fieldno = dtQUARTERDAY;
195  } else if (boost::iequals(field, "day")) {
196  fieldno = dtDAY;
197  } else if (boost::iequals(field, "hour")) {
198  fieldno = dtHOUR;
199  } else if (boost::iequals(field, "minute")) {
200  fieldno = dtMINUTE;
201  } else if (boost::iequals(field, "second")) {
202  fieldno = dtSECOND;
203  } else if (boost::iequals(field, "millennium")) {
204  fieldno = dtMILLENNIUM;
205  } else if (boost::iequals(field, "century")) {
206  fieldno = dtCENTURY;
207  } else if (boost::iequals(field, "decade")) {
208  fieldno = dtDECADE;
209  } else if (boost::iequals(field, "millisecond")) {
210  fieldno = dtMILLISECOND;
211  } else if (boost::iequals(field, "microsecond")) {
212  fieldno = dtMICROSECOND;
213  } else if (boost::iequals(field, "nanosecond")) {
214  fieldno = dtNANOSECOND;
215  } else if (boost::iequals(field, "week")) {
216  fieldno = dtWEEK;
217  } else {
218  throw std::runtime_error("Invalid field in DATE_TRUNC function " + field);
219  }
220  return fieldno;
221 }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
DatetruncField
Definition: DateTruncate.h:27

Member Data Documentation

◆ field_

DatetruncField DateTruncExpr::field_
private

Definition at line 125 of file DateTimeTranslator.h.

◆ from_expr_

std::shared_ptr<Analyzer::Expr> DateTruncExpr::from_expr_
private

Definition at line 124 of file DateTimeTranslator.h.


The documentation for this class was generated from the following files: