OmniSciDB  04ee39c94c
ExtractExpr Class Reference

#include <DateTimeTranslator.h>

+ Inheritance diagram for ExtractExpr:
+ Collaboration diagram for ExtractExpr:

Public Member Functions

 ExtractExpr (const std::shared_ptr< Analyzer::Expr > expr, const ExtractField &field)
 
 ExtractExpr (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 ExtractField &)
 

Static Private Member Functions

static ExtractField to_extract_field (const std::string &field)
 

Private Attributes

std::shared_ptr< Analyzer::Exprfrom_expr_
 
ExtractField 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 84 of file DateTimeTranslator.h.

Constructor & Destructor Documentation

◆ ExtractExpr() [1/2]

ExtractExpr::ExtractExpr ( const std::shared_ptr< Analyzer::Expr expr,
const ExtractField field 
)
inline

Definition at line 86 of file DateTimeTranslator.h.

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

◆ ExtractExpr() [2/2]

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

Definition at line 88 of file DateTimeTranslator.h.

References generate_loop_ref::generate().

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

Member Function Documentation

◆ generate() [1/3]

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

Definition at line 144 of file DateTimeTranslator.cpp.

References field(), and generate().

146  {
147  const auto field = to_extract_field(field_name);
148  return ExtractExpr::generate(from_expr, field);
149 }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
static ExtractField to_extract_field(const std::string &field)
const std::shared_ptr< Analyzer::Expr > generate() const
+ Here is the call graph for this function:

◆ generate() [2/3]

std::shared_ptr< Analyzer::Expr > ExtractExpr::generate ( const std::shared_ptr< Analyzer::Expr from_expr,
const ExtractField field 
)
static

Definition at line 151 of file DateTimeTranslator.cpp.

References Datum::bigintval, anonymous_namespace{ImportTest.cpp}::d(), field(), anonymous_namespace{DateTimeTranslator.cpp}::from_extract_field(), kBIGINT, kEPOCH, kHOUR, kMINUTE, kSECOND, and kTIME.

153  {
154  const auto expr_ti = from_expr->get_type_info();
155  if (!expr_ti.is_time()) {
156  throw std::runtime_error(
157  "Only TIME, TIMESTAMP and DATE types can be in EXTRACT function.");
158  }
159  if (expr_ti.get_type() == kTIME && field != kHOUR && field != kMINUTE &&
160  field != kSECOND) {
161  throw std::runtime_error("Cannot EXTRACT " + from_extract_field(field) +
162  " from TIME.");
163  }
164  const SQLTypeInfo ti(kBIGINT, 0, 0, expr_ti.get_notnull());
165  auto constant = std::dynamic_pointer_cast<Analyzer::Constant>(from_expr);
166  if (constant != nullptr) {
167  Datum d;
168  d.bigintval = field == kEPOCH
169  ? constant->get_constval().bigintval
171  constant->get_constval().bigintval, field, expr_ti);
172  constant->set_constval(d);
173  constant->set_type_info(ti);
174  return constant;
175  }
176  return makeExpr<Analyzer::ExtractExpr>(
177  ti, from_expr->get_contains_agg(), field, from_expr->decompress());
178 }
void d(const SQLTypes expected_type, const std::string &str)
Definition: ImportTest.cpp:268
Definition: sqltypes.h:51
static int64_t getExtractFromTimeConstantValue(const int64_t &timeval, const ExtractField &field, const SQLTypeInfo &ti)
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
int64_t bigintval
Definition: sqltypes.h:126
std::string from_extract_field(const ExtractField &fieldno)
+ Here is the call graph for this function:

◆ generate() [3/3]

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

Definition at line 96 of file DateTimeTranslator.h.

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

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

96  {
97  return generate(from_expr_, field_);
98  }
ExtractField field_
std::shared_ptr< Analyzer::Expr > from_expr_
const std::shared_ptr< Analyzer::Expr > generate() const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ to_extract_field()

ExtractField ExtractExpr::to_extract_field ( const std::string &  field)
staticprivate

Definition at line 104 of file DateTimeTranslator.cpp.

References kDAY, kDOW, kDOY, kEPOCH, kHOUR, kISODOW, kMICROSECOND, kMILLISECOND, kMINUTE, kMONTH, kNANOSECOND, kQUARTER, kQUARTERDAY, kSECOND, kWEEK, and kYEAR.

104  {
105  ExtractField fieldno;
106  if (boost::iequals(field, "year")) {
107  fieldno = kYEAR;
108  } else if (boost::iequals(field, "quarter")) {
109  fieldno = kQUARTER;
110  } else if (boost::iequals(field, "month")) {
111  fieldno = kMONTH;
112  } else if (boost::iequals(field, "day")) {
113  fieldno = kDAY;
114  } else if (boost::iequals(field, "quarterday")) {
115  fieldno = kQUARTERDAY;
116  } else if (boost::iequals(field, "hour")) {
117  fieldno = kHOUR;
118  } else if (boost::iequals(field, "minute")) {
119  fieldno = kMINUTE;
120  } else if (boost::iequals(field, "second")) {
121  fieldno = kSECOND;
122  } else if (boost::iequals(field, "millisecond")) {
123  fieldno = kMILLISECOND;
124  } else if (boost::iequals(field, "microsecond")) {
125  fieldno = kMICROSECOND;
126  } else if (boost::iequals(field, "nanosecond")) {
127  fieldno = kNANOSECOND;
128  } else if (boost::iequals(field, "dow")) {
129  fieldno = kDOW;
130  } else if (boost::iequals(field, "isodow")) {
131  fieldno = kISODOW;
132  } else if (boost::iequals(field, "doy")) {
133  fieldno = kDOY;
134  } else if (boost::iequals(field, "epoch")) {
135  fieldno = kEPOCH;
136  } else if (boost::iequals(field, "week")) {
137  fieldno = kWEEK;
138  } else {
139  throw std::runtime_error("Unsupported field in EXTRACT function " + field);
140  }
141  return fieldno;
142 }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
ExtractField

Member Data Documentation

◆ field_

ExtractField ExtractExpr::field_
private

Definition at line 104 of file DateTimeTranslator.h.

◆ from_expr_

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

Definition at line 103 of file DateTimeTranslator.h.


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