OmniSciDB  c0231cc57d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TargetInfo.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 Heavy.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "TargetInfo.h"
18 
19 namespace target_info {
21  const bool bigint_count) {
22  const auto agg_expr = cast_to_agg_expr(target_expr);
23  bool notnull = target_expr->get_type_info().get_notnull();
24  if (!agg_expr) {
26  auto target_ti = target_expr ? get_logical_type_info(target_expr->get_type_info())
27  : SQLTypeInfo(kBIGINT, notnull);
28  return {false,
29  kMIN,
30  target_ti,
31  SQLTypeInfo(kNULLT, false),
32  false,
33  false,
34  is_varlen_projection};
35  }
36  const auto agg_type = agg_expr->get_aggtype();
37  const auto agg_arg = agg_expr->get_arg();
38  if (!agg_arg) {
39  CHECK_EQ(kCOUNT, agg_type);
40  CHECK(!agg_expr->get_is_distinct());
41  return {true,
42  kCOUNT,
43  SQLTypeInfo(bigint_count ? kBIGINT : kINT, notnull),
44  SQLTypeInfo(kNULLT, false),
45  false,
46  false,
47  false};
48  }
49 
50  const auto& agg_arg_ti = agg_arg->get_type_info();
51  bool is_distinct{false};
52  if (agg_expr->get_aggtype() == kCOUNT) {
53  is_distinct = agg_expr->get_is_distinct();
54  }
55 
56  if (agg_type == kAVG) {
57  // Upcast the target type for AVG, so that the integer argument does not overflow the
58  // sum
59  return {true,
60  agg_expr->get_aggtype(),
61  agg_arg_ti.is_integer() ? SQLTypeInfo(kBIGINT, agg_arg_ti.get_notnull())
62  : agg_arg_ti,
63  agg_arg_ti,
64  !agg_arg_ti.get_notnull(),
66  false};
67  }
68 
69  return {
70  true,
71  agg_expr->get_aggtype(),
72  agg_type == kCOUNT
73  ? SQLTypeInfo((is_distinct || bigint_count) ? kBIGINT : kINT, notnull)
74  : agg_expr->get_type_info(),
75  agg_arg_ti,
76  agg_type == kCOUNT && agg_arg_ti.is_varlen() ? false : !agg_arg_ti.get_notnull(),
78  false};
79 }
80 } // namespace target_info
const Analyzer::Expr * agg_arg(const Analyzer::Expr *expr)
#define CHECK_EQ(x, y)
Definition: Logger.h:230
SQLTypeInfo get_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1221
bool target_expr_has_varlen_projection(const Analyzer::Expr *target_expr)
Definition: TargetInfo.h:40
Definition: sqldefs.h:74
bool is_varlen_projection(const Analyzer::Expr *target_expr, const SQLTypeInfo &ti)
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:82
TargetInfo get_target_info_impl(const Analyzer::Expr *target_expr, const bool bigint_count)
Definition: TargetInfo.cpp:20
const Analyzer::AggExpr * cast_to_agg_expr(const Analyzer::Expr *target_expr)
Definition: TargetInfo.h:31
Definition: sqldefs.h:77
#define CHECK(condition)
Definition: Logger.h:222
Definition: sqltypes.h:59
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:411
Definition: sqldefs.h:73
bool is_distinct(const size_t input_idx, const RelAlgNode *node)