OmniSciDB  6686921089
 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 2017 MapD Technologies, 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/sqltypes.h"
24 #include "../Shared/toString.h"
25 
33  int tableId;
34  int columnId;
35  std::string columnName;
36  std::string sourceName;
38  std::string chunks;
41  std::string virtualExpr;
43  bool isGeoPhyCol{false};
44  std::optional<std::string> default_value;
45 
48  const int columnId,
49  const std::string& columnName,
50  const SQLTypeInfo columnType)
51  : tableId(tableId)
52  , columnId(columnId)
53  , columnName(columnName)
54  , sourceName(columnName)
55  , columnType(columnType)
58  , isDeletedCol(false) {}
60  this->isGeoPhyCol = isGeoPhyCol;
61  }
62 
63  std::string toString() const {
64  return ::typeName(this) + "(tableId=" + ::toString(tableId) +
65  ", columnId=" + ::toString(columnId) +
66  ", columnName=" + ::toString(columnName) +
67  ", columnType=" + ::toString(columnType) +
68  ", defaultValue=" + ::toString(default_value) + ")";
69  }
70 
71  std::string getDefaultValueLiteral() const {
72  // some preprocessing of strings, arrays and especially arrays of strings
73  CHECK(default_value.has_value());
75  return "\'" + default_value.value() + "\'";
76  } else if (columnType.is_array()) {
77  auto value = default_value.value();
78  CHECK(value.front() == '{' && value.back() == '}');
79  value = value.substr(1, value.length() - 2);
81  auto elements = split(value, ", ");
82  value = "ARRAY[";
83  for (size_t i = 0; i < elements.size(); ++i) {
84  value += "'" + elements[i] + "'";
85  if (i != elements.size() - 1) {
86  value += ", ";
87  }
88  }
89  value += "]";
90  } else {
91  value = "ARRAY[" + value + "]";
92  }
93  return value;
94  } else {
95  return default_value.value();
96  }
97  }
98 };
99 
100 #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:515
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:88
bool g_enable_watchdog false
Definition: Execute.cpp:76
ColumnDescriptor(const bool isGeoPhyCol)
#define CHECK(condition)
Definition: Logger.h:209
bool is_geometry() const
Definition: sqltypes.h:521
SQLTypeInfo columnType
bool is_string() const
Definition: sqltypes.h:509
bool is_string_array() const
Definition: sqltypes.h:510
std::string columnName
bool is_array() const
Definition: sqltypes.h:517
std::string toString() const
constexpr auto is_datetime(SQLTypes type)
Definition: sqltypes.h:263