OmniSciDB  cde582ebc3
 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 
49  const int columnId,
50  const std::string& columnName,
51  const SQLTypeInfo columnType)
52  : tableId(tableId)
53  , columnId(columnId)
54  , columnName(columnName)
55  , sourceName(columnName)
56  , columnType(columnType)
59  , isDeletedCol(false) {}
61  this->isGeoPhyCol = isGeoPhyCol;
62  }
63 
64  std::string toString() const {
65  return ::typeName(this) + "(tableId=" + ::toString(tableId) +
66  ", columnId=" + ::toString(columnId) +
67  ", columnName=" + ::toString(columnName) +
68  ", columnType=" + ::toString(columnType) +
69  ", defaultValue=" + ::toString(default_value) + ")";
70  }
71 
72  std::string getDefaultValueLiteral() const {
73  // some preprocessing of strings, arrays and especially arrays of strings
74  CHECK(default_value.has_value());
76  return "\'" + default_value.value() + "\'";
77  } else if (columnType.is_array()) {
78  auto value = default_value.value();
79  CHECK(value.front() == '{' && value.back() == '}');
80  value = value.substr(1, value.length() - 2);
82  auto elements = split(value, ", ");
83  value = "ARRAY[";
84  for (size_t i = 0; i < elements.size(); ++i) {
85  value += "'" + elements[i] + "'";
86  if (i != elements.size() - 1) {
87  value += ", ";
88  }
89  }
90  value += "]";
91  } else {
92  value = "ARRAY[" + value + "]";
93  }
94  return value;
95  } else {
96  return default_value.value();
97  }
98  }
99 };
100 
101 #endif // COLUMN_DESCRIPTOR
std::string virtualExpr
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:330
ColumnDescriptor(const int tableId, const int columnId, const std::string &columnName, const SQLTypeInfo columnType)
bool is_time() const
Definition: sqltypes.h:516
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
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:102
bool g_enable_watchdog false
Definition: Execute.cpp:79
ColumnDescriptor(const bool isGeoPhyCol)
#define CHECK(condition)
Definition: Logger.h:222
bool is_geometry() const
Definition: sqltypes.h:522
SQLTypeInfo columnType
bool is_string() const
Definition: sqltypes.h:510
bool is_string_array() const
Definition: sqltypes.h:511
std::string columnName
bool is_array() const
Definition: sqltypes.h:518
std::string toString() const
constexpr auto is_datetime(SQLTypes type)
Definition: sqltypes.h:263