OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 105 of file DateTimeTranslator.h.

Constructor & Destructor Documentation

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:33
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 109 of file DateTimeTranslator.h.

const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
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 239 of file DateTimeTranslator.cpp.

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

241  {
242  const auto field = to_datetrunc_field(field_name);
243  return DateTruncExpr::generate(from_expr, field);
244 }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
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 246 of file DateTimeTranslator.cpp.

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

248  {
249  const auto& expr_ti = from_expr->get_type_info();
250  if (!expr_ti.is_time()) {
251  throw std::runtime_error(
252  "Only TIME, TIMESTAMP and DATE types can be in DATE_TRUNC function.");
253  }
254  if (from_expr->get_type_info().get_type() == kTIME && field != dtHOUR &&
255  field != dtMINUTE && field != dtSECOND) {
256  throw std::runtime_error("Cannot DATE_TRUNC " + from_datetrunc_field(field) +
257  " from TIME.");
258  }
259  SQLTypeInfo ti(kTIMESTAMP, expr_ti.get_dimension(), 0, expr_ti.get_notnull());
260  auto constant = std::dynamic_pointer_cast<Analyzer::Constant>(from_expr);
261  if (constant) {
262  Datum d{0};
263  d.bigintval =
264  getDateTruncConstantValue(constant->get_constval().bigintval, field, expr_ti);
265  constant->set_constval(d);
266  constant->set_type_info(ti);
267  return constant;
268  }
269  return makeExpr<Analyzer::DatetruncExpr>(
270  ti, from_expr->get_contains_agg(), field, from_expr->decompress());
271 }
Definition: sqltypes.h:76
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
int64_t bigintval
Definition: Datum.h:76
std::string from_datetrunc_field(const DatetruncField &fieldno)
static int64_t getDateTruncConstantValue(const int64_t &timeval, const DatetruncField &field, const SQLTypeInfo &ti)
Definition: Datum.h:71

+ Here is the call graph for this function:

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

Definition at line 117 of file DateTimeTranslator.h.

References generate_loop_ref::generate().

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

117  {
118  return generate(from_expr_, field_);
119  }
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 197 of file DateTimeTranslator.cpp.

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

Referenced by generate().

197  {
198  DatetruncField fieldno;
199  if (boost::iequals(field, "year")) {
200  fieldno = dtYEAR;
201  } else if (boost::iequals(field, "quarter")) {
202  fieldno = dtQUARTER;
203  } else if (boost::iequals(field, "month")) {
204  fieldno = dtMONTH;
205  } else if (boost::iequals(field, "quarterday")) {
206  fieldno = dtQUARTERDAY;
207  } else if (boost::iequals(field, "day")) {
208  fieldno = dtDAY;
209  } else if (boost::iequals(field, "hour")) {
210  fieldno = dtHOUR;
211  } else if (boost::iequals(field, "minute")) {
212  fieldno = dtMINUTE;
213  } else if (boost::iequals(field, "second")) {
214  fieldno = dtSECOND;
215  } else if (boost::iequals(field, "millennium")) {
216  fieldno = dtMILLENNIUM;
217  } else if (boost::iequals(field, "century")) {
218  fieldno = dtCENTURY;
219  } else if (boost::iequals(field, "decade")) {
220  fieldno = dtDECADE;
221  } else if (boost::iequals(field, "millisecond")) {
222  fieldno = dtMILLISECOND;
223  } else if (boost::iequals(field, "microsecond")) {
224  fieldno = dtMICROSECOND;
225  } else if (boost::iequals(field, "nanosecond")) {
226  fieldno = dtNANOSECOND;
227  } else if (boost::iequals(field, "week")) {
228  fieldno = dtWEEK;
229  } else if (boost::iequals(field, "week_sunday")) {
230  fieldno = dtWEEK_SUNDAY;
231  } else if (boost::iequals(field, "week_saturday")) {
232  fieldno = dtWEEK_SATURDAY;
233  } else {
234  throw std::runtime_error("Invalid field in DATE_TRUNC function " + field);
235  }
236  return fieldno;
237 }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
DatetruncField
Definition: DateTruncate.h:27

+ Here is the caller graph for this function:

Member Data Documentation

DatetruncField DateTruncExpr::field_
private

Definition at line 125 of file DateTimeTranslator.h.

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: