@@ -174,8 +174,9 @@ Value TransformLiteralToValue(const substrait::Expression_Literal &literal) {
174
174
case substrait::Expression_Literal::LiteralTypeCase::kVarChar :
175
175
return {literal.var_char ().value ()};
176
176
default :
177
- throw NotImplementedException (" literals of this type are not implemented: %s" ,
178
- substrait::Expression_Literal::GetDescriptor ()->FindFieldByNumber (literal.literal_type_case ())->name ());
177
+ throw NotImplementedException (
178
+ " literals of this type are not implemented: %s" ,
179
+ substrait::Expression_Literal::GetDescriptor ()->FindFieldByNumber (literal.literal_type_case ())->name ());
179
180
}
180
181
}
181
182
@@ -305,6 +306,8 @@ LogicalType SubstraitToDuckDB::SubstraitToDuckType(const substrait::Type &s_type
305
306
switch (s_type.kind_case ()) {
306
307
case substrait::Type::KindCase::kBool :
307
308
return {LogicalTypeId::BOOLEAN};
309
+ case substrait::Type::KindCase::kI8 :
310
+ return {LogicalTypeId::TINYINT};
308
311
case substrait::Type::KindCase::kI16 :
309
312
return {LogicalTypeId::SMALLINT};
310
313
case substrait::Type::KindCase::kI32 :
@@ -317,14 +320,49 @@ LogicalType SubstraitToDuckDB::SubstraitToDuckType(const substrait::Type &s_type
317
320
}
318
321
case substrait::Type::KindCase::kDate :
319
322
return {LogicalTypeId::DATE};
323
+ case substrait::Type::KindCase::kTime :
324
+ return {LogicalTypeId::TIME};
320
325
case substrait::Type::KindCase::kVarchar :
321
326
case substrait::Type::KindCase::kString :
322
327
return {LogicalTypeId::VARCHAR};
328
+ case substrait::Type::KindCase::kBinary :
329
+ return {LogicalTypeId::BLOB};
330
+ case substrait::Type::KindCase::kFp32 :
331
+ return {LogicalTypeId::FLOAT};
323
332
case substrait::Type::KindCase::kFp64 :
324
333
return {LogicalTypeId::DOUBLE};
334
+ case substrait::Type::KindCase::kTimestamp :
335
+ return {LogicalTypeId::TIMESTAMP};
336
+ case substrait::Type::KindCase::kList : {
337
+ auto &s_list_type = s_type.list ();
338
+ auto element_type = SubstraitToDuckType (s_list_type.type ());
339
+ return LogicalType::LIST (element_type);
340
+ }
341
+ case substrait::Type::KindCase::kMap : {
342
+ auto &s_map_type = s_type.map ();
343
+ auto key_type = SubstraitToDuckType (s_map_type.key ());
344
+ auto value_type = SubstraitToDuckType (s_map_type.value ());
345
+ return LogicalType::MAP (key_type, value_type);
346
+ }
347
+ case substrait::Type::KindCase::kStruct : {
348
+ auto &s_struct_type = s_type.struct_ ();
349
+ child_list_t <LogicalType> children;
350
+
351
+ for (idx_t i = 0 ; i < s_struct_type.types_size (); i++) {
352
+ auto field_name = " f" + std::to_string (i);
353
+ auto field_type = SubstraitToDuckType (s_struct_type.types (i));
354
+ children.push_back (make_pair (field_name, field_type));
355
+ }
356
+
357
+ return LogicalType::STRUCT (children);
358
+ }
359
+ case substrait::Type::KindCase::kUuid :
360
+ return {LogicalTypeId::UUID};
361
+ case substrait::Type::KindCase::kIntervalDay :
362
+ return {LogicalTypeId::INTERVAL};
325
363
default :
326
364
throw NotImplementedException (" Substrait type not yet supported: %s" ,
327
- substrait::Type::GetDescriptor ()->FindFieldByNumber (s_type.kind_case ())->name ());
365
+ substrait::Type::GetDescriptor ()->FindFieldByNumber (s_type.kind_case ())->name ());
328
366
}
329
367
}
330
368
@@ -378,9 +416,10 @@ unique_ptr<ParsedExpression> SubstraitToDuckDB::TransformNested(const substrait:
378
416
} else if (nested_expression.has_map ()) {
379
417
auto &map_expression = nested_expression.map ();
380
418
vector<unique_ptr<ParsedExpression>> children;
381
- auto key_value = map_expression.key_values ();
382
- children.emplace_back (TransformExpr (key_value[0 ].key ()));
383
- children.emplace_back (TransformExpr (key_value[0 ].value ()));
419
+ for (auto &key_value_pair : map_expression.key_values ()) {
420
+ children.emplace_back (TransformExpr (key_value_pair.key ()));
421
+ children.emplace_back (TransformExpr (key_value_pair.value ()));
422
+ }
384
423
return make_uniq<FunctionExpression>(" map" , std::move (children));
385
424
386
425
} else {
@@ -410,15 +449,15 @@ unique_ptr<ParsedExpression> SubstraitToDuckDB::TransformExpr(const substrait::E
410
449
return TransformNested (sexpr, iterator);
411
450
case substrait::Expression::RexTypeCase::kSubquery :
412
451
default :
413
- throw NotImplementedException (" Unsupported expression type %s" ,
414
- substrait::Expression::GetDescriptor ()->FindFieldByNumber (sexpr.rex_type_case ())->name ());
452
+ throw NotImplementedException (
453
+ " Unsupported expression type %s" ,
454
+ substrait::Expression::GetDescriptor ()->FindFieldByNumber (sexpr.rex_type_case ())->name ());
415
455
}
416
456
}
417
457
418
458
string SubstraitToDuckDB::FindFunction (uint64_t id) {
419
459
if (functions_map.find (id) == functions_map.end ()) {
420
- throw NotImplementedException (" Could not find aggregate function %s" ,
421
- to_string (id));
460
+ throw NotImplementedException (" Could not find aggregate function %s" , to_string (id));
422
461
}
423
462
return functions_map[id];
424
463
}
@@ -446,8 +485,9 @@ OrderByNode SubstraitToDuckDB::TransformOrder(const substrait::SortField &sordf)
446
485
dnullorder = OrderByNullType::NULLS_LAST;
447
486
break ;
448
487
default :
449
- throw NotImplementedException (" Unsupported ordering %s" ,
450
- substrait::SortField::GetDescriptor ()->FindFieldByNumber (sordf.direction ())->name ());
488
+ throw NotImplementedException (
489
+ " Unsupported ordering %s" ,
490
+ substrait::SortField::GetDescriptor ()->FindFieldByNumber (sordf.direction ())->name ());
451
491
}
452
492
453
493
return {dordertype, dnullorder, TransformExpr (sordf.expr ())};
@@ -478,7 +518,7 @@ shared_ptr<Relation> SubstraitToDuckDB::TransformJoinOp(const substrait::Rel &so
478
518
break ;
479
519
default :
480
520
throw NotImplementedException (" Unsupported join type: %s" ,
481
- substrait::JoinRel::GetDescriptor ()->FindFieldByNumber (sjoin.type ())->name ());
521
+ substrait::JoinRel::GetDescriptor ()->FindFieldByNumber (sjoin.type ())->name ());
482
522
}
483
523
unique_ptr<ParsedExpression> join_condition = TransformExpr (sjoin.expression ());
484
524
return make_shared_ptr<JoinRelation>(TransformOp (sjoin.left ())->Alias (" left" ),
@@ -506,8 +546,8 @@ shared_ptr<Relation> SubstraitToDuckDB::TransformFilterOp(const substrait::Rel &
506
546
return make_shared_ptr<FilterRelation>(TransformOp (sfilter.input ()), TransformExpr (sfilter.condition ()));
507
547
}
508
548
509
- const substrait::RelCommon* GetCommon (const substrait::Rel &sop) {
510
- const substrait::RelCommon * common;
549
+ const substrait::RelCommon * GetCommon (const substrait::Rel &sop) {
550
+ const substrait::RelCommon *common;
511
551
switch (sop.rel_type_case ()) {
512
552
case substrait::Rel::RelTypeCase::kRead :
513
553
return &sop.read ().common ();
@@ -550,12 +590,12 @@ const substrait::RelCommon* GetCommon(const substrait::Rel &sop) {
550
590
case substrait::Rel::RelTypeCase::kDdl :
551
591
default :
552
592
throw NotImplementedException (" Unsupported relation type %s" ,
553
- substrait::Rel::GetDescriptor ()->FindFieldByNumber (sop.rel_type_case ())->name ());
593
+ substrait::Rel::GetDescriptor ()->FindFieldByNumber (sop.rel_type_case ())->name ());
554
594
}
555
595
}
556
596
557
- const google::protobuf::RepeatedField<int32_t >& GetOutputMapping (const substrait::Rel &sop) {
558
- const substrait::RelCommon* common = GetCommon (sop);
597
+ const google::protobuf::RepeatedField<int32_t > & GetOutputMapping (const substrait::Rel &sop) {
598
+ const substrait::RelCommon * common = GetCommon (sop);
559
599
if (!common->has_emit ()) {
560
600
static google::protobuf::RepeatedField<int32_t > empty_mapping;
561
601
return empty_mapping;
@@ -757,15 +797,15 @@ shared_ptr<Relation> SubstraitToDuckDB::TransformReadOp(const substrait::Rel &so
757
797
}
758
798
parameters.push_back (Value::UBIGINT (snapshot_id));
759
799
} else if (sget.iceberg_table ().direct ().has_snapshot_timestamp ()) {
760
- parameters.push_back ( Value::TIMESTAMP (timestamp_t (sget.iceberg_table ().direct ().snapshot_timestamp ())));
800
+ parameters.push_back (Value::TIMESTAMP (timestamp_t (sget.iceberg_table ().direct ().snapshot_timestamp ())));
761
801
}
762
802
shared_ptr<TableFunctionRelation> scan_rel;
763
803
if (acquire_lock) {
764
804
scan_rel = make_shared_ptr<TableFunctionRelation>(context, " iceberg_scan" , parameters,
765
- std::move (named_parameters));
805
+ std::move (named_parameters));
766
806
} else {
767
807
scan_rel = make_shared_ptr<TableFunctionRelation>(context_wrapper, " iceberg_scan" , parameters,
768
- std::move (named_parameters));
808
+ std::move (named_parameters));
769
809
}
770
810
auto rel = static_cast <Relation *>(scan_rel.get ());
771
811
scan = rel->Alias (name);
@@ -810,7 +850,8 @@ shared_ptr<Relation> SubstraitToDuckDB::GetValueRelationWithSingleBoolColumn() {
810
850
return scan;
811
851
}
812
852
813
- shared_ptr<Relation> SubstraitToDuckDB::GetValuesExpression (const google::protobuf::RepeatedPtrField<substrait::Expression_Nested_Struct> &expression_rows) {
853
+ shared_ptr<Relation> SubstraitToDuckDB::GetValuesExpression (
854
+ const google::protobuf::RepeatedPtrField<substrait::Expression_Nested_Struct> &expression_rows) {
814
855
vector<vector<unique_ptr<ParsedExpression>>> expressions;
815
856
for (auto &row : expression_rows) {
816
857
vector<unique_ptr<ParsedExpression>> expression_row;
@@ -852,7 +893,7 @@ static SetOperationType TransformSetOperationType(substrait::SetRel_SetOp setop)
852
893
}
853
894
default : {
854
895
throw NotImplementedException (" SetOperationType transform not implemented for SetRel_SetOp type %s" ,
855
- substrait::SetRel::GetDescriptor ()->FindFieldByNumber (setop)->name ());
896
+ substrait::SetRel::GetDescriptor ()->FindFieldByNumber (setop)->name ());
856
897
}
857
898
}
858
899
}
@@ -895,8 +936,8 @@ shared_ptr<Relation> SubstraitToDuckDB::TransformWriteOp(const substrait::Rel &s
895
936
}
896
937
auto input = TransformOp (swrite.input ());
897
938
switch (swrite.op ()) {
898
- case substrait::WriteRel::WriteOp::WriteRel_WriteOp_WRITE_OP_CTAS:
899
- return input->CreateRel (schema_name, table_name);
939
+ case substrait::WriteRel::WriteOp::WriteRel_WriteOp_WRITE_OP_CTAS:
940
+ return input->CreateRel (schema_name, table_name);
900
941
case substrait::WriteRel::WriteOp::WriteRel_WriteOp_WRITE_OP_INSERT:
901
942
return input->InsertRel (schema_name, table_name);
902
943
case substrait::WriteRel::WriteOp::WriteRel_WriteOp_WRITE_OP_DELETE: {
@@ -916,7 +957,7 @@ shared_ptr<Relation> SubstraitToDuckDB::TransformWriteOp(const substrait::Rel &s
916
957
}
917
958
default :
918
959
throw NotImplementedException (" Unsupported write operation %s" ,
919
- substrait::WriteRel::GetDescriptor ()->FindFieldByNumber (swrite.op ())->name ());
960
+ substrait::WriteRel::GetDescriptor ()->FindFieldByNumber (swrite.op ())->name ());
920
961
}
921
962
}
922
963
@@ -945,7 +986,7 @@ shared_ptr<Relation> SubstraitToDuckDB::TransformOp(const substrait::Rel &sop,
945
986
return TransformWriteOp (sop);
946
987
default :
947
988
throw NotImplementedException (" Unsupported relation type %s" ,
948
- substrait::Rel::GetDescriptor ()->FindFieldByNumber (sop.rel_type_case ())->name ());
989
+ substrait::Rel::GetDescriptor ()->FindFieldByNumber (sop.rel_type_case ())->name ());
949
990
}
950
991
}
951
992
0 commit comments