OmniSciDB  ca0c39ec8f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TargetValue.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_TARGETVALUE_H
24 #define QUERYENGINE_TARGETVALUE_H
25 
26 #include <boost/optional.hpp>
27 #include <boost/variant.hpp>
28 #include "Logger/Logger.h"
29 
30 #include <Shared/sqltypes.h>
31 
32 #include <cstdint>
33 #include <string>
34 #include <vector>
35 
37  int64_t i1;
38  int64_t i2;
39 
40  enum class ITVType { Int, Pair, Str, Arr, Null };
41 
43 
44  explicit InternalTargetValue(const int64_t i1_) : i1(i1_), ty(ITVType::Int) {}
45 
46  explicit InternalTargetValue(const int64_t i1_, const int64_t i2_)
47  : i1(i1_), i2(i2_), ty(ITVType::Pair) {}
48 
49  explicit InternalTargetValue(const std::string* s)
50  : i1(reinterpret_cast<int64_t>(s)), ty(ITVType::Str) {}
51 
52  explicit InternalTargetValue(const std::vector<int64_t>* v)
53  : i1(reinterpret_cast<int64_t>(v)), ty(ITVType::Arr) {}
54 
55  explicit InternalTargetValue() : ty(ITVType::Null) {}
56 
57  std::string strVal() const { return *reinterpret_cast<std::string*>(i1); }
58 
59  std::vector<int64_t> arrVal() const {
60  return *reinterpret_cast<std::vector<int64_t>*>(i1);
61  }
62 
63  bool isInt() const { return ty == ITVType::Int; }
64 
65  bool isPair() const { return ty == ITVType::Pair; }
66 
67  bool isNull() const { return ty == ITVType::Null; }
68 
69  bool isStr() const { return ty == ITVType::Str; }
70 
71  bool operator<(const InternalTargetValue& other) const {
72  switch (ty) {
73  case ITVType::Int:
74  CHECK(other.ty == ITVType::Int);
75  return i1 < other.i1;
76  case ITVType::Pair:
77  CHECK(other.ty == ITVType::Pair);
78  if (i1 != other.i1) {
79  return i1 < other.i1;
80  }
81  return i2 < other.i2;
82  case ITVType::Str:
83  CHECK(other.ty == ITVType::Str);
84  return strVal() < other.strVal();
85  case ITVType::Null:
86  return false;
87  default:
88  abort();
89  }
90  }
91 
92  bool operator==(const InternalTargetValue& other) const {
93  return !(*this < other || other < *this);
94  }
95 };
96 
98  std::shared_ptr<std::vector<double>> coords;
99 
100  GeoPointTargetValue(const std::vector<double>& coords)
101  : coords(std::make_shared<std::vector<double>>(coords)) {}
102 };
103 
105  std::shared_ptr<std::vector<double>> coords;
106 
107  GeoMultiPointTargetValue(const std::vector<double>& coords)
108  : coords(std::make_shared<std::vector<double>>(coords)) {}
109 };
110 
112  std::shared_ptr<std::vector<double>> coords;
113 
114  GeoLineStringTargetValue(const std::vector<double>& coords)
115  : coords(std::make_shared<std::vector<double>>(coords)) {}
116 };
117 
119  std::shared_ptr<std::vector<double>> coords;
120  std::shared_ptr<std::vector<int32_t>> linestring_sizes;
121 
122  GeoMultiLineStringTargetValue(const std::vector<double>& coords,
123  const std::vector<int32_t>& linestring_sizes)
124  : coords(std::make_shared<std::vector<double>>(coords))
125  , linestring_sizes(std::make_shared<std::vector<int32_t>>(linestring_sizes)) {}
126 };
127 
129  std::shared_ptr<std::vector<double>> coords;
130  std::shared_ptr<std::vector<int32_t>> ring_sizes;
131 
132  GeoPolyTargetValue(const std::vector<double>& coords,
133  const std::vector<int32_t>& ring_sizes)
134  : coords(std::make_shared<std::vector<double>>(coords))
135  , ring_sizes(std::make_shared<std::vector<int32_t>>(ring_sizes)) {}
136 };
137 
139  std::shared_ptr<std::vector<double>> coords;
140  std::shared_ptr<std::vector<int32_t>> ring_sizes;
141  std::shared_ptr<std::vector<int32_t>> poly_rings;
142 
143  GeoMultiPolyTargetValue(const std::vector<double>& coords,
144  const std::vector<int32_t>& ring_sizes,
145  const std::vector<int32_t>& poly_rings)
146  : coords(std::make_shared<std::vector<double>>(coords))
147  , ring_sizes(std::make_shared<std::vector<int32_t>>(ring_sizes))
148  , poly_rings(std::make_shared<std::vector<int32_t>>(poly_rings)) {}
149 };
150 
152  std::shared_ptr<VarlenDatum> coords_data;
153 };
154 
156  std::shared_ptr<VarlenDatum> coords_data;
157 };
158 
160  std::shared_ptr<VarlenDatum> coords_data;
161 };
162 
164  std::shared_ptr<VarlenDatum> coords_data;
165  std::shared_ptr<VarlenDatum> linestring_sizes_data;
166 };
167 
169  std::shared_ptr<VarlenDatum> coords_data;
170  std::shared_ptr<VarlenDatum> ring_sizes_data;
171 };
172 
174  std::shared_ptr<VarlenDatum> coords_data;
175  std::shared_ptr<VarlenDatum> ring_sizes_data;
176  std::shared_ptr<VarlenDatum> poly_rings_data;
177 };
178 
179 using NullableString = boost::variant<std::string, void*>;
180 using ScalarTargetValue = boost::variant<int64_t, double, float, NullableString>;
181 using ArrayTargetValue = boost::optional<std::vector<ScalarTargetValue>>;
182 using GeoTargetValue = boost::optional<boost::variant<GeoPointTargetValue,
188 using GeoTargetValuePtr = boost::variant<GeoPointTargetValuePtr,
194 using TargetValue = boost::
195  variant<ScalarTargetValue, ArrayTargetValue, GeoTargetValue, GeoTargetValuePtr>;
196 
197 #endif // QUERYENGINE_TARGETVALUE_H
bool operator<(const InternalTargetValue &other) const
Definition: TargetValue.h:71
std::string strVal() const
Definition: TargetValue.h:57
bool isPair() const
Definition: TargetValue.h:65
InternalTargetValue(const int64_t i1_)
Definition: TargetValue.h:44
std::shared_ptr< VarlenDatum > linestring_sizes_data
Definition: TargetValue.h:165
GeoPolyTargetValue(const std::vector< double > &coords, const std::vector< int32_t > &ring_sizes)
Definition: TargetValue.h:132
bool isStr() const
Definition: TargetValue.h:69
GeoMultiLineStringTargetValue(const std::vector< double > &coords, const std::vector< int32_t > &linestring_sizes)
Definition: TargetValue.h:122
std::shared_ptr< VarlenDatum > coords_data
Definition: TargetValue.h:169
GeoMultiPolyTargetValue(const std::vector< double > &coords, const std::vector< int32_t > &ring_sizes, const std::vector< int32_t > &poly_rings)
Definition: TargetValue.h:143
std::shared_ptr< std::vector< int32_t > > ring_sizes
Definition: TargetValue.h:140
std::shared_ptr< VarlenDatum > poly_rings_data
Definition: TargetValue.h:176
Constants for Builtin SQL Types supported by HEAVY.AI.
std::shared_ptr< std::vector< double > > coords
Definition: TargetValue.h:139
InternalTargetValue(const std::string *s)
Definition: TargetValue.h:49
std::shared_ptr< std::vector< int32_t > > poly_rings
Definition: TargetValue.h:141
std::shared_ptr< std::vector< double > > coords
Definition: TargetValue.h:112
GeoLineStringTargetValue(const std::vector< double > &coords)
Definition: TargetValue.h:114
GeoPointTargetValue(const std::vector< double > &coords)
Definition: TargetValue.h:100
std::shared_ptr< std::vector< double > > coords
Definition: TargetValue.h:105
std::shared_ptr< std::vector< int32_t > > linestring_sizes
Definition: TargetValue.h:120
boost::optional< std::vector< ScalarTargetValue >> ArrayTargetValue
Definition: TargetValue.h:181
std::shared_ptr< std::vector< int32_t > > ring_sizes
Definition: TargetValue.h:130
std::shared_ptr< VarlenDatum > ring_sizes_data
Definition: TargetValue.h:170
boost::optional< boost::variant< GeoPointTargetValue, GeoMultiPointTargetValue, GeoLineStringTargetValue, GeoMultiLineStringTargetValue, GeoPolyTargetValue, GeoMultiPolyTargetValue >> GeoTargetValue
Definition: TargetValue.h:187
std::shared_ptr< std::vector< double > > coords
Definition: TargetValue.h:98
bool isNull() const
Definition: TargetValue.h:67
std::shared_ptr< VarlenDatum > coords_data
Definition: TargetValue.h:156
InternalTargetValue(const int64_t i1_, const int64_t i2_)
Definition: TargetValue.h:46
boost::variant< GeoPointTargetValuePtr, GeoMultiPointTargetValuePtr, GeoLineStringTargetValuePtr, GeoMultiLineStringTargetValuePtr, GeoPolyTargetValuePtr, GeoMultiPolyTargetValuePtr > GeoTargetValuePtr
Definition: TargetValue.h:193
std::vector< int64_t > arrVal() const
Definition: TargetValue.h:59
std::shared_ptr< VarlenDatum > coords_data
Definition: TargetValue.h:160
std::shared_ptr< std::vector< double > > coords
Definition: TargetValue.h:119
boost::variant< std::string, void * > NullableString
Definition: TargetValue.h:179
GeoMultiPointTargetValue(const std::vector< double > &coords)
Definition: TargetValue.h:107
bool isInt() const
Definition: TargetValue.h:63
#define CHECK(condition)
Definition: Logger.h:222
std::shared_ptr< VarlenDatum > coords_data
Definition: TargetValue.h:152
boost::variant< ScalarTargetValue, ArrayTargetValue, GeoTargetValue, GeoTargetValuePtr > TargetValue
Definition: TargetValue.h:195
std::shared_ptr< VarlenDatum > coords_data
Definition: TargetValue.h:174
InternalTargetValue(const std::vector< int64_t > *v)
Definition: TargetValue.h:52
std::shared_ptr< std::vector< double > > coords
Definition: TargetValue.h:129
bool operator==(const InternalTargetValue &other) const
Definition: TargetValue.h:92
std::shared_ptr< VarlenDatum > ring_sizes_data
Definition: TargetValue.h:175
std::shared_ptr< VarlenDatum > coords_data
Definition: TargetValue.h:164
boost::variant< int64_t, double, float, NullableString > ScalarTargetValue
Definition: TargetValue.h:180