22 #include "../Analyzer/Analyzer.h" 28 std::vector<int64_t> agg_init_vals;
30 const bool is_group_by{query_mem_desc.
isGroupBy()};
31 for (
size_t target_idx = 0, agg_col_idx = 0; target_idx < targets.size();
32 ++target_idx, ++agg_col_idx) {
34 const auto agg_info = targets[target_idx];
35 const auto& agg_ti = agg_info.sql_type;
36 if (!agg_info.is_agg || agg_info.agg_kind ==
kSAMPLE) {
37 if (agg_info.agg_kind ==
kSAMPLE && agg_ti.is_string() &&
39 agg_init_vals.push_back(
47 agg_init_vals.push_back(0);
49 if (agg_ti.is_array() ||
50 (agg_ti.is_string() && agg_ti.get_compression() ==
kENCODING_NONE)) {
51 agg_init_vals.push_back(0);
53 if (agg_ti.is_geometry()) {
54 agg_init_vals.push_back(0);
55 for (
auto i = 1; i < agg_ti.get_physical_coord_cols(); ++i) {
56 agg_init_vals.push_back(0);
57 agg_init_vals.push_back(0);
69 init_ti.set_notnull(
false);
71 agg_init_vals.push_back(
74 is_group_by || float_argument_input,
75 (float_argument_input ?
sizeof(
float) : chosen_bytes)));
76 if (
kAVG == agg_info.agg_kind) {
78 agg_init_vals.push_back(0);
87 return std::make_pair(std::numeric_limits<int8_t>::max(),
88 std::numeric_limits<int8_t>::min());
90 return std::make_pair(std::numeric_limits<int16_t>::max(),
91 std::numeric_limits<int16_t>::min());
93 return std::make_pair(std::numeric_limits<int32_t>::max(),
94 std::numeric_limits<int32_t>::min());
96 return std::make_pair(std::numeric_limits<int64_t>::max(),
97 std::numeric_limits<int64_t>::min());
104 switch (byte_width) {
106 return std::make_pair(std::numeric_limits<uint8_t>::max(),
107 std::numeric_limits<uint8_t>::min());
109 return std::make_pair(std::numeric_limits<uint16_t>::max(),
110 std::numeric_limits<uint16_t>::min());
112 return std::make_pair(std::numeric_limits<uint32_t>::max(),
113 std::numeric_limits<uint32_t>::min());
115 return std::make_pair(std::numeric_limits<uint64_t>::max(),
116 std::numeric_limits<uint64_t>::min());
125 const bool enable_compaction,
126 const unsigned min_byte_width_to_compact) {
128 const auto byte_width =
131 unsigned(min_byte_width_to_compact))
140 switch (byte_width) {
143 return *
reinterpret_cast<const int32_t*
>(may_alias_ptr(&null_float));
147 return *
reinterpret_cast<const int64_t*
>(may_alias_ptr(&null_double));
156 switch (byte_width) {
158 const float zero_float{0.};
160 ? *
reinterpret_cast<const int32_t*
>(may_alias_ptr(&zero_float))
164 const double zero_double{0.};
166 ? *
reinterpret_cast<const int64_t*
>(may_alias_ptr(&zero_double))
179 switch (byte_width) {
182 return ti.
get_notnull() ? std::numeric_limits<int8_t>::max()
187 return ti.
get_notnull() ? std::numeric_limits<int16_t>::max()
191 const float max_float = std::numeric_limits<float>::max();
192 const float null_float =
196 ? *
reinterpret_cast<const int32_t*
>(may_alias_ptr(&max_float))
197 : *reinterpret_cast<const int32_t*>(
198 may_alias_ptr(&null_float)))
199 : (ti.
get_notnull() ? std::numeric_limits<int32_t>::max()
203 const double max_double = std::numeric_limits<double>::max();
206 may_alias_ptr(&max_double))
207 : *reinterpret_cast<const int64_t*>(
208 may_alias_ptr(&null_double)))
209 : (ti.
get_notnull() ? std::numeric_limits<int64_t>::max()
219 switch (byte_width) {
222 return ti.
get_notnull() ? std::numeric_limits<int8_t>::min()
227 return ti.
get_notnull() ? std::numeric_limits<int16_t>::min()
231 const float min_float = -std::numeric_limits<float>::max();
232 const float null_float =
236 ? *
reinterpret_cast<const int32_t*
>(may_alias_ptr(&min_float))
237 : *reinterpret_cast<const int32_t*>(
238 may_alias_ptr(&null_float)))
239 : (ti.
get_notnull() ? std::numeric_limits<int32_t>::min()
243 const double min_double = -std::numeric_limits<double>::max();
246 may_alias_ptr(&min_double))
247 : *reinterpret_cast<const int64_t*>(
248 may_alias_ptr(&null_double)))
249 : (ti.
get_notnull() ? std::numeric_limits<int64_t>::min()
262 const std::vector<Analyzer::Expr*>& targets,
263 const std::list<std::shared_ptr<Analyzer::Expr>>& quals,
265 std::vector<TargetInfo> target_infos;
266 target_infos.reserve(targets.size());
267 const auto agg_col_count = query_mem_desc.
getSlotCount();
268 for (
size_t target_idx = 0, agg_col_idx = 0;
269 target_idx < targets.size() && agg_col_idx < agg_col_count;
270 ++target_idx, ++agg_col_idx) {
271 const auto target_expr = targets[target_idx];
273 auto arg_expr =
agg_arg(target_expr);
278 (target.agg_kind ==
kMIN || target.agg_kind ==
kMAX ||
279 target.agg_kind ==
kSUM || target.agg_kind ==
kAVG ||
286 target_infos.push_back(target);
293 return agg_expr ? agg_expr->
get_arg() :
nullptr;
297 const std::list<std::shared_ptr<Analyzer::Expr>>& quals) {
298 for (
const auto& qual : quals) {
303 bool is_negated{
false};
304 if (uoper->get_optype() ==
kNOT) {
305 uoper = std::dynamic_pointer_cast<
Analyzer::UOper>(uoper->get_own_operand());
308 if (uoper && (uoper->get_optype() ==
kISNOTNULL ||
309 (is_negated && uoper->get_optype() ==
kISNULL))) {
310 if (*uoper->get_own_operand() == *expr) {
const Analyzer::Expr * agg_arg(const Analyzer::Expr *expr)
bool constrained_not_null(const Analyzer::Expr *expr, const std::list< std::shared_ptr< Analyzer::Expr >> &quals)
unsigned compact_byte_width(unsigned qw, unsigned low_bound)
size_t getSlotCount() const
TargetInfo get_target_info(const PointerType target_expr, const bool bigint_count)
int64_t get_agg_initial_val(const SQLAgg agg, const SQLTypeInfo &ti, const bool enable_compaction, const unsigned min_byte_width_to_compact)
bool takes_float_argument(const TargetInfo &target_info)
double inline_fp_null_val(const SQL_TYPE_INFO &ti)
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
int get_logical_size() const
const SQLTypeInfo get_compact_type(const TargetInfo &target)
HOST DEVICE bool get_notnull() const
size_t get_bit_width(const SQLTypeInfo &ti)
std::pair< uint64_t, uint64_t > inline_uint_max_min(const size_t byte_width)
Descriptor for the result set buffer layout.
size_t getCompactByteWidth() const
bool isLogicalSizedColumnsAllowed() const
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
std::pair< int64_t, int64_t > inline_int_max_min(const size_t byte_width)
QueryDescriptionType getQueryDescriptionType() const
std::vector< int64_t > init_agg_val_vec(const std::vector< TargetInfo > &targets, const QueryMemoryDescriptor &query_mem_desc)
void set_notnull(TargetInfo &target, const bool not_null)