OmniSciDB  d2f719934e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TargetInfo.h File Reference
#include "sqldefs.h"
#include "sqltypes.h"
#include "../Analyzer/Analyzer.h"
+ Include dependency graph for TargetInfo.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  TargetInfo
 

Functions

const Analyzer::AggExprcast_to_agg_expr (const Analyzer::Expr *target_expr)
 
const Analyzer::AggExprcast_to_agg_expr (const std::shared_ptr< Analyzer::Expr > target_expr)
 
bool target_expr_has_varlen_projection (const Analyzer::Expr *target_expr)
 
bool target_expr_has_varlen_projection (const std::shared_ptr< Analyzer::Expr > target_expr)
 
bool is_agg_domain_range_equivalent (const SQLAgg &agg_kind)
 
template<class PointerType >
TargetInfo get_target_info (const PointerType target_expr, const bool bigint_count)
 
bool is_distinct_target (const TargetInfo &target_info)
 
bool takes_float_argument (const TargetInfo &target_info)
 

Detailed Description

Author
Alex Suhan alex@.nosp@m.mapd.nosp@m..com

Definition in file TargetInfo.h.

Function Documentation

const Analyzer::AggExpr* cast_to_agg_expr ( const Analyzer::Expr target_expr)
inline

Definition at line 30 of file TargetInfo.h.

Referenced by get_target_info().

30  {
31  return dynamic_cast<const Analyzer::AggExpr*>(target_expr);
32 }

+ Here is the caller graph for this function:

const Analyzer::AggExpr* cast_to_agg_expr ( const std::shared_ptr< Analyzer::Expr target_expr)
inline

Definition at line 34 of file TargetInfo.h.

35  {
36  return dynamic_cast<const Analyzer::AggExpr*>(target_expr.get());
37 }
template<class PointerType >
TargetInfo get_target_info ( const PointerType  target_expr,
const bool  bigint_count 
)
inline

Definition at line 92 of file TargetInfo.h.

References agg_arg(), cast_to_agg_expr(), CHECK, CHECK_EQ, get_logical_type_info(), SQLTypeInfo::get_notnull(), Analyzer::Expr::get_type_info(), anonymous_namespace{RelAlgOptimizer.cpp}::is_distinct(), anonymous_namespace{TargetExprBuilder.cpp}::is_varlen_projection(), kAVG, kBIGINT, kCOUNT, kINT, kMIN, kNULLT, and target_expr_has_varlen_projection().

Referenced by QueryMemoryInitializer::allocateCountDistinctBuffers(), GroupByAndAggregate::codegenApproxQuantile(), GroupByAndAggregate::codegenCountDistinct(), ColSlotContext::ColSlotContext(), RelAlgExecutor::createSortInputWorkUnit(), anonymous_namespace{RelAlgExecutor.cpp}::decide_approx_count_distinct_implementation(), Executor::executePlanWithoutGroupBy(), anonymous_namespace{Execute.cpp}::fill_entries_for_empty_input(), anonymous_namespace{QueryMemoryDescriptor.cpp}::get_col_byte_widths(), get_heap_key_slot_index(), anonymous_namespace{GroupByAndAggregate.cpp}::get_keyless_info(), Executor::getDeviceTypeForTargets(), anonymous_namespace{GroupByAndAggregate.cpp}::has_count_distinct(), init_agg_val_vec(), anonymous_namespace{GroupByAndAggregate.cpp}::init_count_distinct_descriptors(), QueryMemoryInitializer::initColumnarGroups(), TargetExprCodegenBuilder::operator()(), anonymous_namespace{Execute.cpp}::GetTargetInfo::operator()(), and target_exprs_to_infos().

