OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DateTimeUtils Namespace Reference

Enumerations

enum  ScalingType { ScaleUp, ScaleDown }
 

Functions

constexpr int64_t get_timestamp_precision_scale (const int32_t dimen)
 
constexpr int64_t get_dateadd_timestamp_precision_scale (const DateaddField field)
 
constexpr int64_t get_extract_timestamp_precision_scale (const ExtractField field)
 
constexpr bool is_subsecond_extract_field (const ExtractField &field)
 
constexpr bool is_subsecond_dateadd_field (const DateaddField field)
 
constexpr bool is_subsecond_datetrunc_field (const DatetruncField field)
 
const std::pair< SQLOps, int64_t > get_dateadd_high_precision_adjusted_scale (const DateaddField field, int32_t dimen)
 
const std::pair< SQLOps, int64_t > get_extract_high_precision_adjusted_scale (const ExtractField &field, const int32_t dimen)
 
const int64_t get_datetrunc_high_precision_scale (const DatetruncField &field, const int32_t dimen)
 
constexpr int64_t get_datetime_scaled_epoch (const ScalingType direction, const int64_t epoch, const int32_t dimen)
 

Enumeration Type Documentation

Enumerator
ScaleUp 
ScaleDown 

Definition at line 49 of file DateTimeUtils.h.

Function Documentation

const std::pair<SQLOps, int64_t> DateTimeUtils::get_dateadd_high_precision_adjusted_scale ( const DateaddField  field,
int32_t  dimen 
)
inline

Definition at line 107 of file DateTimeUtils.h.

References daMICROSECOND, daMILLISECOND, daNANOSECOND, kDIVIDE, kMicroSecsPerSec, kMilliSecsPerSec, kMULTIPLY, and to_string().

109  {
110  switch (field) {
111  case daNANOSECOND:
112  switch (dimen) {
113  case 9:
114  return {};
115  case 6:
116  return {kDIVIDE, kMilliSecsPerSec};
117  case 3:
118  return {kDIVIDE, kMicroSecsPerSec};
119  default:
120  throw std::runtime_error("Unknown dimen = " + std::to_string(dimen));
121  }
122  case daMICROSECOND:
123  switch (dimen) {
124  case 9:
125  return {kMULTIPLY, kMilliSecsPerSec};
126  case 6:
127  return {};
128  case 3:
129  return {kDIVIDE, kMilliSecsPerSec};
130  default:
131  throw std::runtime_error("Unknown dimen = " + std::to_string(dimen));
132  }
133  case daMILLISECOND:
134  switch (dimen) {
135  case 9:
136  return {kMULTIPLY, kMicroSecsPerSec};
137  case 6:
138  return {kMULTIPLY, kMilliSecsPerSec};
139  case 3:
140  return {};
141  default:
142  throw std::runtime_error("Unknown dimen = " + std::to_string(dimen));
143  }
144  default:
145  throw std::runtime_error("Unknown field = " + std::to_string(field));
146  }
147  return {};
148 }
std::string to_string(char const *&&v)
static constexpr int64_t kMilliSecsPerSec
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
static constexpr int64_t kMicroSecsPerSec

+ Here is the call graph for this function:

constexpr int64_t DateTimeUtils::get_dateadd_timestamp_precision_scale ( const DateaddField  field)
inline

Definition at line 67 of file DateTimeUtils.h.

References daMICROSECOND, daMILLISECOND, daNANOSECOND, kMicroSecsPerSec, kMilliSecsPerSec, kNanoSecsPerSec, and to_string().

67  {
68  switch (field) {
69  case daMILLISECOND:
70  return kMilliSecsPerSec;
71  case daMICROSECOND:
72  return kMicroSecsPerSec;
73  case daNANOSECOND:
74  return kNanoSecsPerSec;
75  default:
76  throw std::runtime_error("Unknown field = " + std::to_string(field));
77  }
78  return -1;
79 }
static constexpr int64_t kNanoSecsPerSec
std::string to_string(char const *&&v)
static constexpr int64_t kMilliSecsPerSec
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
static constexpr int64_t kMicroSecsPerSec

+ Here is the call graph for this function:

constexpr int64_t DateTimeUtils::get_datetime_scaled_epoch ( const ScalingType  direction,
const int64_t  epoch,
const int32_t  dimen 
)
inline

Definition at line 169 of file DateTimeUtils.h.

References get_timestamp_precision_scale(), ScaleDown, and ScaleUp.

Referenced by Analyzer::Constant::do_cast(), and anonymous_namespace{ExpressionRange.cpp}::getDateTimePrecisionCastRange().

171  {
172  switch (direction) {
173  case ScaleUp: {
174  const auto scaled_epoch = epoch * get_timestamp_precision_scale(dimen);
175  if (epoch && epoch != scaled_epoch / get_timestamp_precision_scale(dimen)) {
176  throw std::runtime_error(
177  "Value Overflow/underflow detected while scaling DateTime precision.");
178  }
179  return scaled_epoch;
180  }
181  case ScaleDown:
182  return epoch / get_timestamp_precision_scale(dimen);
183  default:
184  abort();
185  }
186  return std::numeric_limits<int64_t>::min();
187 }
constexpr int64_t get_timestamp_precision_scale(const int32_t dimen)
Definition: DateTimeUtils.h:51

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const int64_t DateTimeUtils::get_datetrunc_high_precision_scale ( const DatetruncField field,
const int32_t  dimen 
)
inline

