23 #ifndef QUERYENGINE_THRIFTSERIALIZERS_H
24 #define QUERYENGINE_THRIFTSERIALIZERS_H
26 #include "gen-cpp/serialized_result_set_types.h"
40 namespace ThriftSerializers {
42 #define THRIFT_LAYOUT_CASE(layout) \
43 case heavyai::QueryDescriptionType::layout: \
44 return TResultSetLayout::layout;
47 const heavyai::QueryDescriptionType layout) {
54 CHECK(
false) <<
static_cast<int>(layout);
59 #undef THRIFT_LAYOUT_CASE
61 #define UNTHRIFT_LAYOUT_CASE(layout) \
62 case TResultSetLayout::layout: \
63 return heavyai::QueryDescriptionType::layout;
73 CHECK(
false) <<
static_cast<int>(layout);
78 #undef UNTHRIFT_LAYOUT_CASE
80 #define THRIFT_AGGKIND_CASE(kind) \
82 return TAggKind::kind;
97 CHECK(
false) <<
static_cast<int>(agg);
102 #undef THRIFT_AGGKIND_CASE
104 #define UNTHRIFT_AGGKIND_CASE(kind) \
105 case TAggKind::kind: \
121 CHECK(
false) <<
static_cast<int>(agg);
126 #undef UNTHRIFT_AGGKIND_CASE
129 const std::vector<TColumnRange>& thrift_column_ranges) {
131 for (
const auto& thrift_column_range : thrift_column_ranges) {
133 thrift_column_range.table_id,
134 thrift_column_range.db_id};
135 switch (thrift_column_range.type) {
136 case TExpressionRangeType::INTEGER:
140 thrift_column_range.int_max,
141 thrift_column_range.bucket,
142 thrift_column_range.has_nulls));
144 case TExpressionRangeType::FLOAT:
148 thrift_column_range.fp_max,
149 thrift_column_range.has_nulls));
151 case TExpressionRangeType::DOUBLE:
155 thrift_column_range.fp_max,
156 thrift_column_range.has_nulls));
165 return column_ranges;
169 const std::vector<TDictionaryGeneration>& thrift_string_dictionary_generations) {
171 for (
const auto& thrift_string_dictionary_generation :
172 thrift_string_dictionary_generations) {
174 {thrift_string_dictionary_generation.db_id,
175 thrift_string_dictionary_generation.dict_id},
176 thrift_string_dictionary_generation.entry_count);
178 return string_dictionary_generations;
191 thrift_ti.precision =
199 TStringDictKey t_dict_key;
200 t_dict_key.
db_id = dict_key.db_id;
201 t_dict_key.dict_id = dict_key.dict_id;
202 thrift_ti.__set_dict_key(t_dict_key);
208 return target_info.
is_agg &&
213 const TRowDescriptor& row_desc) {
214 std::vector<TargetMetaInfo> target_meta_infos;
215 for (
const auto& col : row_desc) {
218 return target_meta_infos;
223 const int output_srid) {
224 col_type.col_type.precision =
static_cast<int>(subtype);
225 col_type.col_type.scale = output_srid;
230 TColumnType proj_info;
232 if (proj_info.col_name.empty()) {
238 proj_info.col_type.nullable = !target_ti.get_notnull();
239 proj_info.col_type.is_array = target_ti.get_type() ==
kARRAY;
240 if (
IS_GEO(target_ti.get_type())) {
242 proj_info, target_ti.get_subtype(), target_ti.get_output_srid());
244 proj_info.col_type.precision = target_ti.get_precision();
245 proj_info.col_type.scale = target_ti.get_scale();
247 if (target_ti.get_type() ==
kDATE) {
248 proj_info.col_type.size = target_ti.get_size();
250 proj_info.col_type.comp_param =
251 (target_ti.is_date_in_days() && target_ti.get_comp_param() == 0)
253 : target_ti.get_comp_param();
256 const auto& dict_key = target_ti.getStringDictKey();
257 TStringDictKey t_dict_key;
258 t_dict_key.db_id = dict_key.db_id;
259 t_dict_key.dict_id = dict_key.dict_id;
260 proj_info.col_type.__set_dict_key(t_dict_key);
266 const std::vector<TargetMetaInfo>& targets) {
267 TRowDescriptor row_desc;
269 for (
const auto& target : targets) {
277 TTargetInfo thrift_target_info;
278 thrift_target_info.is_agg = target_info.
is_agg;
281 thrift_target_info.arg_type =
takes_arg(target_info)
283 : thrift_target_info.type;
285 thrift_target_info.is_distinct = target_info.
is_distinct;
286 return thrift_target_info;
291 target_info.
is_agg = thrift_target_info.is_agg;
294 target_info.
is_distinct = thrift_target_info.is_distinct;
303 const std::vector<TargetInfo>& targets) {
304 std::vector<TTargetInfo> thrift_targets;
305 for (
const auto& target_info : targets) {
308 return thrift_targets;
312 const std::vector<TTargetInfo>& thrift_targets) {
313 std::vector<TargetInfo> targets;
314 for (
const auto& thrift_target_info : thrift_targets) {
320 #define THRIFT_COUNTDESCRIPTORIMPL_CASE(kind) \
321 case CountDistinctImplType::kind: \
322 return TCountDistinctImplType::kind;
336 #undef THRIFT_COUNTDESCRIPTORIMPL_CASE
340 TCountDistinctDescriptor thrift_count_distinct_descriptor;
341 thrift_count_distinct_descriptor.impl_type =
343 thrift_count_distinct_descriptor.min_val = count_distinct_descriptor.
min_val;
344 thrift_count_distinct_descriptor.bitmap_sz_bits =
346 thrift_count_distinct_descriptor.approximate = count_distinct_descriptor.
approximate;
347 thrift_count_distinct_descriptor.device_type =
350 thrift_count_distinct_descriptor.sub_bitmap_count =
352 return thrift_count_distinct_descriptor;
355 #define UNTHRIFT_COUNTDESCRIPTORIMPL_CASE(kind) \
356 case TCountDistinctImplType::kind: \
357 return CountDistinctImplType::kind;
371 #undef UNTHRIFT_COUNTDESCRIPTORIMPL_CASE
374 const TCountDistinctDescriptor& thrift_count_distinct_descriptor) {
378 count_distinct_descriptor.
min_val = thrift_count_distinct_descriptor.min_val;
380 thrift_count_distinct_descriptor.bitmap_sz_bits;
381 count_distinct_descriptor.
approximate = thrift_count_distinct_descriptor.approximate;
383 thrift_count_distinct_descriptor.device_type == TDeviceType::GPU
387 thrift_count_distinct_descriptor.sub_bitmap_count;
388 return count_distinct_descriptor;
393 case TExtArgumentType::Int8:
395 case TExtArgumentType::Int16:
397 case TExtArgumentType::Int32:
399 case TExtArgumentType::Int64:
401 case TExtArgumentType::Float:
405 case TExtArgumentType::Void:
407 case TExtArgumentType::PInt8:
409 case TExtArgumentType::PInt16:
411 case TExtArgumentType::PInt32:
413 case TExtArgumentType::PInt64:
415 case TExtArgumentType::PFloat:
417 case TExtArgumentType::PDouble:
419 case TExtArgumentType::PBool:
421 case TExtArgumentType::Bool:
423 case TExtArgumentType::ArrayInt8:
425 case TExtArgumentType::ArrayInt16:
427 case TExtArgumentType::ArrayInt32:
429 case TExtArgumentType::ArrayInt64:
431 case TExtArgumentType::ArrayFloat:
433 case TExtArgumentType::ArrayDouble:
435 case TExtArgumentType::ArrayBool:
437 case TExtArgumentType::ArrayTextEncodingNone:
439 case TExtArgumentType::ArrayTextEncodingDict:
449 case TExtArgumentType::Cursor:
455 case TExtArgumentType::ColumnInt8:
457 case TExtArgumentType::ColumnInt16:
459 case TExtArgumentType::ColumnInt32:
461 case TExtArgumentType::ColumnInt64:
463 case TExtArgumentType::ColumnFloat:
465 case TExtArgumentType::ColumnDouble:
467 case TExtArgumentType::ColumnBool:
469 case TExtArgumentType::ColumnTextEncodingNone:
471 case TExtArgumentType::ColumnTextEncodingDict:
473 case TExtArgumentType::ColumnTimestamp:
475 case TExtArgumentType::TextEncodingNone:
477 case TExtArgumentType::TextEncodingDict:
479 case TExtArgumentType::Timestamp:
481 case TExtArgumentType::ColumnListInt8:
483 case TExtArgumentType::ColumnListInt16:
485 case TExtArgumentType::ColumnListInt32:
487 case TExtArgumentType::ColumnListInt64:
489 case TExtArgumentType::ColumnListFloat:
491 case TExtArgumentType::ColumnListDouble:
493 case TExtArgumentType::ColumnListBool:
495 case TExtArgumentType::ColumnListTextEncodingNone:
497 case TExtArgumentType::ColumnListTextEncodingDict:
499 case TExtArgumentType::ColumnArrayInt8:
501 case TExtArgumentType::ColumnArrayInt16:
503 case TExtArgumentType::ColumnArrayInt32:
505 case TExtArgumentType::ColumnArrayInt64:
507 case TExtArgumentType::ColumnArrayFloat:
509 case TExtArgumentType::ColumnArrayDouble:
511 case TExtArgumentType::ColumnArrayBool:
513 case TExtArgumentType::ColumnArrayTextEncodingNone:
515 case TExtArgumentType::ColumnArrayTextEncodingDict:
517 case TExtArgumentType::ColumnListArrayInt8:
519 case TExtArgumentType::ColumnListArrayInt16:
521 case TExtArgumentType::ColumnListArrayInt32:
523 case TExtArgumentType::ColumnListArrayInt64:
525 case TExtArgumentType::ColumnListArrayFloat:
527 case TExtArgumentType::ColumnListArrayDouble:
529 case TExtArgumentType::ColumnListArrayBool:
531 case TExtArgumentType::ColumnListArrayTextEncodingNone:
533 case TExtArgumentType::ColumnListArrayTextEncodingDict:
535 case TExtArgumentType::DayTimeInterval:
537 case TExtArgumentType::YearMonthTimeInterval:
539 case TExtArgumentType::ColumnGeoPoint:
541 case TExtArgumentType::ColumnGeoLineString:
543 case TExtArgumentType::ColumnGeoPolygon:
545 case TExtArgumentType::ColumnGeoMultiPoint:
547 case TExtArgumentType::ColumnGeoMultiLineString:
549 case TExtArgumentType::ColumnGeoMultiPolygon:
551 case TExtArgumentType::ColumnListGeoPoint:
553 case TExtArgumentType::ColumnListGeoLineString:
555 case TExtArgumentType::ColumnListGeoPolygon:
557 case TExtArgumentType::ColumnListGeoMultiPoint:
559 case TExtArgumentType::ColumnListGeoMultiLineString:
561 case TExtArgumentType::ColumnListGeoMultiPolygon:
571 return TExtArgumentType::Int8;
573 return TExtArgumentType::Int16;
575 return TExtArgumentType::Int32;
577 return TExtArgumentType::Int64;
579 return TExtArgumentType::Float;
583 return TExtArgumentType::Void;
585 return TExtArgumentType::PInt8;
587 return TExtArgumentType::PInt16;
589 return TExtArgumentType::PInt32;
591 return TExtArgumentType::PInt64;
593 return TExtArgumentType::PFloat;
595 return TExtArgumentType::PDouble;
597 return TExtArgumentType::PBool;
599 return TExtArgumentType::Bool;
601 return TExtArgumentType::ArrayInt8;
603 return TExtArgumentType::ArrayInt16;
605 return TExtArgumentType::ArrayInt32;
607 return TExtArgumentType::ArrayInt64;
609 return TExtArgumentType::ArrayFloat;
611 return TExtArgumentType::ArrayDouble;
613 return TExtArgumentType::ArrayBool;
615 return TExtArgumentType::ArrayTextEncodingNone;
617 return TExtArgumentType::ArrayTextEncodingDict;
627 return TExtArgumentType::Cursor;
633 return TExtArgumentType::ColumnInt8;
635 return TExtArgumentType::ColumnInt16;
637 return TExtArgumentType::ColumnInt32;
639 return TExtArgumentType::ColumnInt64;
641 return TExtArgumentType::ColumnFloat;
643 return TExtArgumentType::ColumnDouble;
645 return TExtArgumentType::ColumnBool;
647 return TExtArgumentType::ColumnTextEncodingNone;
649 return TExtArgumentType::ColumnTextEncodingDict;
651 return TExtArgumentType::ColumnTimestamp;
653 return TExtArgumentType::TextEncodingNone;
655 return TExtArgumentType::TextEncodingDict;
657 return TExtArgumentType::Timestamp;
659 return TExtArgumentType::ColumnListInt8;
661 return TExtArgumentType::ColumnListInt16;
663 return TExtArgumentType::ColumnListInt32;
665 return TExtArgumentType::ColumnListInt64;
667 return TExtArgumentType::ColumnListFloat;
669 return TExtArgumentType::ColumnListDouble;
671 return TExtArgumentType::ColumnListBool;
673 return TExtArgumentType::ColumnListTextEncodingNone;
675 return TExtArgumentType::ColumnListTextEncodingDict;
677 return TExtArgumentType::ColumnArrayInt8;
679 return TExtArgumentType::ColumnArrayInt16;
681 return TExtArgumentType::ColumnArrayInt32;
683 return TExtArgumentType::ColumnArrayInt64;
685 return TExtArgumentType::ColumnArrayFloat;
687 return TExtArgumentType::ColumnArrayDouble;
689 return TExtArgumentType::ColumnArrayBool;
691 return TExtArgumentType::ColumnArrayTextEncodingNone;
693 return TExtArgumentType::ColumnArrayTextEncodingDict;
695 return TExtArgumentType::ColumnListArrayInt8;
697 return TExtArgumentType::ColumnListArrayInt16;
699 return TExtArgumentType::ColumnListArrayInt32;
701 return TExtArgumentType::ColumnListArrayInt64;
703 return TExtArgumentType::ColumnListArrayFloat;
705 return TExtArgumentType::ColumnListArrayDouble;
707 return TExtArgumentType::ColumnListArrayBool;
709 return TExtArgumentType::ColumnListArrayTextEncodingDict;
711 return TExtArgumentType::ColumnListArrayTextEncodingNone;
713 return TExtArgumentType::DayTimeInterval;
715 return TExtArgumentType::YearMonthTimeInterval;
717 return TExtArgumentType::ColumnGeoPoint;
719 return TExtArgumentType::ColumnGeoLineString;
721 return TExtArgumentType::ColumnGeoPolygon;
723 return TExtArgumentType::ColumnGeoMultiPoint;
725 return TExtArgumentType::ColumnGeoMultiLineString;
727 return TExtArgumentType::ColumnGeoMultiPolygon;
729 return TExtArgumentType::ColumnListGeoPoint;
731 return TExtArgumentType::ColumnListGeoLineString;
733 return TExtArgumentType::ColumnListGeoPolygon;
735 return TExtArgumentType::ColumnListGeoMultiPoint;
737 return TExtArgumentType::ColumnListGeoMultiLineString;
739 return TExtArgumentType::ColumnListGeoMultiPolygon;
746 const std::vector<TExtArgumentType::type>& v) {
747 std::vector<ExtArgumentType>
result;
751 std::back_inserter(result),
757 const std::vector<ExtArgumentType>& v) {
758 std::vector<TExtArgumentType::type>
result;
762 std::back_inserter(result),
770 case TOutputBufferSizeType::kConstant:
772 case TOutputBufferSizeType::kUserSpecifiedConstantParameter:
774 case TOutputBufferSizeType::kUserSpecifiedRowMultiplier:
776 case TOutputBufferSizeType::kTableFunctionSpecifiedParameter:
778 case TOutputBufferSizeType::kPreFlightParameter:
789 return TOutputBufferSizeType::kConstant;
791 return TOutputBufferSizeType::kUserSpecifiedConstantParameter;
793 return TOutputBufferSizeType::kUserSpecifiedRowMultiplier;
795 return TOutputBufferSizeType::kTableFunctionSpecifiedParameter;
797 return TOutputBufferSizeType::kPreFlightParameter;
804 TUserDefinedFunction tfunc;
805 tfunc.name = udf.
getName(
true);
813 TUserDefinedTableFunction tfunc;
824 inline std::vector<TUserDefinedTableFunction>
to_thrift(
825 const std::vector<table_functions::TableFunction>& v) {
826 std::vector<TUserDefinedTableFunction>
result;
829 std::back_inserter(result),
838 #endif // QUERYENGINE_THRIFTSERIALIZERS_H
TCountDistinctImplType::type count_distinct_impl_type_to_thrift(const CountDistinctImplType impl_type)
AggregatedColRange column_ranges_from_thrift(const std::vector< TColumnRange > &thrift_column_ranges)
std::vector< TTargetInfo > target_infos_to_thrift(const std::vector< TargetInfo > &targets)
HOST DEVICE SQLTypes get_subtype() const
ExecutorDeviceType device_type
StringDictionaryGenerations string_dictionary_generations_from_thrift(const std::vector< TDictionaryGeneration > &thrift_string_dictionary_generations)
HOST DEVICE int get_size() const
struct GeoLineStringStruct GeoLineString
Descriptor for the storage layout use for (approximate) count distinct operations.
TDatumType::type type_to_thrift(const SQLTypeInfo &type_info)
#define UNTHRIFT_AGGKIND_CASE(kind)
TCountDistinctDescriptor count_distinct_descriptor_to_thrift(const CountDistinctDescriptor &count_distinct_descriptor)
TRowDescriptor target_meta_infos_to_thrift(const std::vector< TargetMetaInfo > &targets)
void setGeneration(const shared::StringDictKey &dict_key, const uint64_t generation)
struct GeoPointStruct GeoPoint
const ExtArgumentType getRet() const
TargetInfo target_info_from_thrift(const TTargetInfo &thrift_target_info)
HOST DEVICE int get_scale() const
Cache for physical column ranges. Set by the aggregator on the leaves.
CountDistinctDescriptor count_distinct_descriptor_from_thrift(const TCountDistinctDescriptor &thrift_count_distinct_descriptor)
ExtArgumentType from_thrift(const TExtArgumentType::type &t)
const std::string getName(bool keep_suffix=true) const
HOST DEVICE SQLTypes get_type() const
CountDistinctImplType impl_type_
static ExpressionRange makeFloatRange(const float fp_min, const float fp_max, const bool has_nulls)
size_t getOutputRowSizeParameter() const
std::vector< TargetInfo > target_infos_from_thrift(const std::vector< TTargetInfo > &thrift_targets)
Supported runtime functions management and retrieval.
bool is_distinct_target(const TargetInfo &target_info)
const std::vector< ExtArgumentType > & getOutputArgs() const
OUTPUT transform(INPUT const &input, FUNC const &func)
SQLTypeInfo type_info_from_thrift(const TTypeInfo &thrift_ti, const bool strip_geo_encoding=false)
SQLAgg agg_kind_from_thrift(const TAggKind::type agg)
std::string getName(const bool drop_suffix=false, const bool lower=false) const
struct GeoMultiPointStruct GeoMultiPoint
int get_precision() const
static ExpressionRange makeIntRange(const int64_t int_min, const int64_t int_max, const int64_t bucket, const bool has_nulls)
void fixup_geo_column_descriptor(TColumnType &col_type, const SQLTypes subtype, const int output_srid)
#define THRIFT_COUNTDESCRIPTORIMPL_CASE(kind)
static ExpressionRange makeDoubleRange(const double fp_min, const double fp_max, const bool has_nulls)
TExtArgumentType::type to_thrift(const ExtArgumentType &t)
CountDistinctImplType count_distinct_impl_type_from_thrift(const TCountDistinctImplType::type impl_type)
struct GeoMultiLineStringStruct GeoMultiLineString
#define UNTHRIFT_COUNTDESCRIPTORIMPL_CASE(kind)
HOST DEVICE EncodingType get_compression() const
heavyai::QueryDescriptionType layout_from_thrift(const TResultSetLayout::type layout)
const std::vector< ExtArgumentType > & getInputArgs() const
QueryEngine enum classes with minimal #include files.
const std::vector< ExtArgumentType > & getInputArgs() const
bool takes_arg(const TargetInfo &target_info)
TColumnType target_meta_info_to_thrift(const TargetMetaInfo &target, const size_t idx)
HOST DEVICE int get_comp_param() const
const std::vector< ExtArgumentType > & getSqlArgs() const
std::vector< TargetMetaInfo > target_meta_infos_from_thrift(const TRowDescriptor &row_desc)
TAggKind::type agg_kind_to_thrift(const SQLAgg agg)
void setColRange(const PhysicalInput &, const ExpressionRange &)
struct GeoMultiPolygonStruct GeoMultiPolygon
static ExpressionRange makeInvalidRange()
#define THRIFT_LAYOUT_CASE(layout)
struct GeoPolygonStruct GeoPolygon
HOST DEVICE bool get_notnull() const
const std::vector< std::map< std::string, std::string > > & getAnnotations() const
TTypeInfo type_info_to_thrift(const SQLTypeInfo &ti)
SQLTypeInfo get_elem_type() const
OutputBufferSizeType getOutputRowSizeType() const
#define UNTHRIFT_LAYOUT_CASE(layout)
#define THRIFT_AGGKIND_CASE(kind)
const std::vector< std::map< std::string, std::string > > & getAnnotations() const
TTargetInfo target_info_to_thrift(const TargetInfo &target_info)
const shared::StringDictKey & getStringDictKey() const
TResultSetLayout::type layout_to_thrift(const heavyai::QueryDescriptionType layout)
TEncodingType::type encoding_to_thrift(const SQLTypeInfo &type_info)