93  {
94  const auto agg_expr = cast_to_agg_expr(target_expr);
95  bool notnull = target_expr->get_type_info().get_notnull();
96  if (!agg_expr) {
98  auto target_ti = target_expr ? get_logical_type_info(target_expr->get_type_info())
99  : SQLTypeInfo(kBIGINT, notnull);
100  return {false,
101  kMIN,
102  target_ti,
103  SQLTypeInfo(kNULLT, false),
104  false,
105  false,
106  is_varlen_projection};
107  }
108  const auto agg_type = agg_expr->get_aggtype();
109  const auto agg_arg = agg_expr->get_arg();
110  if (!agg_arg) {
111  CHECK_EQ(kCOUNT, agg_type);
112  CHECK(!agg_expr->get_is_distinct());
113  return {true,
114  kCOUNT,
115  SQLTypeInfo(bigint_count ? kBIGINT : kINT, notnull),
116  SQLTypeInfo(kNULLT, false),
117  false,
118  false,
119  false};
120  }
121 
122  const auto& agg_arg_ti = agg_arg->get_type_info();
123  bool is_distinct{false};
124  if (agg_expr->get_aggtype() == kCOUNT) {
125  is_distinct = agg_expr->get_is_distinct();
126  }
127 
128  if (agg_type == kAVG) {
129  // Upcast the target type for AVG, so that the integer argument does not overflow the
130  // sum
131  return {true,
132  agg_expr->get_aggtype(),
133  agg_arg_ti.is_integer() ? SQLTypeInfo(kBIGINT, agg_arg_ti.get_notnull())
134  : agg_arg_ti,
135  agg_arg_ti,
136  !agg_arg_ti.get_notnull(),
137  is_distinct,
138  false};
139  }
140 
141  return {
142  true,
143  agg_expr->get_aggtype(),
144  agg_type == kCOUNT
145  ? SQLTypeInfo((is_distinct || bigint_count) ? kBIGINT : kINT, notnull)
146  : agg_expr->get_type_info(),
147  agg_arg_ti,
148  agg_type == kCOUNT && agg_arg_ti.is_varlen() ? false : !agg_arg_ti.get_notnull(),
149  is_distinct,
150  false};
151 }
const Analyzer::Expr * agg_arg(const Analyzer::Expr *expr)
#define CHECK_EQ(x, y)
Definition: Logger.h:219
SQLTypeInfo get_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1064
bool target_expr_has_varlen_projection(const Analyzer::Expr *target_expr)
Definition: TargetInfo.h:39
Definition: sqldefs.h:73
bool is_varlen_projection(const Analyzer::Expr *target_expr, const SQLTypeInfo &ti)
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:77
const Analyzer::AggExpr * cast_to_agg_expr(const Analyzer::Expr *target_expr)
Definition: TargetInfo.h:30
Definition: sqldefs.h:76
bool g_enable_watchdog false
Definition: Execute.cpp:76
#define CHECK(condition)
Definition: Logger.h:211
Definition: sqltypes.h:45
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:336
Definition: sqldefs.h:72
bool is_distinct(const size_t input_idx, const RelAlgNode *node)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool is_agg_domain_range_equivalent ( const SQLAgg agg_kind)
inline

Returns true if the aggregate function always returns a value in the domain of the argument. Returns false otherwise.

Definition at line 78 of file TargetInfo.h.

References kMAX, kMIN, kSAMPLE, and kSINGLE_VALUE.

Referenced by TargetExprCodegen::codegenAggregate(), and get_compact_type().

78  {
79  switch (agg_kind) {
80  case kMIN:
81  case kMAX:
82  case kSINGLE_VALUE:
83  case kSAMPLE:
84  return true;
85  default:
86  break;
87  }
88  return false;
89 }
Definition: sqldefs.h:73
Definition: sqldefs.h:74

+ Here is the caller graph for this function:

bool takes_float_argument ( const TargetInfo target_info)
inline

Definition at line 157 of file TargetInfo.h.

References TargetInfo::agg_arg_type, TargetInfo::agg_kind, SQLTypeInfo::get_type(), TargetInfo::is_agg, kAVG, kFLOAT, kMAX, kMIN, kSINGLE_VALUE, and kSUM.

Referenced by anonymous_namespace{ResultSetSortImpl.cu}::baseline_sort_fp(), TargetExprCodegen::codegenAggregate(), Executor::executePlanWithoutGroupBy(), anonymous_namespace{Execute.cpp}::fill_entries_for_empty_input(), anonymous_namespace{GroupByAndAggregate.cpp}::get_keyless_info(), init_agg_val_vec(), result_set::initialize_target_values_for_storage(), anonymous_namespace{ResultSetIteration.cpp}::make_avg_target_value(), ResultSet::ResultSetComparator< BUFFER_ITERATOR_TYPE >::operator()(), ResultSetReductionJIT::reduceOneSlot(), ResultSetStorage::reduceOneSlot(), ResultSetStorage::reduceOneSlotSingleValue(), and ResultSetStorage::reduceSingleRow().

157  {
158  return target_info.is_agg &&
159  (target_info.agg_kind == kAVG || target_info.agg_kind == kSUM ||
160  target_info.agg_kind == kMIN || target_info.agg_kind == kMAX ||
161  target_info.agg_kind == kSINGLE_VALUE) &&
162  target_info.agg_arg_type.get_type() == kFLOAT;
163 }
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
SQLTypeInfo agg_arg_type
Definition: TargetInfo.h:52
Definition: sqldefs.h:73
bool is_agg
Definition: TargetInfo.h:49
Definition: sqldefs.h:75
SQLAgg agg_kind
Definition: TargetInfo.h:50
Definition: sqldefs.h:74
Definition: sqldefs.h:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool target_expr_has_varlen_projection ( const Analyzer::Expr target_expr)
inline

Definition at line 39 of file TargetInfo.h.

Referenced by get_target_info().

39  {
40  return !(dynamic_cast<const Analyzer::GeoExpr*>(target_expr) == nullptr);
41 }

+ Here is the caller graph for this function:

bool target_expr_has_varlen_projection ( const std::shared_ptr< Analyzer::Expr target_expr)
inline

Definition at line 43 of file TargetInfo.h.

44  {
45  return !(dynamic_cast<const Analyzer::GeoExpr*>(target_expr.get()) == nullptr);
46 }