OmniSciDB  0b528656ed
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 79 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 81 of file DateTimeTranslator.h.

82  : 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 83 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 148 of file DateTimeTranslator.cpp.

References field(), and generate().

150  {
151  const auto field = to_extract_field(field_name);
152  return ExtractExpr::generate(from_expr, field);
153 }
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 155 of file DateTimeTranslator.cpp.

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

157  {
158  const auto expr_ti = from_expr->get_type_info();
159  if (!expr_ti.is_time()) {
160  throw std::runtime_error(
161  "Only TIME, TIMESTAMP and DATE types can be in EXTRACT function.");
162  }
163  if (expr_ti.get_type() == kTIME && field != kHOUR && field != kMINUTE &&
164  field != kSECOND) {
165  throw std::runtime_error("Cannot EXTRACT " + from_extract_field(field) +
166  " from TIME.");
167  }
168  const SQLTypeInfo ti(kBIGINT, 0, 0, expr_ti.get_notnull());
169  auto constant = std::dynamic_pointer_cast<Analyzer::Constant>(from_expr);
170  if (constant != nullptr) {
171  Datum d;
172  d.bigintval = field == kEPOCH
173  ? constant->get_constval().bigintval
175  constant->get_constval().bigintval, field, expr_ti);
176  constant->set_constval(d);
177  constant->set_type_info(ti);
178  return constant;
179  }
180  return makeExpr<Analyzer::ExtractExpr>(
181  ti, from_expr->get_contains_agg(), field, from_expr->decompress());
182 }
Definition: sqltypes.h:50
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:136
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 91 of file DateTimeTranslator.h.

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

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

91  {
92  return generate(from_expr_, field_);
93  }
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 106 of file DateTimeTranslator.cpp.

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

106  {
107  ExtractField fieldno;
108  if (boost::iequals(field, "year")) {
109  fieldno = kYEAR;
110  } else if (boost::iequals(field, "quarter")) {
111  fieldno = kQUARTER;
112  } else if (boost::iequals(field, "month")) {
113  fieldno = kMONTH;
114  } else if (boost::iequals(field, "day")) {
115  fieldno = kDAY;
116  } else if (boost::iequals(field, "quarterday")) {
117  fieldno = kQUARTERDAY;
118  } else if (boost::iequals(field, "hour")) {
119  fieldno = kHOUR;
120  } else if (boost::iequals(field, "minute")) {
121  fieldno = kMINUTE;
122  } else if (boost::iequals(field, "second")) {
123  fieldno = kSECOND;
124  } else if (boost::iequals(field, "millisecond")) {
125  fieldno = kMILLISECOND;
126  } else if (boost::iequals(field, "microsecond")) {
127  fieldno = kMICROSECOND;
128  } else if (boost::iequals(field, "nanosecond")) {
129  fieldno = kNANOSECOND;
130  } else if (boost::iequals(field, "dow")) {
131  fieldno = kDOW;
132  } else if (boost::iequals(field, "isodow")) {
133  fieldno = kISODOW;
134  } else if (boost::iequals(field, "doy")) {
135  fieldno = kDOY;
136  } else if (boost::iequals(field, "epoch")) {
137  fieldno = kEPOCH;
138  } else if (boost::iequals(field, "week")) {
139  fieldno = kWEEK;
140  } else if (boost::iequals(field, "dateepoch")) {
141  fieldno = kDATEEPOCH;
142  } else {
143  throw std::runtime_error("Unsupported field in EXTRACT function " + field);
144  }
145  return fieldno;
146 }
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 99 of file DateTimeTranslator.h.

◆ from_expr_

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

Definition at line 98 of file DateTimeTranslator.h.


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