OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sqltypes_lite.h
Go to the documentation of this file.
1 /*
2  * Copyright 2023 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 /*
18  Provides a light-weight data structure SQLTypeInfoLite to serialize
19  SQLTypeInfo (from sqltypes.h) for the extension functions (in
20  heavydbTypes.h) by FlatBufferManager.
21 
22  Extend SQLTypeInfoLite struct as needed but keep it simple so that
23  both sqltypes.h and heavydbTypes.h are able to include it (recall,
24  the two header files cannot include each other).
25 */
26 
27 #pragma once
28 
30  enum SQLTypes {
35  INT,
47  };
48  enum EncodingType {
49  NONE = 0,
50  DICT, // used by TEXT and ARRAY of TEXT
51  GEOINT // used by geotypes
52  };
54  SQLTypes subtype; // used by ARRAY
55  EncodingType compression; // used by geotypes and TEXT and ARRAY of TEXT
56  int32_t dimension; // used by geotypes (input_srid)
57  int32_t scale; // used by geotypes (output_srid)
58  int32_t db_id; // used by TEXT and ARRAY of TEXT
59  int32_t dict_id; // used by TEXT and ARRAY of TEXT
60 
61  inline bool is_geoint() const { return compression == GEOINT; }
62  inline int32_t get_input_srid() const { return dimension; }
63  inline int32_t get_output_srid() const { return scale; }
64 
65  bool operator==(const SQLTypeInfoLite& other) const {
66  if (type != other.type)
67  return false;
68  if (type == ARRAY) {
69  if (subtype != other.subtype)
70  return false;
71  if (subtype == TEXT) {
72  if (compression != other.compression)
73  return false;
74  if (compression == DICT)
75  return db_id == other.db_id && dict_id == other.dict_id;
76  }
77  } else if (type == TEXT) {
78  if (compression != other.compression)
79  return false;
80  if (compression == DICT)
81  return db_id == other.db_id && dict_id == other.dict_id;
82  } else if (type == POINT || type == LINESTRING || type == POLYGON ||
84  if (compression != other.compression)
85  return false;
86  return get_input_srid() == other.get_input_srid() &&
87  get_output_srid() == other.get_output_srid();
88  }
89  return true;
90  }
91 };
92 
93 #if !(defined(__CUDACC__) || defined(NO_BOOST))
94 
95 #include <ostream>
96 
97 inline std::ostream& operator<<(std::ostream& os, const SQLTypeInfoLite::SQLTypes& type) {
98  switch (type) {
99  case SQLTypeInfoLite::SQLTypes::UNSPECIFIED:
100  os << "UNSPECIFIED";
101  break;
102  case SQLTypeInfoLite::SQLTypes::BOOLEAN:
103  os << "BOOLEAN";
104  break;
105  case SQLTypeInfoLite::SQLTypes::TINYINT:
106  os << "TINYINT";
107  break;
108  case SQLTypeInfoLite::SQLTypes::SMALLINT:
109  os << "SMALLINT";
110  break;
111  case SQLTypeInfoLite::SQLTypes::INT:
112  os << "INT";
113  break;
114  case SQLTypeInfoLite::SQLTypes::BIGINT:
115  os << "BIGINT";
116  break;
117  case SQLTypeInfoLite::SQLTypes::FLOAT:
118  os << "FLOAT";
119  break;
120  case SQLTypeInfoLite::SQLTypes::DOUBLE:
121  os << "DOUBLE";
122  break;
123  case SQLTypeInfoLite::SQLTypes::POINT:
124  os << "POINT";
125  break;
126  case SQLTypeInfoLite::SQLTypes::LINESTRING:
127  os << "LINESTRING";
128  break;
129  case SQLTypeInfoLite::SQLTypes::POLYGON:
130  os << "POLYGON";
131  break;
132  case SQLTypeInfoLite::SQLTypes::MULTIPOINT:
133  os << "MULTIPOINT";
134  break;
135  case SQLTypeInfoLite::SQLTypes::MULTILINESTRING:
136  os << "MULTILINESTRING";
137  break;
138  case SQLTypeInfoLite::SQLTypes::MULTIPOLYGON:
139  os << "MULTIPOLYGON";
140  break;
141  case SQLTypeInfoLite::SQLTypes::TEXT:
142  os << "TEXT";
143  break;
144  case SQLTypeInfoLite::SQLTypes::ARRAY:
145  os << "ARRAY";
146  break;
147  }
148  return os;
149 }
150 inline std::ostream& operator<<(std::ostream& os,
152  switch (type) {
153  case SQLTypeInfoLite::EncodingType::NONE:
154  os << "NONE";
155  break;
156  case SQLTypeInfoLite::EncodingType::DICT:
157  os << "DICT";
158  break;
159  case SQLTypeInfoLite::EncodingType::GEOINT:
160  os << "GEOINT";
161  break;
162  }
163  return os;
164 }
165 inline std::ostream& operator<<(std::ostream& os, const SQLTypeInfoLite& ti_lite) {
166  os << "SQLTypeInfoLite(";
167  os << "type=" << ti_lite.type;
168  os << ", subtype=" << ti_lite.subtype;
169  os << ", compression=" << ti_lite.compression;
170  os << ", dimension=" << ti_lite.dimension;
171  os << ", scale=" << ti_lite.scale;
172  os << ", db_id=" << ti_lite.db_id;
173  os << ", dict_id=" << ti_lite.dict_id;
174  os << ")";
175  return os;
176 }
177 #endif
bool is_geoint() const
Definition: sqltypes_lite.h:61
SQLTypes subtype
Definition: sqltypes_lite.h:54
std::ostream & operator<<(std::ostream &os, const SessionInfo &session_info)
Definition: SessionInfo.cpp:57
int32_t get_output_srid() const
Definition: sqltypes_lite.h:63
EncodingType compression
Definition: sqltypes_lite.h:55
bool operator==(const SQLTypeInfoLite &other) const
Definition: sqltypes_lite.h:65
int32_t get_input_srid() const
Definition: sqltypes_lite.h:62