OmniSciDB  ca0c39ec8f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StringOpInfo.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 
17 #pragma once
18 
19 #ifndef __CUDACC__
20 
21 #include "Shared/sqldefs.h"
22 #include "Shared/sqltypes.h"
23 
24 #include <map>
25 #include <memory>
26 #include <ostream>
27 
28 namespace StringOps_Namespace {
29 
30 using LiteralArgMap = std::map<size_t, std::pair<SQLTypes, Datum>>;
31 
32 struct StringOpInfo {
33  public:
35  const SQLTypeInfo& return_ti,
36  const LiteralArgMap& literal_arg_map)
37  : op_kind_(op_kind)
38  , return_ti_(return_ti)
39  , literal_arg_map_(literal_arg_map)
41 
42  const SqlStringOpKind& getOpKind() const { return op_kind_; }
43 
44  const LiteralArgMap& getLiteralArgMap() const { return literal_arg_map_; }
45 
46  size_t numLiterals() const { return literal_arg_map_.size(); }
47 
49 
50  bool intLiteralArgAtIdxExists(const size_t index) const;
51 
52  bool stringLiteralArgAtIdxExists(const size_t index) const;
53 
54  size_t numNonVariableLiterals() const {
55  return literal_arg_map_.size() - (hasVarStringLiteral() ? 1UL : 0UL);
56  }
57 
58  const SQLTypeInfo& getReturnType() const { return return_ti_; }
59 
60  bool hasNullLiteralArg() const { return num_null_literals_ > 0UL; }
61 
62  std::string getStringLiteral(const size_t index) const;
63 
64  int64_t getIntLiteral(const size_t index) const;
65 
66  std::string toString() const;
67 
68  friend std::ostream& operator<<(std::ostream& stream,
69  const StringOpInfo& string_op_info);
70 
71  private:
72  static bool isLiteralArgNull(const SQLTypes datum_type, const Datum& datum);
73 
74  static size_t calcNumNullLiteralArgs(const LiteralArgMap& literal_arg_map);
75 
79  const size_t num_null_literals_;
80 };
81 
82 std::ostream& operator<<(std::ostream& stream,
83  const std::vector<StringOpInfo>& string_op_infos);
84 
85 } // namespace StringOps_Namespace
86 
87 #endif // #ifndef __CUDACC__
const SQLTypeInfo & getReturnType() const
Definition: StringOpInfo.h:58
bool stringLiteralArgAtIdxExists(const size_t index) const
SQLTypes
Definition: sqltypes.h:53
static size_t calcNumNullLiteralArgs(const LiteralArgMap &literal_arg_map)
static bool isLiteralArgNull(const SQLTypes datum_type, const Datum &datum)
SqlStringOpKind
Definition: sqldefs.h:84
Constants for Builtin SQL Types supported by HEAVY.AI.
std::map< size_t, std::pair< SQLTypes, Datum >> LiteralArgMap
Definition: StringOpInfo.h:30
bool intLiteralArgAtIdxExists(const size_t index) const
int64_t getIntLiteral(const size_t index) const
size_t numNonVariableLiterals() const
Definition: StringOpInfo.h:54
const SqlStringOpKind op_kind_
Definition: StringOpInfo.h:76
const LiteralArgMap & getLiteralArgMap() const
Definition: StringOpInfo.h:44
StringOpInfo(const SqlStringOpKind op_kind, const SQLTypeInfo &return_ti, const LiteralArgMap &literal_arg_map)
Definition: StringOpInfo.h:34
std::ostream & operator<<(std::ostream &stream, const StringOpInfo &string_op_info)
const LiteralArgMap literal_arg_map_
Definition: StringOpInfo.h:78
std::string getStringLiteral(const size_t index) const
friend std::ostream & operator<<(std::ostream &stream, const StringOpInfo &string_op_info)
Common Enum definitions for SQL processing.
const SqlStringOpKind & getOpKind() const
Definition: StringOpInfo.h:42
Definition: Datum.h:44