OmniSciDB  a5dc49c757
 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 "Analyzer/Analyzer.h"
27 #include "misc.h"
28 #include "sqldefs.h"
29 #include "sqltypes.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  if (is_agg) {
63  result += "agg_kind=" + ::toString(agg_kind) + ", ";
64  }
65  result += "sql_type=" + sql_type.to_string() + ", ";
66  if (is_agg) {
67  result += "agg_arg_type=" + agg_arg_type.to_string() + ", ";
68  }
69  result += "skip_null_val=" + std::string(skip_null_val ? "true" : "false") + ", ";
70  result += "is_distinct=" + std::string(is_distinct ? "true" : "false") + ", ";
71  result +=
72  "is_varlen_projection=" + std::string(is_varlen_projection ? "true" : "false") +
73  ")";
74  return result;
75  }
76 #endif
77 };
78 
83 inline bool is_agg_domain_range_equivalent(const SQLAgg agg_kind) {
84  return shared::is_any<kMIN, kMAX, kSINGLE_VALUE, kSAMPLE, kMODE, kCOUNT_IF>(agg_kind);
85 }
86 
87 namespace target_info {
89  const bool bigint_count);
90 }
91 
92 inline TargetInfo get_target_info(const Analyzer::Expr* target_expr,
93  const bool bigint_count) {
94  return target_info::get_target_info_impl(target_expr, bigint_count);
95 }
96 
97 inline TargetInfo get_target_info(const std::shared_ptr<Analyzer::Expr> target_expr,
98  const bool bigint_count) {
99  return target_info::get_target_info_impl(target_expr.get(), bigint_count);
100 }
101 
102 inline bool is_distinct_target(const TargetInfo& target_info) {
103  return target_info.is_distinct || target_info.agg_kind == kAPPROX_COUNT_DISTINCT;
104 }
105 
106 inline bool takes_float_argument(const TargetInfo& target_info) {
107  return target_info.is_agg && target_info.agg_arg_type.get_type() == kFLOAT &&
108  shared::is_any<kAVG, kSUM, kSUM_IF, kMIN, kMAX, kSINGLE_VALUE, kMODE>(
109  target_info.agg_kind);
110 }
111 
112 #endif // QUERYENGINE_TARGETINFO_H
Defines data structures for the semantic analysis phase of query processing.
SQLAgg
Definition: sqldefs.h:76
SQLTypeInfo sql_type
Definition: TargetInfo.h:52
bool is_agg_domain_range_equivalent(const SQLAgg agg_kind)
Definition: TargetInfo.h:83
Constants for Builtin SQL Types supported by HEAVY.AI.
bool takes_float_argument(const TargetInfo &target_info)
Definition: TargetInfo.h:106
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
bool skip_null_val
Definition: TargetInfo.h:54
TargetInfo get_target_info(const Analyzer::Expr *target_expr, const bool bigint_count)
Definition: TargetInfo.h:92
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
std::string to_string() const
Definition: sqltypes.h:528
bool is_agg
Definition: TargetInfo.h:50
std::string toString() const
Definition: TargetInfo.h:59
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:102
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