OmniSciDB  cde582ebc3
 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:
34  StringOpInfo(const SqlStringOpKind op_kind, const LiteralArgMap& literal_arg_map)
35  : op_kind_(op_kind)
36  , literal_arg_map_(literal_arg_map)
38 
39  const SqlStringOpKind& getOpKind() const { return op_kind_; }
40 
41  const LiteralArgMap& getLiteralArgMap() const { return literal_arg_map_; }
42 
43  size_t numLiterals() const { return literal_arg_map_.size(); }
44 
46 
47  bool intLiteralArgAtIdxExists(const size_t index) const;
48 
49  bool stringLiteralArgAtIdxExists(const size_t index) const;
50 
51  size_t numNonVariableLiterals() const {
52  return literal_arg_map_.size() - (hasVarStringLiteral() ? 1UL : 0UL);
53  }
54 
55  bool hasNullLiteralArg() const { return num_null_literals_ > 0UL; }
56 
57  std::string getStringLiteral(const size_t index) const;
58 
59  int64_t getIntLiteral(const size_t index) const;
60 
61  std::string toString() const;
62 
63  friend std::ostream& operator<<(std::ostream& stream,
64  const StringOpInfo& string_op_info);
65 
66  private:
67  static bool isLiteralArgNull(const SQLTypes datum_type, const Datum& datum);
68 
69  static size_t calcNumNullLiteralArgs(const LiteralArgMap& literal_arg_map);
70 
73  const size_t num_null_literals_;
74 };
75 
76 std::ostream& operator<<(std::ostream& stream,
77  const std::vector<StringOpInfo>& string_op_infos);
78 
79 } // namespace StringOps_Namespace
80 
81 #endif // #ifndef __CUDACC__
bool stringLiteralArgAtIdxExists(const size_t index) const
SQLTypes
Definition: sqltypes.h:38
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:51
const SqlStringOpKind op_kind_
Definition: StringOpInfo.h:71
const LiteralArgMap & getLiteralArgMap() const
Definition: StringOpInfo.h:41
StringOpInfo(const SqlStringOpKind op_kind, 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:72
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:39