OmniSciDB  0fdbebe030
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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::Expr
generate () const
 

Static Public Member Functions

static std::shared_ptr
< Analyzer::Expr
generate (const std::shared_ptr< Analyzer::Expr >, const std::string &)
 
static std::shared_ptr
< Analyzer::Expr
generate (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::Constant
getNumericConstant (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 102 of file DateTimeTranslator.h.

Constructor & Destructor Documentation

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

Definition at line 104 of file DateTimeTranslator.h.

105  : 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::DateTruncExpr ( const std::shared_ptr< Analyzer::Expr expr,
const std::string &  field 
)
inline

Definition at line 106 of file DateTimeTranslator.h.

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)

Member Function Documentation

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

Definition at line 222 of file DateTimeTranslator.cpp.

References field(), generate(), and to_datetrunc_field().

224  {
225  const auto field = to_datetrunc_field(field_name);
226  return DateTruncExpr::generate(from_expr, field);
227 }
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)
const std::shared_ptr< Analyzer::Expr > generate() const

+ Here is the call graph for this function:

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

Definition at line 229 of file DateTimeTranslator.cpp.

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

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

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

Definition at line 114 of file DateTimeTranslator.h.

References generate_loop_ref::generate().

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

114  {
115  return generate(from_expr_, field_);
116  }
std::shared_ptr< Analyzer::Expr > from_expr_
DatetruncField field_
const std::shared_ptr< Analyzer::Expr > generate() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 184 of file DateTimeTranslator.cpp.

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

Referenced by generate().

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

+ Here is the caller graph for this function:

Member Data Documentation

DatetruncField DateTruncExpr::field_
private

Definition at line 122 of file DateTimeTranslator.h.

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

Definition at line 121 of file DateTimeTranslator.h.


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