Definition at line 160 of file DateTimeUtils.h.

References anonymous_namespace{DateTimeUtils.h}::datetrunc_precision_lookup, and run_benchmark_import::result.

Referenced by DateTimeTranslator::getDateTruncConstantValue().

161  {
162  const auto result = datetrunc_precision_lookup.find(std::make_pair(dimen, field));
163  if (result != datetrunc_precision_lookup.end()) {
164  return result->second;
165  }
166  return -1;
167 }
static const std::map< std::pair< int32_t, DatetruncField >, int64_t > datetrunc_precision_lookup
Definition: DateTimeUtils.h:40
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33

+ Here is the caller graph for this function:

const std::pair<SQLOps, int64_t> DateTimeUtils::get_extract_high_precision_adjusted_scale ( const ExtractField field,
const int32_t  dimen 
)
inline

Definition at line 150 of file DateTimeUtils.h.

References anonymous_namespace{DateTimeUtils.h}::extract_precision_lookup, and run_benchmark_import::result.

Referenced by CodeGenerator::codegenExtractHighPrecisionTimestamps(), and DateTimeTranslator::getExtractFromTimeConstantValue().

152  {
153  const auto result = extract_precision_lookup.find(std::make_pair(dimen, field));
154  if (result != extract_precision_lookup.end()) {
155  return result->second;
156  }
157  return {};
158 }
static const std::map< std::pair< int32_t, ExtractField >, std::pair< SQLOps, int64_t > > extract_precision_lookup
Definition: DateTimeUtils.h:32
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33

+ Here is the caller graph for this function:

constexpr int64_t DateTimeUtils::get_extract_timestamp_precision_scale ( const ExtractField  field)
inline

Definition at line 81 of file DateTimeUtils.h.

References kMICROSECOND, kMicroSecsPerSec, kMILLISECOND, kMilliSecsPerSec, kNANOSECOND, kNanoSecsPerSec, and to_string().

Referenced by CodeGenerator::codegen(), and DateTimeTranslator::getExtractFromTimeConstantValue().

81  {
82  switch (field) {
83  case kMILLISECOND:
84  return kMilliSecsPerSec;
85  case kMICROSECOND:
86  return kMicroSecsPerSec;
87  case kNANOSECOND:
88  return kNanoSecsPerSec;
89  default:
90  throw std::runtime_error("Unknown field = " + std::to_string(field));
91  }
92  return -1;
93 }
static constexpr int64_t kNanoSecsPerSec
std::string to_string(char const *&&v)
static constexpr int64_t kMilliSecsPerSec
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
static constexpr int64_t kMicroSecsPerSec

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

constexpr int64_t DateTimeUtils::get_timestamp_precision_scale ( const int32_t  dimen)
inline

Definition at line 51 of file DateTimeUtils.h.

References kMicroSecsPerSec, kMilliSecsPerSec, kNanoSecsPerSec, and to_string().

Referenced by apply_hpt_qual(), CodeGenerator::codegenCastBetweenTimestamps(), CodeGenerator::codegenCastTimestampToDate(), CodeGenerator::codegenCastTimestampToTime(), Analyzer::Constant::do_cast(), ExtractExpr::generate(), get_datetime_scaled_epoch(), anonymous_namespace{Execute.cpp}::get_hpt_overflow_underflow_safe_scaled_values(), anonymous_namespace{ExpressionRange.cpp}::getDateTimePrecisionCastRange(), DateTimeTranslator::getDateTruncConstantValue(), getExpressionRange(), and DateTimeTranslator::getExtractFromTimeConstantValue().

51  {
52  switch (dimen) {
53  case 0:
54  return 1;
55  case 3:
56  return kMilliSecsPerSec;
57  case 6:
58  return kMicroSecsPerSec;
59  case 9:
60  return kNanoSecsPerSec;
61  default:
62  throw std::runtime_error("Unknown dimen = " + std::to_string(dimen));
63  }
64  return -1;
65 }
static constexpr int64_t kNanoSecsPerSec
std::string to_string(char const *&&v)
static constexpr int64_t kMilliSecsPerSec
static constexpr int64_t kMicroSecsPerSec

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

constexpr bool DateTimeUtils::is_subsecond_dateadd_field ( const DateaddField  field)
inline

Definition at line 99 of file DateTimeUtils.h.

References daMICROSECOND, daMILLISECOND, and daNANOSECOND.

Referenced by CodeGenerator::codegen().

99  {
101 }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33

+ Here is the caller graph for this function:

constexpr bool DateTimeUtils::is_subsecond_datetrunc_field ( const DatetruncField  field)
inline

Definition at line 103 of file DateTimeUtils.h.

References dtMICROSECOND, dtMILLISECOND, and dtNANOSECOND.

Referenced by DateTimeTranslator::getDateTruncConstantValue().

103  {
105 }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33

+ Here is the caller graph for this function:

constexpr bool DateTimeUtils::is_subsecond_extract_field ( const ExtractField field)
inline

Definition at line 95 of file DateTimeUtils.h.

References kMICROSECOND, kMILLISECOND, and kNANOSECOND.

Referenced by CodeGenerator::codegen(), CodeGenerator::codegenExtractHighPrecisionTimestamps(), and DateTimeTranslator::getExtractFromTimeConstantValue().

95  {
96  return field == kMILLISECOND || field == kMICROSECOND || field == kNANOSECOND;
97 }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33

+ Here is the caller graph for this function: