OmniSciDB  c0231cc57d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TargetInfo.h
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 
23 #ifndef QUERYENGINE_TARGETINFO_H
24 #define QUERYENGINE_TARGETINFO_H
25 
26 #include "sqldefs.h"
27 #include "sqltypes.h"
28 
29 #include "../Analyzer/Analyzer.h"
30 
31 inline const Analyzer::AggExpr* cast_to_agg_expr(const Analyzer::Expr* target_expr) {
32  return dynamic_cast<const Analyzer::AggExpr*>(target_expr);
33 }
34 
36  const std::shared_ptr<Analyzer::Expr> target_expr) {
37  return dynamic_cast<const Analyzer::AggExpr*>(target_expr.get());
38 }
39 
40 inline bool target_expr_has_varlen_projection(const Analyzer::Expr* target_expr) {
41  return !(dynamic_cast<const Analyzer::GeoExpr*>(target_expr) == nullptr);
42 }
43 
45  const std::shared_ptr<Analyzer::Expr> target_expr) {
46  return !(dynamic_cast<const Analyzer::GeoExpr*>(target_expr.get()) == nullptr);
47 }
48 
49 struct TargetInfo {
50  bool is_agg;
57 #ifndef __CUDACC__
58  public:
59  inline std::string toString() const {
60  auto result = std::string("TargetInfo(");
61  result += "is_agg=" + std::string(is_agg ? "true" : "false") + ", ";
62  result += "agg_kind=" + ::toString(agg_kind) + ", ";
63  result += "sql_type=" + sql_type.to_string() + ", ";
64  result += "agg_arg_type=" + agg_arg_type.to_string() + ", ";
65  result += "skip_null_val=" + std::string(skip_null_val ? "true" : "false") + ", ";
66  result += "is_distinct=" + std::string(is_distinct ? "true" : "false") + ")";
67  result +=
68  "is_varlen_projection=" + std::string(is_varlen_projection ? "true" : "false") +
69  ")";
70  return result;
71  }
72 #endif
73 };
74 
79 inline bool is_agg_domain_range_equivalent(const SQLAgg& agg_kind) {
80  switch (agg_kind) {
81  case kMIN:
82  case kMAX:
83  case kSINGLE_VALUE:
84  case kSAMPLE:
85  return true;
86  default:
87  break;
88  }
89  return false;
90 }
91 
92 namespace target_info {
94  const bool bigint_count);
95 }
96 
97 inline TargetInfo get_target_info(const Analyzer::Expr* target_expr,
98  const bool bigint_count) {
99  return target_info::get_target_info_impl(target_expr, bigint_count);
100 }
101 
102 inline TargetInfo get_target_info(const std::shared_ptr<Analyzer::Expr> target_expr,
103  const bool bigint_count) {
104  return target_info::get_target_info_impl(target_expr.get(), bigint_count);
105 }
106 
107 inline bool is_distinct_target(const TargetInfo& target_info) {
108  return target_info.is_distinct || target_info.agg_kind == kAPPROX_COUNT_DISTINCT;
109 }
110 
111 inline bool takes_float_argument(const TargetInfo& target_info) {
112  return target_info.is_agg &&
113  (target_info.agg_kind == kAVG || target_info.agg_kind == kSUM ||
114  target_info.agg_kind == kMIN || target_info.agg_kind == kMAX ||
115  target_info.agg_kind == kSINGLE_VALUE) &&
116  target_info.agg_arg_type.get_type() == kFLOAT;
117 }
118 
119 #endif // QUERYENGINE_TARGETINFO_H
SQLAgg
Definition: sqldefs.h:72
SQLTypeInfo sql_type
Definition: TargetInfo.h:52
Constants for Builtin SQL Types supported by HEAVY.AI.
bool takes_float_argument(const TargetInfo &target_info)
Definition: TargetInfo.h:111
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:404
bool skip_null_val
Definition: TargetInfo.h:54
TargetInfo get_target_info(const Analyzer::Expr *target_expr, const bool bigint_count)
Definition: TargetInfo.h:97
SQLTypeInfo agg_arg_type
Definition: TargetInfo.h:53
bool target_expr_has_varlen_projection(const Analyzer::Expr *target_expr)
Definition: TargetInfo.h:40
bool is_varlen_projection
Definition: TargetInfo.h:56
Definition: sqldefs.h:74
std::string to_string() const
Definition: sqltypes.h:568
bool is_agg
Definition: TargetInfo.h:50
std::string toString() const
Definition: TargetInfo.h:59
Definition: sqldefs.h:76
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:107
SQLAgg agg_kind
Definition: TargetInfo.h:51
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
Common Enum definitions for SQL processing.
bool is_distinct
Definition: TargetInfo.h:55
Definition: sqldefs.h:75
Definition: sqldefs.h:73
bool is_agg_domain_range_equivalent(const SQLAgg &agg_kind)
Definition: TargetInfo.h:79