OmniSciDB  04ee39c94c
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 107 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 109 of file DateTimeTranslator.h.

110  : 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 111 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 218 of file DateTimeTranslator.cpp.

References field(), and generate().

220  {
221  const auto field = to_datetrunc_field(field_name);
222  return DateTruncExpr::generate(from_expr, field);
223 }
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 225 of file DateTimeTranslator.cpp.

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

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

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

Referenced by generate(), rewrite_to_date_trunc(), RelAlgTranslator::translateExtract(), and anonymous_namespace{CalciteAdapter.cpp}::CalciteAdapter::translateExtract().

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

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

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

Member Data Documentation

◆ field_

DatetruncField DateTruncExpr::field_
private

Definition at line 127 of file DateTimeTranslator.h.

◆ from_expr_

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

Definition at line 126 of file DateTimeTranslator.h.


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