OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ColumnDescriptor.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 #ifndef COLUMN_DESCRIPTOR_H
18 #define COLUMN_DESCRIPTOR_H
19 
20 #include <cassert>
21 #include <optional>
22 #include <string>
23 #include "../Shared/StringTransform.h"
24 #include "../Shared/sqltypes.h"
25 #include "../Shared/toString.h"
26 
34  int tableId;
35  int columnId;
36  std::string columnName;
37  std::string sourceName;
39  std::string chunks;
42  std::string virtualExpr;
44  bool isGeoPhyCol{false};
45  std::optional<std::string> default_value;
46  int32_t db_id;
47 
50  const int columnId,
51  const std::string& columnName,
52  const SQLTypeInfo columnType,
53  int32_t db_id)
54  : tableId(tableId)
55  , columnId(columnId)
56  , columnName(columnName)
57  , sourceName(columnName)
58  , columnType(columnType)
62  , db_id(db_id) {}
64  this->isGeoPhyCol = isGeoPhyCol;
65  }
66 
67  std::string toString() const {
68  return ::typeName(this) + "(tableId=" + ::toString(tableId) +
69  ", columnId=" + ::toString(columnId) +
70  ", columnName=" + ::toString(columnName) +
71  ", columnType=" + ::toString(columnType) +
72  ", defaultValue=" + ::toString(default_value) +
73  ", db_id=" + ::toString(db_id) + ")";
74  }
75 
76  std::string getDefaultValueLiteral() const {
77  // some preprocessing of strings, arrays and especially arrays of strings
78  CHECK(default_value.has_value());
80  return "\'" + default_value.value() + "\'";
81  } else if (columnType.is_array()) {
82  auto value = default_value.value();
83  CHECK(value.front() == '{' && value.back() == '}');
84  value = value.substr(1, value.length() - 2);
86  auto elements = split(value, ", ");
87  value = "ARRAY[";
88  for (size_t i = 0; i < elements.size(); ++i) {
89  value += "'" + elements[i] + "'";
90  if (i != elements.size() - 1) {
91  value += ", ";
92  }
93  }
94  value += "]";
95  } else {
96  value = "ARRAY[" + value + "]";
97  }
98  return value;
99  } else {
100  return default_value.value();
101  }
102  }
103 };
104 
105 #endif // COLUMN_DESCRIPTOR
std::string virtualExpr
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:392
bool is_time() const
Definition: sqltypes.h:579
std::string sourceName
std::vector< std::string > split(std::string_view str, std::string_view delim, std::optional< size_t > maxsplit)
split apart a string into a vector of substrings
std::string chunks
std::string getDefaultValueLiteral() const
ColumnDescriptor(const int tableId, const int columnId, const std::string &columnName, const SQLTypeInfo columnType, int32_t db_id)
specifies the content in-memory of a row in the column metadata table
std::optional< std::string > default_value
std::string typeName(const T *v)
Definition: toString.h:106
bool g_enable_watchdog false
Definition: Execute.cpp:80
ColumnDescriptor(const bool isGeoPhyCol)
#define CHECK(condition)
Definition: Logger.h:291
bool is_geometry() const
Definition: sqltypes.h:597
SQLTypeInfo columnType
bool is_string() const
Definition: sqltypes.h:561
bool is_string_array() const
Definition: sqltypes.h:564
std::string columnName
bool is_array() const
Definition: sqltypes.h:585
std::string toString() const
constexpr auto is_datetime(SQLTypes type)
Definition: sqltypes.h:325