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

Constructor & Destructor Documentation

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

Definition at line 84 of file DateTimeTranslator.h.

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

Definition at line 86 of file DateTimeTranslator.h.

ExtractField field_
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
static ExtractField to_extract_field(const std::string &field)
std::shared_ptr< Analyzer::Expr > from_expr_

Member Function Documentation

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

Definition at line 160 of file DateTimeTranslator.cpp.

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

162  {
163  const auto field = to_extract_field(field_name);
164  return ExtractExpr::generate(from_expr, field);
165 }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
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:

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

Definition at line 167 of file DateTimeTranslator.cpp.

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

169  {
170  const auto expr_ti = from_expr->get_type_info();
171  if (!expr_ti.is_time()) {
172  throw std::runtime_error(
173  "Only TIME, TIMESTAMP and DATE types can be in EXTRACT function.");
174  }
175  if (expr_ti.get_type() == kTIME && field != kHOUR && field != kMINUTE &&
176  field != kSECOND) {
177  throw std::runtime_error("Cannot EXTRACT " + from_extract_field(field) +
178  " from TIME.");
179  }
180  const SQLTypeInfo ti(kBIGINT, 0, 0, expr_ti.get_notnull());
181  auto constant = std::dynamic_pointer_cast<Analyzer::Constant>(from_expr);
182  if (constant != nullptr) {
183  Datum d;
184  d.bigintval = field == kEPOCH
185  ? floor_div(constant->get_constval().bigintval,
186  get_timestamp_precision_scale(expr_ti.get_dimension()))
188  constant->get_constval().bigintval, field, expr_ti);
189  constant->set_constval(d);
190  constant->set_type_info(ti);
191  return constant;
192  }
193  return makeExpr<Analyzer::ExtractExpr>(
194  ti, from_expr->get_contains_agg(), field, from_expr->decompress());
195 }
Definition: sqltypes.h:76
DEVICE int64_t floor_div(int64_t const dividend, int64_t const divisor)
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:33
int64_t bigintval
Definition: Datum.h:76
std::string from_extract_field(const ExtractField &fieldno)
constexpr int64_t get_timestamp_precision_scale(const int32_t dimen)
Definition: DateTimeUtils.h:51
Definition: Datum.h:71

+ Here is the call graph for this function:

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

Definition at line 94 of file DateTimeTranslator.h.

References generate_loop_ref::generate().

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

94  {
95  return generate(from_expr_, field_);
96  }
ExtractField field_
const std::shared_ptr< Analyzer::Expr > generate() const
std::shared_ptr< Analyzer::Expr > from_expr_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 114 of file DateTimeTranslator.cpp.

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

Referenced by generate().

114  {
115  ExtractField fieldno;
116  if (boost::iequals(field, "year")) {
117  fieldno = kYEAR;
118  } else if (boost::iequals(field, "quarter")) {
119  fieldno = kQUARTER;
120  } else if (boost::iequals(field, "month")) {
121  fieldno = kMONTH;
122  } else if (boost::iequals(field, "day")) {
123  fieldno = kDAY;
124  } else if (boost::iequals(field, "quarterday")) {
125  fieldno = kQUARTERDAY;
126  } else if (boost::iequals(field, "hour")) {
127  fieldno = kHOUR;
128  } else if (boost::iequals(field, "minute")) {
129  fieldno = kMINUTE;
130  } else if (boost::iequals(field, "second")) {
131  fieldno = kSECOND;
132  } else if (boost::iequals(field, "millisecond")) {
133  fieldno = kMILLISECOND;
134  } else if (boost::iequals(field, "microsecond")) {
135  fieldno = kMICROSECOND;
136  } else if (boost::iequals(field, "nanosecond")) {
137  fieldno = kNANOSECOND;
138  } else if (boost::iequals(field, "dow")) {
139  fieldno = kDOW;
140  } else if (boost::iequals(field, "isodow")) {
141  fieldno = kISODOW;
142  } else if (boost::iequals(field, "doy")) {
143  fieldno = kDOY;
144  } else if (boost::iequals(field, "epoch")) {
145  fieldno = kEPOCH;
146  } else if (boost::iequals(field, "week")) {
147  fieldno = kWEEK;
148  } else if (boost::iequals(field, "week_sunday")) {
149  fieldno = kWEEK_SUNDAY;
150  } else if (boost::iequals(field, "week_saturday")) {
151  fieldno = kWEEK_SATURDAY;
152  } else if (boost::iequals(field, "dateepoch")) {
153  fieldno = kDATEEPOCH;
154  } else {
155  throw std::runtime_error("Unsupported field in EXTRACT function " + field);
156  }
157  return fieldno;
158 }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
ExtractField

+ Here is the caller graph for this function:

Member Data Documentation

ExtractField ExtractExpr::field_
private

Definition at line 102 of file DateTimeTranslator.h.

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

Definition at line 101 of file DateTimeTranslator.h.


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