OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
heavydbTypes.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 #pragma once
18 
19 #include <cstring>
20 #include <limits>
21 #include <stdexcept>
22 #include <type_traits>
23 
24 #include "DateTruncate.h"
25 #include "ExtractFromTime.h"
27 #include "Utils/FlatBuffer.h"
28 
29 #include "DateAdd.h"
30 
31 #if !(defined(__CUDACC__) || defined(NO_BOOST))
32 #include "../Shared/DateTimeParser.h"
33 #endif
34 
35 /* `../` is required for UDFCompiler */
36 #include "../Shared/InlineNullValues.h"
37 #include "../Shared/funcannotations.h"
38 
39 #ifndef __CUDACC__
40 #ifndef UDF_COMPILED
41 #include "Shared/toString.h"
43 #endif // #ifndef UDF_COMPILED
44 #endif // #ifndef __CUDACC__
45 
46 // declaring CPU functions as __host__ can help catch erroneous compilation of
47 // these being done by the CUDA compiler at build time
48 #define EXTENSION_INLINE_HOST extern "C" RUNTIME_EXPORT ALWAYS_INLINE HOST
49 #define EXTENSION_NOINLINE_HOST extern "C" RUNTIME_EXPORT NEVER_INLINE HOST
50 
51 #define EXTENSION_INLINE extern "C" RUNTIME_EXPORT ALWAYS_INLINE DEVICE
52 #define EXTENSION_NOINLINE extern "C" RUNTIME_EXPORT NEVER_INLINE DEVICE
53 #define TEMPLATE_INLINE ALWAYS_INLINE DEVICE
54 #define TEMPLATE_NOINLINE NEVER_INLINE DEVICE
55 
56 EXTENSION_NOINLINE int8_t* allocate_varlen_buffer(int64_t element_count,
57  int64_t element_size);
58 
59 /*
60  Table function management functions and macros:
61  */
62 #define FUNC_NAME (std::string(__func__).substr(0, std::string(__func__).find("__")))
63 // TODO: support windows path format
64 #define ERROR_STRING(MSG) \
65  (std::string(__FILE__).substr(std::string(__FILE__).rfind("/") + 1) + ":" + \
66  std::to_string(__LINE__) + " " + FUNC_NAME + ": " + MSG) \
67  .c_str()
68 #define TABLE_FUNCTION_ERROR(MSG) table_function_error(ERROR_STRING(MSG))
69 #define ERROR_MESSAGE(MSG) error_message(ERROR_STRING(MSG))
70 
72  int32_t index,
73  int64_t output_array_values_total_number);
74 EXTENSION_NOINLINE_HOST void set_output_row_size(int64_t num_rows);
76  int8_t* mgr_ptr,
77  int32_t index,
78  int64_t output_array_values_total_number);
80  int64_t num_rows);
82 EXTENSION_NOINLINE_HOST int32_t table_function_error(const char* message);
84  const char* message);
86  int8_t* mgr_ptr,
87  const char* key,
88  const uint8_t* raw_bytes,
89  const size_t num_bytes,
90  const TableFunctionMetadataType value_type);
92  int8_t* mgr_ptr,
93  const char* key,
94  const uint8_t*& raw_bytes,
95  size_t& num_bytes,
96  TableFunctionMetadataType& value_type);
97 
99 
101 
103  int8_t* mgr_ptr,
104  int32_t db_id,
105  int32_t dict_id);
106 
107 std::string TableFunctionManager_getString(int8_t* mgr_ptr,
108  int32_t db_id,
109  int32_t dict_id,
110  int32_t string_id);
111 
112 EXTENSION_NOINLINE_HOST const char* TableFunctionManager_getCString(int8_t* mgr_ptr,
113  int32_t db_id,
114  int32_t dict_id,
115  int32_t string_id);
116 
118  int32_t db_id,
119  int32_t dict_id,
120  std::string str);
121 
122 /*
123  Row function management functions and macros:
124  */
125 
126 #define GET_DICT_DB_ID(mgr, arg_idx) (mgr.getDictDbId(__func__, arg_idx))
127 
128 #define GET_DICT_ID(mgr, arg_idx) (mgr.getDictId(__func__, arg_idx))
129 
131  int8_t* mgr_ptr,
132  int32_t db_id,
133  int32_t dict_id,
134  int32_t string_id);
135 
137  const char* func_name,
138  size_t arg_idx);
139 
141  const char* func_name,
142  size_t arg_idx);
143 
145  int32_t db_id,
146  int32_t dict_id,
147  std::string str);
148 
149 // https://www.fluentcpp.com/2018/04/06/strong-types-by-struct/
151  int32_t value;
152 
153 #ifndef __CUDACC__
154  TextEncodingDict(const int32_t other) : value(other) {}
156 #endif
157 
158  operator int32_t() const { return value; }
159 
160  TextEncodingDict operator=(const int32_t other) {
161  value = other;
162  return *this;
163  }
164 
165  DEVICE ALWAYS_INLINE bool isNull() const {
166  return value == inline_int_null_value<int32_t>();
167  }
168 
169  DEVICE ALWAYS_INLINE bool operator==(const TextEncodingDict& other) const {
170  return value == other.value;
171  }
172 
173  DEVICE ALWAYS_INLINE bool operator==(const int32_t& other) const {
174  return value == other;
175  }
176 
177  DEVICE ALWAYS_INLINE bool operator==(const int64_t& other) const {
178  return value == other;
179  }
180 
181  DEVICE ALWAYS_INLINE bool operator!=(const TextEncodingDict& other) const {
182  return !operator==(other);
183  }
184  DEVICE ALWAYS_INLINE bool operator!=(const int32_t& other) const {
185  return !operator==(other);
186  }
187 
188  DEVICE ALWAYS_INLINE bool operator!=(const int64_t& other) const {
189  return !operator==(other);
190  }
191 
192  DEVICE ALWAYS_INLINE bool operator<(const TextEncodingDict& other) const {
193  return value < other.value;
194  }
195 
196  DEVICE ALWAYS_INLINE bool operator<(const int32_t& other) const {
197  return value < other;
198  }
199 
200  DEVICE ALWAYS_INLINE bool operator<(const int64_t& other) const {
201  return value < other;
202  }
203 
204 #ifdef HAVE_TOSTRING
205  std::string toString() const {
206  return ::typeName(this) + "(value=" + ::toString(value) + ")";
207  }
208 #endif
209 };
210 
211 template <>
213 #ifndef __CUDACC__
214  return TextEncodingDict(inline_int_null_value<int32_t>());
215 #else
216  TextEncodingDict null_val;
217  null_val.value = inline_int_null_value<int32_t>();
218  return null_val;
219 #endif
220 }
221 
222 template <typename T>
223 struct Array {
224  T* ptr;
225  int64_t size;
226  int8_t is_null;
227 
228  DEVICE Array(T* ptr, const int64_t size, const bool is_null = false)
229  : ptr(is_null ? nullptr : ptr), size(size), is_null(is_null) {}
230  DEVICE Array() : ptr(nullptr), size(0), is_null(true) {}
231 
232  DEVICE Array(const int64_t size, const bool is_null = false)
233  : size(size), is_null(is_null) {
234  if (!is_null) {
235  // Memory must be manually released, otherwise leaks can happen.
236  // On UDFs, if it is the return argument, memory is released with
237  // register_buffer_with_executor_rsm
238  ptr = reinterpret_cast<T*>(
239  allocate_varlen_buffer(size, static_cast<int64_t>(sizeof(T))));
240  } else {
241  ptr = nullptr;
242  }
243  }
244 
245  DEVICE T operator()(const unsigned int index) const {
246  if (index < static_cast<unsigned int>(size)) {
247  return ptr[index];
248  } else {
249  return 0; // see array_at
250  }
251  }
252 
253  DEVICE T& operator[](const unsigned int index) { return ptr[index]; }
254  DEVICE const T& operator[](const unsigned int index) const { return ptr[index]; }
255 
256  DEVICE int64_t getSize() const { return size; }
257 
258  DEVICE bool isNull() const { return is_null; }
259 
260  DEVICE constexpr inline T null_value() const { return inline_null_value<T>(); }
261 
262  DEVICE bool isNull(const unsigned int index) const {
263  return (is_null ? false : ptr[index] == null_value());
264  }
265 
266 #ifdef HAVE_TOSTRING
267  std::string toString() const {
268  std::string result =
269  ::typeName(this) + "(ptr=" + ::toString(reinterpret_cast<void*>(ptr)) +
270  ", size=" + std::to_string(size) + ", is_null=" + std::to_string(is_null) + ")[";
271  for (int64_t i = 0; i < size; i++) {
272  if (size > 10) {
273  // show the first 8 and the last 2 values in the array:
274  if (i == 8) {
275  result += "..., ";
276  } else if (i > 8 && i < size - 2) {
277  continue;
278  }
279  }
280  result += ::toString((*this)[i]) + ", ";
281  }
282  result += "]";
283  return result;
284  }
285 #endif
286 };
287 
289  char* ptr_;
290  int64_t size_;
291  // padding is required to prevent clang/gcc from expanding arguments
292  // https://stackoverflow.com/questions/27386912/prevent-clang-from-expanding-arguments-that-are-aggregate-types/27387908#27387908
293  int8_t padding;
294 
295 #ifndef __CUDACC__
296  TextEncodingNone() = default;
297  TextEncodingNone(const std::string& str) {
298  size_ = str.length();
299  if (str.empty()) {
300  ptr_ = nullptr;
301  } else {
302  // Memory must be manually released, otherwise leaks can happen.
303  // On UDFs, if it is the return argument, memory is released with
304  // register_buffer_with_executor_rsm
305  ptr_ = reinterpret_cast<char*>(
306  allocate_varlen_buffer((size_ + 1), static_cast<int64_t>(sizeof(char))));
307  strncpy(ptr_, str.c_str(), (size_ + 1));
308  }
309  }
310  operator std::string() const { return std::string(ptr_, size_); }
311  std::string getString() const { return std::string(ptr_, size_); }
312  const char* getCString() const { return ptr_; }
313 #endif
314 
315  DEVICE ALWAYS_INLINE char& operator[](const unsigned int index) {
316  return index < size_ ? ptr_[index] : ptr_[size_ - 1];
317  }
318  DEVICE ALWAYS_INLINE bool operator==(const char* rhs) const {
319 #ifdef __CUDACC__
320  for (int i = 0; i < size_; i++) {
321  if (rhs[i] == '\0' || ptr_[i] != rhs[i]) {
322  return false;
323  }
324  }
325  return rhs[size_] == '\0';
326 #else
327  return strcmp(ptr_, rhs) == 0;
328 #endif
329  }
330  DEVICE ALWAYS_INLINE bool operator!=(const char* rhs) const {
331  return !(this->operator==(rhs));
332  }
333  DEVICE ALWAYS_INLINE operator char*() const { return ptr_; }
334  DEVICE ALWAYS_INLINE int64_t size() const { return size_; }
335  DEVICE ALWAYS_INLINE bool isNull() const { return size_ == 0; }
336 };
337 
338 struct DayTimeInterval;
339 struct YearMonthTimeInterval;
340 struct Timestamp {
341  int64_t time;
342 
343  Timestamp() = default;
344 
345  DEVICE Timestamp(int64_t timeval) : time(timeval) {}
346 
347  DEVICE ALWAYS_INLINE Timestamp operator+(const DayTimeInterval& interval) const;
349 
350 #if !(defined(__CUDACC__) || defined(NO_BOOST))
351  DEVICE Timestamp(std::string_view const str) {
352  time = dateTimeParse<kTIMESTAMP>(str, 9);
353  }
354 #endif
355 
356  DEVICE ALWAYS_INLINE const Timestamp operator+(const Timestamp& other) const {
357 #ifndef __CUDACC__
358  if (other.time > 0) {
359  if (time > (std::numeric_limits<int64_t>::max() - other.time)) {
360  throw std::underflow_error("Underflow in Timestamp addition!");
361  }
362  } else {
363  if (time < (std::numeric_limits<int64_t>::min() - other.time)) {
364  throw std::overflow_error("Overflow in Timestamp addition!");
365  }
366  }
367 #endif
368  return Timestamp(time + other.time);
369  }
370 
371  DEVICE ALWAYS_INLINE const Timestamp operator-(const Timestamp& other) const {
372 #ifndef __CUDACC__
373  if (other.time > 0) {
374  if (time < (std::numeric_limits<int64_t>::min() + other.time)) {
375  throw std::underflow_error("Underflow in Timestamp substraction!");
376  }
377  } else {
378  if (time > (std::numeric_limits<int64_t>::max() + other.time)) {
379  throw std::overflow_error("Overflow in Timestamp substraction!");
380  }
381  }
382 #endif
383  return Timestamp(time - other.time);
384  }
385 
386  DEVICE ALWAYS_INLINE int64_t operator/(const Timestamp& other) const {
387 #ifndef __CUDACC__
388  if (other.time == 0) {
389  throw std::runtime_error("Timestamp division by zero!");
390  }
391 #endif
392  return time / other.time;
393  }
394 
395  DEVICE ALWAYS_INLINE const Timestamp operator*(const int64_t multiplier) const {
396 #ifndef __CUDACC__
397  int64_t overflow_test = static_cast<int64_t>(time) * static_cast<int64_t>(multiplier);
398  if (time != 0 && overflow_test / time != static_cast<int64_t>(multiplier)) {
399  throw std::overflow_error("Overflow in Timestamp multiplication!");
400  }
401 #endif
402  return Timestamp(time * multiplier);
403  }
404 
405  DEVICE ALWAYS_INLINE bool operator==(const Timestamp& other) const {
406  return time == other.time;
407  }
408 
409  DEVICE ALWAYS_INLINE bool operator!=(const Timestamp& other) const {
410  return !operator==(other);
411  }
412 
413  DEVICE ALWAYS_INLINE bool operator<(const Timestamp& other) const {
414  return time < other.time;
415  }
416 
419  }
420 
423  }
424 
427  }
428 
431  }
432 
435  }
436 
439  }
440 
443  }
444 
447  }
448 
451  }
452  // Should always be safe as we're downcasting to lower precisions
455  }
456  // Should always be safe as we're downcasting to lower precisions
459  }
460  // Should always be safe as we're downcasting to lower precisions
461  DEVICE ALWAYS_INLINE int64_t getSeconds() const {
463  }
464  DEVICE ALWAYS_INLINE int64_t getMinutes() const {
466  }
467  DEVICE ALWAYS_INLINE int64_t getHours() const {
469  }
470  DEVICE ALWAYS_INLINE int64_t getDay() const {
472  }
473  DEVICE ALWAYS_INLINE int64_t getMonth() const {
475  }
476  DEVICE ALWAYS_INLINE int64_t getYear() const {
478  }
479 #ifdef HAVE_TOSTRING
480  std::string toString() const {
481  Datum d;
482  d.bigintval = time;
483  return ::typeName(this) + "(time=" + ::toString(time) + ")" +
484  ", (formatted= " + DatumToString(d, SQLTypeInfo(kTIMESTAMP, 9, 0, false)) +
485  ")";
486  }
487 #endif
488 };
489 
490 template <>
492  return Timestamp(inline_int_null_value<int64_t>());
493 }
494 
496  int64_t timeval;
497 
498  DEVICE DayTimeInterval(int64_t init) : timeval(init) {}
499 
500  DEVICE ALWAYS_INLINE bool operator==(const DayTimeInterval& other) const {
501  return timeval == other.timeval;
502  }
503 
504  DEVICE ALWAYS_INLINE bool operator!=(const DayTimeInterval& other) const {
505  return !operator==(other);
506  }
507 
510  daMILLISECOND, timeval, t.time, 9, inline_int_null_value<int64_t>()));
511  }
512 
513  DEVICE ALWAYS_INLINE DayTimeInterval operator*(const int64_t multiplier) const {
514  return DayTimeInterval(timeval * multiplier);
515  }
516 
518  const Timestamp& end) const {
519 #ifndef __CUDACC__
520  if (timeval == 0) {
521  throw std::runtime_error("Timestamp division by zero!");
522  }
523 #endif
524 
525  if ((timeval > 0 && end.time < begin.time) ||
526  (timeval < 0 && end.time > begin.time)) {
527  return -1;
528  }
529 
530  Timestamp diff = end.time - begin.time;
531  int64_t asNanoSecs =
532  static_cast<int64_t>(timeval) * static_cast<int64_t>(kMicroSecsPerSec);
533 #ifndef __CUDACC__
534  if (timeval != 0 && asNanoSecs / timeval != static_cast<int64_t>(kMicroSecsPerSec)) {
535  throw std::overflow_error("Overflow in INTERVAL precision conversion!");
536  }
537 #endif
538 
539  return diff / asNanoSecs;
540  }
541 };
542 
544  int64_t timeval;
545 
547 
549  return timeval == other.timeval;
550  }
551 
553  return !operator==(other);
554  }
555 
558  daMONTH, timeval, t.time, 9, inline_int_null_value<int64_t>()));
559  }
560 
561  DEVICE ALWAYS_INLINE YearMonthTimeInterval operator*(const int64_t multiplier) const {
562  return YearMonthTimeInterval(timeval * multiplier);
563  }
564 
566  const Timestamp& end) const {
567  if ((timeval > 0 && end.time < begin.time) ||
568  (timeval < 0 && end.time > begin.time)) {
569  return -1;
570  }
571 
572  int64_t ret = ((end.getYear() * 12 + end.getMonth()) -
573  (begin.getYear() * 12 + begin.getMonth())) /
574  timeval;
575  return ret;
576  }
577 };
578 
580  const DayTimeInterval& interval) const {
581  return interval + *this;
582 }
583 
585  const YearMonthTimeInterval& interval) const {
586  return interval + *this;
587 }
588 
589 struct GeoPoint {
590  int8_t* ptr;
591  int32_t sz;
592  int32_t compression;
593  int32_t input_srid;
594  int32_t output_srid;
595 
596  DEVICE int64_t getSize() const { return sz; }
597 
598  DEVICE int32_t getCompression() const { return compression; }
599 
600  DEVICE int32_t getInputSrid() const { return input_srid; }
601 
602  DEVICE int32_t getOutputSrid() const { return output_srid; }
603 };
604 
606  int8_t* ptr;
607  int32_t sz;
608  int32_t compression;
609  int32_t input_srid;
610  int32_t output_srid;
611 
612  DEVICE int32_t getSize() const { return sz; }
613 
614  DEVICE int32_t getCompression() const { return compression; }
615 
616  DEVICE int32_t getInputSrid() const { return input_srid; }
617 
618  DEVICE int32_t getOutputSrid() const { return output_srid; }
619 };
620 
622  int8_t* ptr;
623  int32_t sz;
624  int32_t compression;
625  int32_t input_srid;
626  int32_t output_srid;
627 
628  DEVICE int32_t getSize() const { return sz; }
629 
630  DEVICE int32_t getCompression() const { return compression; }
631 
632  DEVICE int32_t getInputSrid() const { return input_srid; }
633 
634  DEVICE int32_t getOutputSrid() const { return output_srid; }
635 };
636 
638  int8_t* ptr;
639  int32_t sz;
642  int32_t compression;
643  int32_t input_srid;
644  int32_t output_srid;
645 
646  DEVICE int8_t* getCoords() const { return ptr; }
647 
648  DEVICE int32_t getCoordsSize() const { return sz; }
649 
651 
652  DEVICE int32_t getNumLineStrings() const { return num_linestrings; }
653 
654  DEVICE int32_t getCompression() const { return compression; }
655 
656  DEVICE int32_t getInputSrid() const { return input_srid; }
657 
658  DEVICE int32_t getOutputSrid() const { return output_srid; }
659 };
660 
661 struct GeoPolygon {
662  int8_t* ptr_coords;
663  int32_t coords_size;
664  int8_t* ring_sizes;
665  int32_t num_rings;
666  int32_t compression;
667  int32_t input_srid;
668  int32_t output_srid;
669 
670  DEVICE int8_t* getRingSizes() { return ring_sizes; }
671  DEVICE int32_t getCoordsSize() const { return coords_size; }
672 
673  DEVICE int32_t getNumRings() const { return num_rings; }
674 
675  DEVICE int32_t getCompression() const { return compression; }
676 
677  DEVICE int32_t getInputSrid() const { return input_srid; }
678 
679  DEVICE int32_t getOutputSrid() const { return output_srid; }
680 };
681 
683  int8_t* ptr_coords;
684  int32_t coords_size;
685  int8_t* ring_sizes;
686  int32_t num_rings;
687  int8_t* poly_sizes;
688  int32_t num_polys;
689  int32_t compression;
690  int32_t input_srid;
691  int32_t output_srid;
692 
693  DEVICE int8_t* getRingSizes() { return ring_sizes; }
694  DEVICE int32_t getCoordsSize() const { return coords_size; }
695 
696  DEVICE int32_t getNumRings() const { return num_rings; }
697 
698  DEVICE int8_t* getPolygonSizes() { return poly_sizes; }
699 
700  DEVICE int32_t getNumPolygons() const { return num_polys; }
701 
702  DEVICE int32_t getCompression() const { return compression; }
703 
704  DEVICE int32_t getInputSrid() const { return input_srid; }
705 
706  DEVICE int32_t getOutputSrid() const { return output_srid; }
707 };
708 
709 // There are redundant #ifndef UDF_COMPILED inside
710 // ifguard for StringDictionaryProxy to flag that
711 // if we decide to adapt C++ UDF Compiler for table
712 // functions, the linking issue we encountered with
713 // the shared_mutex include in StringDicitonaryProxy
714 // will need to be resolved separately.
715 
716 #ifndef UDF_COMPILED
717 
718 #ifdef __CUDACC__
719 template <typename T>
720 static DEVICE __constant__ T Column_null_value;
721 #endif
722 
723 template <typename T>
724 struct Column {
725  T* ptr_; // row data
726  int64_t num_rows_; // row count
727 
728  DEVICE Column(T* ptr, const int64_t num_rows) : ptr_(ptr), num_rows_(num_rows) {}
729 
730 #ifndef __CUDACC__
731 #ifndef UDF_COMPILED
732  DEVICE Column(const Column& other) : ptr_(other.ptr_), num_rows_(other.num_rows_) {}
733  DEVICE Column(std::vector<T>& input_vec)
734  : ptr_(input_vec.data()), num_rows_(static_cast<int64_t>(input_vec.size())) {}
735 #endif
736 #endif
737 
738  DEVICE T& operator[](const unsigned int index) const {
739  if (index >= num_rows_) {
740 #ifndef __CUDACC__
741  throw std::runtime_error("column buffer index is out of range");
742 #else
743  auto& null_value = Column_null_value<T>;
744  set_null(null_value);
745  return null_value;
746 #endif
747  }
748  return ptr_[index];
749  }
750  DEVICE inline T* getPtr() const { return ptr_; }
751  DEVICE inline int64_t size() const { return num_rows_; }
752  DEVICE inline void setSize(int64_t num_rows) { num_rows_ = num_rows; }
753 
754  DEVICE inline bool isNull(int64_t index) const { return is_null(ptr_[index]); }
755  DEVICE inline void setNull(int64_t index) { set_null(ptr_[index]); }
757 #ifndef __CUDACC__
758  if (size() == other.size()) {
759  memcpy(ptr_, &other[0], other.size() * sizeof(T));
760  } else {
761  throw std::runtime_error("cannot copy assign columns with different sizes");
762  }
763 #else
764  if (size() == other.size()) {
765  for (unsigned int i = 0; i < size(); i++) {
766  ptr_[i] = other[i];
767  }
768  } else {
769  // TODO: set error
770  }
771 #endif
772  return *this;
773  }
774 
775 #ifdef HAVE_TOSTRING
776  std::string toString() const {
777  return ::typeName(this) + "(ptr=" + ::toString(reinterpret_cast<void*>(ptr_)) +
778  ", num_rows=" + std::to_string(num_rows_) + ")";
779  }
780 #endif
781 };
782 
783 template <typename T>
784 struct Column<Array<T>> {
785  // A type for a column of variable length arrays
786  //
787  // Internally, the varlen arrays are stored using compressed storage
788  // format (see https://pearu.github.io/variable_length_arrays.html
789  // for the description) using FlatBuffer tool.
790  int8_t* flatbuffer_; // contains a flat buffer of the storage, use FlatBufferManager
791  // to access it.
792  int64_t num_rows_; // total row count, the number of all varlen arrays
793 
794  Column<Array<T>>(int8_t* flatbuffer, const int64_t num_rows)
795  : flatbuffer_(flatbuffer), num_rows_(num_rows) {}
796 
797  DEVICE Array<T> getItem(const int64_t index, const int64_t expected_numel = -1) const {
798  FlatBufferManager m{flatbuffer_};
799  int8_t* ptr;
800  int64_t size;
801  bool is_null;
802  auto status = m.getItem(index, size, ptr, is_null);
803  if (status == FlatBufferManager::Status::ItemUnspecifiedError) {
804  if (expected_numel < 0) {
805 #ifndef __CUDACC__
806  throw std::runtime_error("getItem failed: " + ::toString(status));
807 #endif
808  }
809  status = m.setItem(index,
810  nullptr,
811  expected_numel * sizeof(T),
812  nullptr); // reserves a junk in array buffer
813  if (status != FlatBufferManager::Status::Success) {
814 #ifndef __CUDACC__
815  throw std::runtime_error("getItem failed[setItem]: " + ::toString(status));
816 #endif
817  }
818  status = m.getItem(index, size, ptr, is_null);
819  }
820  if (status == FlatBufferManager::Status::Success) {
821  if (expected_numel >= 0 &&
822  expected_numel * static_cast<int64_t>(sizeof(T)) != size) {
823 #ifndef __CUDACC__
824  throw std::runtime_error("getItem failed: unexpected size");
825 #endif
826  }
827  } else {
828 #ifndef __CUDACC__
829  throw std::runtime_error("getItem failed: " + ::toString(status));
830 #endif
831  }
832  Array<T> result(reinterpret_cast<T*>(ptr), size / sizeof(T), is_null);
833  return result;
834  }
835 
836  DEVICE inline Array<T> operator[](const unsigned int index) const {
837  return getItem(static_cast<int64_t>(index));
838  }
839 
840  DEVICE int64_t size() const { return num_rows_; }
841 
842  DEVICE inline bool isNull(int64_t index) const {
843  FlatBufferManager m{flatbuffer_};
844  bool is_null = false;
845  auto status = m.isNull(index, is_null);
846 #ifndef __CUDACC__
847  if (status != FlatBufferManager::Status::Success) {
848  throw std::runtime_error("isNull failed: " + ::toString(status));
849  }
850 #endif
851  return is_null;
852  }
853 
854  DEVICE inline void setNull(int64_t index) {
855  FlatBufferManager m{flatbuffer_};
856  auto status = m.setNull(index);
857 #ifndef __CUDACC__
858  if (status != FlatBufferManager::Status::Success) {
859  throw std::runtime_error("setNull failed: " + ::toString(status));
860  }
861 #endif
862  }
863 
864  DEVICE inline void setItem(int64_t index, const Array<T>& other) {
865  FlatBufferManager m{flatbuffer_};
867  if (other.isNull()) {
868  status = m.setNull(index);
869  } else {
870  status = m.setItem(index,
871  reinterpret_cast<const int8_t*>(&(other[0])),
872  other.getSize() * sizeof(T));
873  }
874 #ifndef __CUDACC__
875  if (status != FlatBufferManager::Status::Success) {
876  throw std::runtime_error("setItem failed: " + ::toString(status));
877  }
878 #endif
879  }
880 
881  DEVICE inline void concatItem(int64_t index, const Array<T>& other) {
882  FlatBufferManager m{flatbuffer_};
884  if (other.isNull()) {
885  status = m.setNull(index);
886  } else {
887  status = m.concatItem(index,
888  reinterpret_cast<const int8_t*>(&(other[0])),
889  other.getSize() * sizeof(T));
890 #ifndef __CUDACC__
891  if (status != FlatBufferManager::Status::Success) {
892  throw std::runtime_error("concatItem failed: " + ::toString(status));
893  }
894 #endif
895  }
896  }
897 
898  DEVICE inline int32_t getDictDbId() const {
899  FlatBufferManager m{flatbuffer_};
900  return m.getDTypeMetadataDictDbId();
901  }
902 
903  DEVICE inline int32_t getDictId() const {
904  FlatBufferManager m{flatbuffer_};
905  return m.getDTypeMetadataDictId();
906  }
907 };
908 
909 template <>
911  TextEncodingDict* ptr_; // row data
912  int64_t num_rows_; // row count
913 #ifndef __CUDACC__
914 #ifndef UDF_COMPILED
916  DEVICE Column(const Column& other)
917  : ptr_(other.ptr_)
918  , num_rows_(other.num_rows_)
919  , string_dict_proxy_(other.string_dict_proxy_) {}
921  const int64_t num_rows,
922  StringDictionaryProxy* string_dict_proxy)
923  : ptr_(ptr), num_rows_(num_rows), string_dict_proxy_(string_dict_proxy) {}
924  DEVICE Column(std::vector<TextEncodingDict>& input_vec)
925  : ptr_(input_vec.data())
926  , num_rows_(static_cast<int64_t>(input_vec.size()))
927  , string_dict_proxy_(nullptr) {}
928 #else
929  DEVICE Column(TextEncodingDict* ptr, const int64_t num_rows)
930  : ptr_(ptr), num_rows_(num_rows) {}
931 #endif // #ifndef UDF_COMPILED
932 #else
933  DEVICE Column(TextEncodingDict* ptr, const int64_t num_rows)
934  : ptr_(ptr), num_rows_(num_rows) {}
935 #endif // #ifndef __CUDACC__
936 
937  DEVICE TextEncodingDict& operator[](const unsigned int index) const {
938  if (index >= num_rows_) {
939 #ifndef __CUDACC__
940  throw std::runtime_error("column buffer index is out of range");
941 #else
942  static DEVICE TextEncodingDict null_value;
943  set_null(null_value.value);
944  return null_value;
945 #endif
946  }
947  return ptr_[index];
948  }
949  DEVICE inline TextEncodingDict* getPtr() const { return ptr_; }
950  DEVICE inline int64_t size() const { return num_rows_; }
951  DEVICE inline void setSize(int64_t num_rows) { num_rows_ = num_rows; }
952 
953  DEVICE inline bool isNull(int64_t index) const { return is_null(ptr_[index].value); }
954 
955  DEVICE inline void setNull(int64_t index) { set_null(ptr_[index].value); }
956 
957 #ifndef __CUDACC__
958 #ifndef UDF_COMPILED
959  DEVICE inline int32_t getDictDbId() const {
960  return string_dict_proxy_->getDictKey().db_id;
961  }
962  DEVICE inline int32_t getDictId() const {
963  return string_dict_proxy_->getDictKey().dict_id;
964  }
965  DEVICE inline const std::string getString(int64_t index) const {
966  return isNull(index) ? "" : string_dict_proxy_->getString(ptr_[index].value);
967  }
968  DEVICE inline const char* getCString(int64_t index) const {
969  if (isNull(index)) {
970  return nullptr;
971  }
972  auto [c_str, len] = string_dict_proxy_->getStringBytes(ptr_[index].value);
973  return c_str;
974  }
975  DEVICE inline const TextEncodingDict getOrAddTransient(const std::string& str) {
976  return string_dict_proxy_->getOrAddTransient(str);
977  }
978 #endif // #ifndef UDF_COMPILED
979 #endif // #ifndef __CUDACC__
980 
982 #ifndef __CUDACC__
983  if (size() == other.size()) {
984  memcpy(ptr_, other.ptr_, other.size() * sizeof(TextEncodingDict));
985  } else {
986  throw std::runtime_error("cannot copy assign columns with different sizes");
987  }
988 #else
989  if (size() == other.size()) {
990  for (unsigned int i = 0; i < size(); i++) {
991  ptr_[i] = other[i];
992  }
993  } else {
994  // TODO: set error
995  }
996 #endif
997  return *this;
998  }
999 
1000 #ifdef HAVE_TOSTRING
1001  std::string toString() const {
1002  return ::typeName(this) + "(ptr=" + ::toString(reinterpret_cast<void*>(ptr_)) +
1003  ", num_rows=" + std::to_string(num_rows_) + ")";
1004  }
1005 #endif
1006 };
1007 
1008 template <>
1009 DEVICE inline bool Column<Timestamp>::isNull(int64_t index) const {
1010  return is_null(ptr_[index].time);
1011 }
1012 
1013 template <>
1014 DEVICE inline void Column<Timestamp>::setNull(int64_t index) {
1015  set_null(ptr_[index].time);
1016 }
1017 
1018 template <>
1020  set_null(t.time);
1021 }
1022 
1023 /*
1024  ColumnList is an ordered list of Columns.
1025 */
1026 template <typename T>
1027 struct ColumnList {
1028  int8_t** ptrs_; // ptrs to columns data
1029  int64_t num_cols_; // the length of columns list
1030  int64_t num_rows_; // the number of rows of columns
1031 
1032  DEVICE ColumnList(int8_t** ptrs, const int64_t num_cols, const int64_t num_rows)
1033  : ptrs_(ptrs), num_cols_(num_cols), num_rows_(num_rows) {}
1034 
1035  DEVICE int64_t size() const { return num_rows_; }
1036  DEVICE int64_t numCols() const { return num_cols_; }
1037  DEVICE Column<T> operator[](const int index) const {
1038  if (index >= 0 && index < num_cols_)
1039  return {reinterpret_cast<T*>(ptrs_[index]), num_rows_};
1040  else
1041  return {nullptr, -1};
1042  }
1043 
1044 #ifdef HAVE_TOSTRING
1045 
1046  std::string toString() const {
1047  std::string result = ::typeName(this) + "(ptrs=[";
1048  for (int64_t index = 0; index < num_cols_; index++) {
1049  result += ::toString(reinterpret_cast<void*>(ptrs_[index])) +
1050  (index < num_cols_ - 1 ? ", " : "");
1051  }
1052  result += "], num_cols=" + std::to_string(num_cols_) +
1053  ", num_rows=" + std::to_string(num_rows_) + ")";
1054  return result;
1055  }
1056 
1057 #endif
1058 };
1059 
1060 template <typename T>
1061 struct ColumnList<Array<T>> {
1062  int8_t** ptrs_; // ptrs to columns data in FlatBuffer format
1063  int64_t num_cols_; // the length of columns list
1064  int64_t num_rows_; // the size of columns
1065 
1066  DEVICE int64_t size() const { return num_rows_; }
1067  DEVICE int64_t numCols() const { return num_cols_; }
1068  DEVICE Column<Array<T>> operator[](const int index) const {
1069  int8_t* ptr = ((index >= 0 && index < num_cols_) ? ptrs_[index] : nullptr);
1070  int64_t num_rows = ((index >= 0 && index < num_cols_) ? num_rows_ : -1);
1071  Column<Array<T>> result(ptr, num_rows);
1072  return result;
1073  }
1074 
1075 #ifdef HAVE_TOSTRING
1076 
1077  std::string toString() const {
1078  std::string result = ::typeName(this) + "(ptrs=[";
1079  for (int64_t index = 0; index < num_cols_; index++) {
1080  result += ::toString(reinterpret_cast<void*>(ptrs_[index])) +
1081  (index < num_cols_ - 1 ? ", " : "");
1082  }
1083  result += "], num_cols=" + std::to_string(num_cols_) +
1084  ", num_rows=" + std::to_string(num_rows_) + ")";
1085  return result;
1086  }
1087 
1088 #endif
1089 };
1090 
1091 template <>
1093  int8_t** ptrs_; // ptrs to columns data
1094  int64_t num_cols_; // the length of columns list
1095  int64_t num_rows_; // the size of columns
1096 #ifndef __CUDACC__
1097 #ifndef UDF_COMPILED
1099  DEVICE ColumnList(int8_t** ptrs,
1100  const int64_t num_cols,
1101  const int64_t num_rows,
1102  StringDictionaryProxy** string_dict_proxies)
1103  : ptrs_(ptrs)
1104  , num_cols_(num_cols)
1105  , num_rows_(num_rows)
1106  , string_dict_proxies_(string_dict_proxies) {}
1107 #else
1108  DEVICE ColumnList(int8_t** ptrs, const int64_t num_cols, const int64_t num_rows)
1109  : ptrs_(ptrs), num_cols_(num_cols), num_rows_(num_rows) {}
1110 #endif // #ifndef UDF_COMPILED
1111 #else
1112  DEVICE ColumnList(int8_t** ptrs, const int64_t num_cols, const int64_t num_rows)
1113  : ptrs_(ptrs), num_cols_(num_cols), num_rows_(num_rows) {}
1114 #endif // #ifndef __CUDACC__
1115 
1116  DEVICE int64_t size() const { return num_rows_; }
1117  DEVICE int64_t numCols() const { return num_cols_; }
1118  DEVICE Column<TextEncodingDict> operator[](const int index) const {
1119  if (index >= 0 && index < num_cols_) {
1120  Column<TextEncodingDict> result(reinterpret_cast<TextEncodingDict*>(ptrs_[index]),
1121  num_rows_
1122 #ifndef __CUDACC__
1123 #ifndef UDF_COMPILED
1124  ,
1125  string_dict_proxies_[index]
1126 #endif // #ifndef UDF_COMPILED
1127 #endif // #ifndef __CUDACC__
1128  );
1129  return result;
1130  } else {
1132  -1
1133 #ifndef __CUDACC__
1134 #ifndef UDF_COMPILED
1135  ,
1136  nullptr
1137 #endif // #ifndef UDF_COMPILED
1138 #endif // #ifndef__CUDACC__
1139  );
1140  return result;
1141  }
1142  }
1143 
1144 #ifdef HAVE_TOSTRING
1145 
1146  std::string toString() const {
1147  std::string result = ::typeName(this) + "(ptrs=[";
1148  for (int64_t index = 0; index < num_cols_; index++) {
1149  result += ::toString(reinterpret_cast<void*>(ptrs_[index])) +
1150  (index < num_cols_ - 1 ? ", " : "");
1151  }
1152  result += "], num_cols=" + std::to_string(num_cols_) +
1153  ", num_rows=" + std::to_string(num_rows_) + ")";
1154  return result;
1155  }
1156 
1157 #endif
1158 };
1159 
1160 #ifndef __CUDACC__
1162  std::string getString(int32_t db_id, int32_t dict_id, int32_t string_id) {
1164  reinterpret_cast<int8_t*>(this), db_id, dict_id, string_id);
1165  }
1166 
1167  int32_t getDictDbId(const char* func_name, size_t arg_idx) {
1169  reinterpret_cast<int8_t*>(this), func_name, arg_idx);
1170  }
1171 
1172  int32_t getDictId(const char* func_name, size_t arg_idx) {
1174  reinterpret_cast<int8_t*>(this), func_name, arg_idx);
1175  }
1176 
1177  int32_t getOrAddTransient(int32_t db_id, int32_t dict_id, std::string str) {
1179  reinterpret_cast<int8_t*>(this), db_id, dict_id, str);
1180  }
1181 };
1182 #endif
1183 
1184 /*
1185  This TableFunctionManager struct is a minimal proxy to the
1186  TableFunctionManager defined in TableFunctionManager.h. The
1187  corresponding instances share `this` but have different virtual
1188  tables for methods.
1189 */
1190 #ifndef __CUDACC__
1191 
1192 namespace {
1193 template <typename T>
1195  if constexpr (std::is_same<T, int8_t>::value) {
1197  } else if constexpr (std::is_same<T, int16_t>::value) {
1199  } else if constexpr (std::is_same<T, int32_t>::value) {
1201  } else if constexpr (std::is_same<T, int64_t>::value) {
1203  } else if constexpr (std::is_same<T, float>::value) {
1205  } else if constexpr (std::is_same<T, double>::value) {
1207  } else if constexpr (std::is_same<T, bool>::value) {
1209  }
1210  throw std::runtime_error("Unsupported TableFunctionMetadataType");
1211 }
1212 } // namespace
1213 
1216  return reinterpret_cast<TableFunctionManager*>(TableFunctionManager_get_singleton());
1217  }
1218 
1220  int64_t output_array_values_total_number) {
1222  reinterpret_cast<int8_t*>(this), index, output_array_values_total_number);
1223  }
1224 
1225  void set_output_row_size(int64_t num_rows) {
1226  if (!output_allocations_disabled) {
1227  TableFunctionManager_set_output_row_size(reinterpret_cast<int8_t*>(this), num_rows);
1228  }
1229  }
1230 
1231  void disable_output_allocations() { output_allocations_disabled = true; }
1232 
1233  void enable_output_allocations() { output_allocations_disabled = false; }
1234 
1235  int32_t error_message(const char* message) {
1236  return TableFunctionManager_error_message(reinterpret_cast<int8_t*>(this), message);
1237  }
1238 
1239  template <typename T>
1240  void set_metadata(const std::string& key, const T& value) {
1241  TableFunctionManager_set_metadata(reinterpret_cast<int8_t*>(this),
1242  key.c_str(),
1243  reinterpret_cast<const uint8_t*>(&value),
1244  sizeof(value),
1245  get_metadata_type<T>());
1246  }
1247 
1248  template <typename T>
1249  void get_metadata(const std::string& key, T& value) {
1250  const uint8_t* raw_data{};
1251  size_t num_bytes{};
1252  TableFunctionMetadataType value_type;
1254  reinterpret_cast<int8_t*>(this), key.c_str(), raw_data, num_bytes, value_type);
1255  if (sizeof(T) != num_bytes) {
1256  throw std::runtime_error("Size mismatch for Table Function Metadata '" + key + "'");
1257  }
1258  if (get_metadata_type<T>() != value_type) {
1259  throw std::runtime_error("Type mismatch for Table Function Metadata '" + key + "'");
1260  }
1261  std::memcpy(&value, raw_data, num_bytes);
1262  }
1263  int32_t getNewDictDbId() {
1264  return TableFunctionManager_getNewDictDbId(reinterpret_cast<int8_t*>(this));
1265  }
1266  int32_t getNewDictId() {
1267  return TableFunctionManager_getNewDictId(reinterpret_cast<int8_t*>(this));
1268  }
1269  StringDictionaryProxy* getStringDictionaryProxy(int32_t db_id, int32_t dict_id) {
1270  return reinterpret_cast<StringDictionaryProxy*>(
1272  reinterpret_cast<int8_t*>(this), db_id, dict_id));
1273  }
1274  std::string getString(int32_t db_id, int32_t dict_id, int32_t string_id) {
1276  reinterpret_cast<int8_t*>(this), db_id, dict_id, string_id);
1277  }
1278  const char* getCString(int32_t db_id, int32_t dict_id, int32_t string_id) {
1280  reinterpret_cast<int8_t*>(this), db_id, dict_id, string_id);
1281  }
1282  int32_t getOrAddTransient(int32_t db_id, int32_t dict_id, std::string str) {
1284  reinterpret_cast<int8_t*>(this), db_id, dict_id, str);
1285  }
1286 
1287 #ifdef HAVE_TOSTRING
1288  std::string toString() const {
1289  std::string result = ::typeName(this) + "(";
1290  if (!(void*)this) { // cast to void* to avoid warnings
1291  result += "UNINITIALIZED";
1292  }
1293  result += ")";
1294  return result;
1295  }
1296 #endif // HAVE_TOSTRING
1297  bool output_allocations_disabled{false};
1298 };
1299 #endif // #ifndef __CUDACC__
1300 
1301 #endif // #ifndef UDF_COMPILED
DEVICE const std::string getString(int64_t index) const
Definition: heavydbTypes.h:965
int32_t getDTypeMetadataDictDbId() const
Definition: FlatBuffer.h:314
EXTENSION_NOINLINE_HOST int32_t RowFunctionManager_getDictDbId(int8_t *mgr_ptr, const char *func_name, size_t arg_idx)
void set_output_row_size(int64_t num_rows)
DEVICE int64_t size() const
Definition: heavydbTypes.h:840
std::string getString(int32_t db_id, int32_t dict_id, int32_t string_id)
int32_t compression
Definition: heavydbTypes.h:666
DEVICE ALWAYS_INLINE Timestamp truncateToSeconds() const
Definition: heavydbTypes.h:425
DEVICE int32_t getDictDbId() const
Definition: heavydbTypes.h:959
DEVICE ALWAYS_INLINE Timestamp truncateToDay() const
Definition: heavydbTypes.h:437
DEVICE int32_t getCompression() const
Definition: heavydbTypes.h:702
int8_t * ptr_coords
Definition: heavydbTypes.h:662
void set_output_array_values_total_number(int32_t index, int64_t output_array_values_total_number)
int32_t getDTypeMetadataDictId() const
Definition: FlatBuffer.h:328
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:458
EXTENSION_NOINLINE_HOST void set_output_array_values_total_number(int32_t index, int64_t output_array_values_total_number)
DEVICE Column(std::vector< T > &input_vec)
Definition: heavydbTypes.h:733
DEVICE ALWAYS_INLINE bool operator!=(const int64_t &other) const
Definition: heavydbTypes.h:188
DEVICE int32_t getInputSrid() const
Definition: heavydbTypes.h:677
DEVICE Array< T > getItem(const int64_t index, const int64_t expected_numel=-1) const
Definition: heavydbTypes.h:797
int64_t DateTruncate(DatetruncField field, const int64_t timeval)
EXTENSION_NOINLINE_HOST void set_output_row_size(int64_t num_rows)
int32_t output_srid
Definition: heavydbTypes.h:668
#define EXTENSION_NOINLINE
Definition: heavydbTypes.h:52
DEVICE ALWAYS_INLINE const Timestamp operator+(const Timestamp &other) const
Definition: heavydbTypes.h:356
int32_t input_srid
Definition: heavydbTypes.h:593
static constexpr int64_t kNanoSecsPerSec
void get_metadata(const std::string &key, T &value)
EXTENSION_NOINLINE_HOST int32_t RowFunctionManager_getDictId(int8_t *mgr_ptr, const char *func_name, size_t arg_idx)
int8_t * ptr
Definition: heavydbTypes.h:606
DEVICE int32_t getCoordsSize() const
Definition: heavydbTypes.h:648
DEVICE ALWAYS_INLINE bool operator==(const YearMonthTimeInterval &other) const
Definition: heavydbTypes.h:548
EXTENSION_NOINLINE_HOST int8_t * TableFunctionManager_get_singleton()
std::string getString() const
Definition: heavydbTypes.h:311
EXTENSION_NOINLINE_HOST int32_t TableFunctionManager_getNewDictDbId(int8_t *mgr_ptr)
DEVICE ALWAYS_INLINE bool operator<(const TextEncodingDict &other) const
Definition: heavydbTypes.h:192
int32_t getOrAddTransient(int32_t db_id, int32_t dict_id, std::string str)
Simplified core of GeoJSON Polygon coordinates definition.
Definition: heavydbTypes.h:661
int64_t size
Definition: heavydbTypes.h:225
DEVICE ALWAYS_INLINE int64_t getMicroseconds() const
Definition: heavydbTypes.h:453
DEVICE YearMonthTimeInterval(int64_t init)
Definition: heavydbTypes.h:546
TextEncodingDict operator=(const int32_t other)
Definition: heavydbTypes.h:160
DEVICE int64_t size() const
Definition: heavydbTypes.h:751
EXTENSION_NOINLINE_HOST int32_t RowFunctionManager_getOrAddTransient(int8_t *mgr_ptr, int32_t db_id, int32_t dict_id, std::string str)
CONSTEXPR DEVICE void set_null< Timestamp >(Timestamp &t)
int32_t compression
Definition: heavydbTypes.h:608
int64_t num_rows_
DEVICE void setNull(int64_t index)
Definition: heavydbTypes.h:854
DEVICE int64_t size() const
int32_t coords_size
Definition: heavydbTypes.h:663
DEVICE Timestamp(std::string_view const str)
Definition: heavydbTypes.h:351
DEVICE int64_t numCols() const
DEVICE int8_t * getLineStringSizes()
Definition: heavydbTypes.h:650
DEVICE int8_t * getPolygonSizes()
Definition: heavydbTypes.h:698
DEVICE ALWAYS_INLINE int64_t getYear() const
Definition: heavydbTypes.h:476
T * ptr_
Definition: heavydbTypes.h:725
int32_t getDictId(const char *func_name, size_t arg_idx)
int64_t time
Definition: heavydbTypes.h:341
DEVICE ColumnList(int8_t **ptrs, const int64_t num_cols, const int64_t num_rows)
DEVICE T * getPtr() const
Definition: heavydbTypes.h:750
const char * getCString() const
Definition: heavydbTypes.h:312
DEVICE Column< T > & operator=(const Column< T > &other)
Definition: heavydbTypes.h:756
DEVICE Column< T > operator[](const int index) const
DEVICE int8_t * getRingSizes()
Definition: heavydbTypes.h:693
DEVICE ALWAYS_INLINE bool operator!=(const DayTimeInterval &other) const
Definition: heavydbTypes.h:504
DEVICE int64_t size() const
RUNTIME_EXPORT DEVICE int64_t DateAddHighPrecisionNullable(const DateaddField field, const int64_t number, const int64_t timeval, const int32_t dim, const int64_t null_val)
DEVICE void setNull(int64_t index)
Definition: heavydbTypes.h:955
DEVICE ALWAYS_INLINE Timestamp truncateToHours() const
Definition: heavydbTypes.h:433
DEVICE ALWAYS_INLINE int64_t getDay() const
Definition: heavydbTypes.h:470
DEVICE ALWAYS_INLINE Timestamp operator+(const Timestamp &t) const
Definition: heavydbTypes.h:556
EXTENSION_NOINLINE_HOST void TableFunctionManager_get_metadata(int8_t *mgr_ptr, const char *key, const uint8_t *&raw_bytes, size_t &num_bytes, TableFunctionMetadataType &value_type)
DEVICE ALWAYS_INLINE bool operator==(const Timestamp &other) const
Definition: heavydbTypes.h:405
int8_t * ptr
Definition: heavydbTypes.h:622
DEVICE ALWAYS_INLINE bool operator!=(const YearMonthTimeInterval &other) const
Definition: heavydbTypes.h:552
std::string to_string(char const *&&v)
int32_t compression
Definition: heavydbTypes.h:689
DEVICE void concatItem(int64_t index, const Array< T > &other)
Definition: heavydbTypes.h:881
int32_t output_srid
Definition: heavydbTypes.h:594
DEVICE ALWAYS_INLINE int64_t size() const
Definition: heavydbTypes.h:334
Simplified core of GeoJSON MultiPolygon coordinates definition.
Definition: heavydbTypes.h:682
DEVICE int32_t getNumRings() const
Definition: heavydbTypes.h:696
#define DEVICE
DEVICE ALWAYS_INLINE Timestamp truncateToYear() const
Definition: heavydbTypes.h:445
int8_t * linestring_sizes
Definition: heavydbTypes.h:640
EXTENSION_NOINLINE_HOST int32_t TableFunctionManager_error_message(int8_t *mgr_ptr, const char *message)
DEVICE ALWAYS_INLINE bool operator==(const TextEncodingDict &other) const
Definition: heavydbTypes.h:169
static constexpr int64_t kMilliSecsPerSec
EXTENSION_NOINLINE_HOST int8_t * TableFunctionManager_getStringDictionaryProxy(int8_t *mgr_ptr, int32_t db_id, int32_t dict_id)
#define HOST
DEVICE int32_t getInputSrid() const
Definition: heavydbTypes.h:600
DEVICE int32_t getDictDbId() const
Definition: heavydbTypes.h:898
int32_t output_srid
Definition: heavydbTypes.h:626
DEVICE int32_t getInputSrid() const
Definition: heavydbTypes.h:632
int32_t error_message(const char *message)
DEVICE Array< T > operator[](const unsigned int index) const
Definition: heavydbTypes.h:836
EXTENSION_NOINLINE int8_t * allocate_varlen_buffer(int64_t element_count, int64_t element_size)
DEVICE T & operator[](const unsigned int index) const
Definition: heavydbTypes.h:738
TableFunctionMetadataType get_metadata_type()
int32_t output_srid
Definition: heavydbTypes.h:691
CONSTEXPR DEVICE bool is_null(const T &value)
std::string TableFunctionManager_getString(int8_t *mgr_ptr, int32_t db_id, int32_t dict_id, int32_t string_id)
StringDictionaryProxy ** string_dict_proxies_
#define CONSTEXPR
DEVICE Array(const int64_t size, const bool is_null=false)
Definition: heavydbTypes.h:232
DEVICE TextEncodingDict inline_null_value()
Definition: heavydbTypes.h:212
DEVICE ALWAYS_INLINE bool operator<(const int32_t &other) const
Definition: heavydbTypes.h:196
DEVICE Column< Array< T > > operator[](const int index) const
void init(LogOptions const &log_opts)
Definition: Logger.cpp:360
DEVICE int32_t getDictId() const
Definition: heavydbTypes.h:962
DEVICE ALWAYS_INLINE bool operator!=(const int32_t &other) const
Definition: heavydbTypes.h:184
DEVICE ALWAYS_INLINE Timestamp operator+(const Timestamp &t) const
Definition: heavydbTypes.h:508
DEVICE ALWAYS_INLINE bool isNull() const
Definition: heavydbTypes.h:165
DEVICE int32_t getCompression() const
Definition: heavydbTypes.h:654
DEVICE T operator()(const unsigned int index) const
Definition: heavydbTypes.h:245
int64_t bigintval
Definition: Datum.h:72
int8_t * ring_sizes
Definition: heavydbTypes.h:685
DEVICE int32_t getCoordsSize() const
Definition: heavydbTypes.h:671
int32_t coords_size
Definition: heavydbTypes.h:684
StringDictionaryProxy * string_dict_proxy_
Definition: heavydbTypes.h:915
CONSTEXPR DEVICE void set_null(T &value)
DEVICE ALWAYS_INLINE int64_t numStepsBetween(const Timestamp &begin, const Timestamp &end) const
Definition: heavydbTypes.h:517
int32_t input_srid
Definition: heavydbTypes.h:690
DEVICE int32_t getNumPolygons() const
Definition: heavydbTypes.h:700
TextEncodingNone(const std::string &str)
Definition: heavydbTypes.h:297
int32_t input_srid
Definition: heavydbTypes.h:609
const char * getCString(int32_t db_id, int32_t dict_id, int32_t string_id)
DEVICE int64_t getSize() const
Definition: heavydbTypes.h:256
#define EXTENSION_NOINLINE_HOST
Definition: heavydbTypes.h:49
DEVICE int32_t getCompression() const
Definition: heavydbTypes.h:675
DEVICE ALWAYS_INLINE bool operator==(const char *rhs) const
Definition: heavydbTypes.h:318
DEVICE ALWAYS_INLINE int64_t operator/(const Timestamp &other) const
Definition: heavydbTypes.h:386
DEVICE int32_t getCoordsSize() const
Definition: heavydbTypes.h:694
int64_t num_rows_
Definition: heavydbTypes.h:726
DEVICE int32_t getInputSrid() const
Definition: heavydbTypes.h:616
std::string toString(const ExecutorDeviceType &device_type)
DEVICE Array()
Definition: heavydbTypes.h:230
DEVICE ALWAYS_INLINE DayTimeInterval operator*(const int64_t multiplier) const
Definition: heavydbTypes.h:513
DEVICE int32_t getInputSrid() const
Definition: heavydbTypes.h:704
DEVICE TextEncodingDict & operator[](const unsigned int index) const
Definition: heavydbTypes.h:937
int32_t compression
Definition: heavydbTypes.h:592
int8_t is_null
Definition: heavydbTypes.h:226
DEVICE int32_t getOutputSrid() const
Definition: heavydbTypes.h:658
DEVICE ALWAYS_INLINE int64_t getMinutes() const
Definition: heavydbTypes.h:464
int32_t num_rings
Definition: heavydbTypes.h:665
DEVICE ALWAYS_INLINE int64_t getSeconds() const
Definition: heavydbTypes.h:461
bool g_enable_smem_group_by true
DEVICE ALWAYS_INLINE bool operator!=(const TextEncodingDict &other) const
Definition: heavydbTypes.h:181
int8_t * ring_sizes
Definition: heavydbTypes.h:664
int32_t sz
Definition: heavydbTypes.h:591
void disable_output_allocations()
TableFunctionMetadataType
DEVICE const T & operator[](const unsigned int index) const
Definition: heavydbTypes.h:254
DEVICE ALWAYS_INLINE const Timestamp operator-(const Timestamp &other) const
Definition: heavydbTypes.h:371
EXTENSION_NOINLINE_HOST int32_t table_function_error(const char *message)
DEVICE TextEncodingDict * getPtr() const
Definition: heavydbTypes.h:949
int8_t * poly_sizes
Definition: heavydbTypes.h:687
#define RUNTIME_EXPORT
DEVICE int64_t numCols() const
DEVICE int32_t getNumRings() const
Definition: heavydbTypes.h:673
StringDictionaryProxy * getStringDictionaryProxy(int32_t db_id, int32_t dict_id)
int8_t ** ptrs_
int64_t num_cols_
DEVICE ALWAYS_INLINE Timestamp truncateToMilliseconds() const
Definition: heavydbTypes.h:421
TextEncodingDict(const int32_t other)
Definition: heavydbTypes.h:154
EXTENSION_NOINLINE_HOST const char * TableFunctionManager_getCString(int8_t *mgr_ptr, int32_t db_id, int32_t dict_id, int32_t string_id)
DEVICE ALWAYS_INLINE bool operator!=(const Timestamp &other) const
Definition: heavydbTypes.h:409
Status setNull(int64_t index)
Definition: FlatBuffer.h:585
DEVICE int32_t getSize() const
Definition: heavydbTypes.h:628
DEVICE int32_t getCompression() const
Definition: heavydbTypes.h:630
DEVICE constexpr T null_value() const
Definition: heavydbTypes.h:260
DEVICE int32_t getOutputSrid() const
Definition: heavydbTypes.h:679
DEVICE Timestamp(int64_t timeval)
Definition: heavydbTypes.h:345
DEVICE ALWAYS_INLINE char & operator[](const unsigned int index)
Definition: heavydbTypes.h:315
EXTENSION_NOINLINE_HOST void TableFunctionManager_set_metadata(int8_t *mgr_ptr, const char *key, const uint8_t *raw_bytes, const size_t num_bytes, const TableFunctionMetadataType value_type)
TextEncodingDict * ptr_
Definition: heavydbTypes.h:911
DEVICE bool isNull(int64_t index) const
Definition: heavydbTypes.h:754
int32_t getOrAddTransient(int32_t db_id, int32_t dict_id, std::string str)
DEVICE int32_t getNumLineStrings() const
Definition: heavydbTypes.h:652
DEVICE ALWAYS_INLINE Timestamp truncateToMicroseconds() const
Definition: heavydbTypes.h:417
DEVICE void setNull(int64_t index)
Definition: heavydbTypes.h:755
int8_t * ptr
Definition: heavydbTypes.h:590
DEVICE int32_t getDictId() const
Definition: heavydbTypes.h:903
DEVICE Column(const Column &other)
Definition: heavydbTypes.h:732
DEVICE int32_t getOutputSrid() const
Definition: heavydbTypes.h:602
DEVICE int32_t getInputSrid() const
Definition: heavydbTypes.h:656
DEVICE Column< TextEncodingDict > operator[](const int index) const
DEVICE ALWAYS_INLINE int64_t getMonth() const
Definition: heavydbTypes.h:473
DEVICE Column(TextEncodingDict *ptr, const int64_t num_rows, StringDictionaryProxy *string_dict_proxy)
Definition: heavydbTypes.h:920
int32_t compression
Definition: heavydbTypes.h:624
DEVICE int64_t ExtractFromTime(ExtractField field, const int64_t timeval)
DEVICE bool isNull(int64_t index) const
Definition: heavydbTypes.h:953
RUNTIME_EXPORT NEVER_INLINE HOST std::string RowFunctionManager_getString(int8_t *mgr_ptr, int32_t db_id, int32_t dict_id, int32_t string_id)
DEVICE int8_t * getRingSizes()
Definition: heavydbTypes.h:670
std::string typeName(const T *v)
Definition: toString.h:103
DEVICE int64_t getSize() const
Definition: heavydbTypes.h:596
DEVICE Column< TextEncodingDict > & operator=(const Column< TextEncodingDict > &other)
Definition: heavydbTypes.h:981
DEVICE void setSize(int64_t num_rows)
Definition: heavydbTypes.h:752
DEVICE ALWAYS_INLINE bool operator==(const DayTimeInterval &other) const
Definition: heavydbTypes.h:500
DEVICE ALWAYS_INLINE Timestamp operator+(const DayTimeInterval &interval) const
Definition: heavydbTypes.h:579
DEVICE ALWAYS_INLINE int64_t getHours() const
Definition: heavydbTypes.h:467
DEVICE ALWAYS_INLINE bool isNull() const
Definition: heavydbTypes.h:335
#define NEVER_INLINE
DEVICE int32_t getCompression() const
Definition: heavydbTypes.h:598
EXTENSION_NOINLINE_HOST void TableFunctionManager_set_output_row_size(int8_t *mgr_ptr, int64_t num_rows)
TextEncodingNone()=default
DEVICE int32_t getSize() const
Definition: heavydbTypes.h:612
void set_metadata(const std::string &key, const T &value)
DEVICE Array(T *ptr, const int64_t size, const bool is_null=false)
Definition: heavydbTypes.h:228
DEVICE ALWAYS_INLINE Timestamp truncateToMonth() const
Definition: heavydbTypes.h:441
DEVICE ALWAYS_INLINE bool operator<(const Timestamp &other) const
Definition: heavydbTypes.h:413
DEVICE int8_t * getCoords() const
Definition: heavydbTypes.h:646
DEVICE void setItem(int64_t index, const Array< T > &other)
Definition: heavydbTypes.h:864
std::string getString(int32_t db_id, int32_t dict_id, int32_t string_id)
DEVICE ALWAYS_INLINE int64_t numStepsBetween(const Timestamp &begin, const Timestamp &end) const
Definition: heavydbTypes.h:565
DEVICE bool isNull(int64_t index) const
Definition: heavydbTypes.h:842
T * ptr
Definition: heavydbTypes.h:224
DEVICE int64_t numCols() const
int32_t output_srid
Definition: heavydbTypes.h:610
DEVICE ALWAYS_INLINE int64_t getMilliseconds() const
Definition: heavydbTypes.h:457
DEVICE T & operator[](const unsigned int index)
Definition: heavydbTypes.h:253
DEVICE int64_t size() const
Definition: heavydbTypes.h:950
Timestamp()=default
int8_t * ptr_coords
Definition: heavydbTypes.h:683
EXTENSION_NOINLINE_HOST int32_t TableFunctionManager_getNewDictId(int8_t *mgr_ptr)
DEVICE int32_t getOutputSrid() const
Definition: heavydbTypes.h:618
DEVICE int64_t size() const
DEVICE Column(const Column &other)
Definition: heavydbTypes.h:916
DEVICE ALWAYS_INLINE const Timestamp operator*(const int64_t multiplier) const
Definition: heavydbTypes.h:395
DEVICE int32_t getOutputSrid() const
Definition: heavydbTypes.h:706
DEVICE ALWAYS_INLINE YearMonthTimeInterval operator*(const int64_t multiplier) const
Definition: heavydbTypes.h:561
DEVICE Column(T *ptr, const int64_t num_rows)
Definition: heavydbTypes.h:728
DEVICE const TextEncodingDict getOrAddTransient(const std::string &str)
Definition: heavydbTypes.h:975
DEVICE ColumnList(int8_t **ptrs, const int64_t num_cols, const int64_t num_rows, StringDictionaryProxy **string_dict_proxies)
DEVICE ALWAYS_INLINE int64_t getNanoseconds() const
Definition: heavydbTypes.h:449
#define ALWAYS_INLINE
Definition: Datum.h:67
DEVICE DayTimeInterval(int64_t init)
Definition: heavydbTypes.h:498
DEVICE ALWAYS_INLINE Timestamp truncateToMinutes() const
Definition: heavydbTypes.h:429
DEVICE bool isNull(const unsigned int index) const
Definition: heavydbTypes.h:262
void enable_output_allocations()
DEVICE ALWAYS_INLINE bool operator==(const int32_t &other) const
Definition: heavydbTypes.h:173
static TableFunctionManager * get_singleton()
EXTENSION_NOINLINE_HOST void TableFunctionManager_set_output_array_values_total_number(int8_t *mgr_ptr, int32_t index, int64_t output_array_values_total_number)
DEVICE bool isNull() const
Definition: heavydbTypes.h:258
DEVICE ALWAYS_INLINE bool operator<(const int64_t &other) const
Definition: heavydbTypes.h:200
int32_t input_srid
Definition: heavydbTypes.h:667
static constexpr int64_t kMicroSecsPerSec
DEVICE ALWAYS_INLINE bool operator!=(const char *rhs) const
Definition: heavydbTypes.h:330
DEVICE void setSize(int64_t num_rows)
Definition: heavydbTypes.h:951
int32_t getDictDbId(const char *func_name, size_t arg_idx)
int32_t input_srid
Definition: heavydbTypes.h:625
DEVICE ALWAYS_INLINE bool operator==(const int64_t &other) const
Definition: heavydbTypes.h:177
EXTENSION_NOINLINE_HOST int32_t TableFunctionManager_getOrAddTransient(int8_t *mgr_ptr, int32_t db_id, int32_t dict_id, std::string str)
DEVICE int32_t getCompression() const
Definition: heavydbTypes.h:614
DEVICE const char * getCString(int64_t index) const
Definition: heavydbTypes.h:968
DEVICE Column(std::vector< TextEncodingDict > &input_vec)
Definition: heavydbTypes.h:924
DEVICE int32_t getOutputSrid() const
Definition: heavydbTypes.h:634