OmniSciDB  c1a53651b2
 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  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  return shared::is_any<kMIN, kMAX, kSINGLE_VALUE, kSAMPLE, kMODE, kCOUNT_IF>(agg_kind);
81 }
82 
83 namespace target_info {
85  const bool bigint_count);
86 }
87 
88 inline TargetInfo get_target_info(const Analyzer::Expr* target_expr,
89  const bool bigint_count) {
90  return target_info::get_target_info_impl(target_expr, bigint_count);
91 }
92 
93 inline TargetInfo get_target_info(const std::shared_ptr<Analyzer::Expr> target_expr,
94  const bool bigint_count) {
95  return target_info::get_target_info_impl(target_expr.get(), bigint_count);
96 }
97 
98 inline bool is_distinct_target(const TargetInfo& target_info) {
99  return target_info.is_distinct || target_info.agg_kind == kAPPROX_COUNT_DISTINCT;
100 }
101 
102 inline bool takes_float_argument(const TargetInfo& target_info) {
103  return target_info.is_agg && target_info.agg_arg_type.get_type() == kFLOAT &&
104  shared::is_any<kAVG, kSUM, kSUM_IF, kMIN, kMAX, kSINGLE_VALUE, kMODE>(
105  target_info.agg_kind);
106 }
107 
108 #endif // QUERYENGINE_TARGETINFO_H
Defines data structures for the semantic analysis phase of query processing.
SQLAgg
Definition: sqldefs.h:73
SQLTypeInfo sql_type
Definition: TargetInfo.h:52
bool is_agg_domain_range_equivalent(const SQLAgg agg_kind)
Definition: TargetInfo.h:79
Constants for Builtin SQL Types supported by HEAVY.AI.
bool takes_float_argument(const TargetInfo &target_info)
Definition: TargetInfo.h:102
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:381
bool skip_null_val
Definition: TargetInfo.h:54
TargetInfo get_target_info(const Analyzer::Expr *target_expr, const bool bigint_count)
Definition: TargetInfo.h:88
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:547
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:98
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