@@ -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,50 @@ 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
+ case substrait::Type::KindCase::kIntervalYear :
363
+ return {LogicalTypeId::INTERVAL};
325
364
default :
326
365
throw NotImplementedException (" Substrait type not yet supported: %s" ,
327
- substrait::Type::GetDescriptor ()->FindFieldByNumber (s_type.kind_case ())->name ());
366
+ substrait::Type::GetDescriptor ()->FindFieldByNumber (s_type.kind_case ())->name ());
328
367
}
329
368
}
330
369
@@ -378,9 +417,10 @@ unique_ptr<ParsedExpression> SubstraitToDuckDB::TransformNested(const substrait:
378
417
} else if (nested_expression.has_map ()) {
379
418
auto &map_expression = nested_expression.map ();
380
419
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 ()));
420
+ for (auto &key_value_pair : map_expression.key_values ()) {
421
+ children.emplace_back (TransformExpr (key_value_pair.key ()));
422
+ children.emplace_back (TransformExpr (key_value_pair.value ()));
423
+ }
384
424
return make_uniq<FunctionExpression>(" map" , std::move (children));
385
425
386
426
} else {
@@ -410,15 +450,15 @@ unique_ptr<ParsedExpression> SubstraitToDuckDB::TransformExpr(const substrait::E
410
450
return TransformNested (sexpr, iterator);
411
451
case substrait::Expression::RexTypeCase::kSubquery :
412
452
default :
413
- throw NotImplementedException (" Unsupported expression type %s" ,
414
- substrait::Expression::GetDescriptor ()->FindFieldByNumber (sexpr.rex_type_case ())->name ());
453
+ throw NotImplementedException (
454
+ " Unsupported expression type %s" ,
455
+ substrait::Expression::GetDescriptor ()->FindFieldByNumber (sexpr.rex_type_case ())->name ());
415
456
}
416
457
}
417
458
418
459
string SubstraitToDuckDB::FindFunction (uint64_t id) {
419
460
if (functions_map.find (id) == functions_map.end ()) {
420
- throw NotImplementedException (" Could not find aggregate function %s" ,
421
- to_string (id));
461
+ throw NotImplementedException (" Could not find aggregate function %s" , to_string (id));
422
462
}
423
463
return functions_map[id];
424
464
}
@@ -446,8 +486,9 @@ OrderByNode SubstraitToDuckDB::TransformOrder(const substrait::SortField &sordf)
446
486
dnullorder = OrderByNullType::NULLS_LAST;
447
487
break ;
448
488
default :
449
- throw NotImplementedException (" Unsupported ordering %s" ,
450
- substrait::SortField::GetDescriptor ()->FindFieldByNumber (sordf.direction ())->name ());
489
+ throw NotImplementedException (
490
+ " Unsupported ordering %s" ,
491
+ substrait::SortField::GetDescriptor ()->FindFieldByNumber (sordf.direction ())->name ());
451
492
}
452
493
453
494
return {dordertype, dnullorder, TransformExpr (sordf.expr ())};
@@ -478,7 +519,7 @@ shared_ptr<Relation> SubstraitToDuckDB::TransformJoinOp(const substrait::Rel &so
478
519
break ;
479
520
default :
480
521
throw NotImplementedException (" Unsupported join type: %s" ,
481
- substrait::JoinRel::GetDescriptor ()->FindFieldByNumber (sjoin.type ())->name ());
522
+ substrait::JoinRel::GetDescriptor ()->FindFieldByNumber (sjoin.type ())->name ());
482
523
}
483
524
unique_ptr<ParsedExpression> join_condition = TransformExpr (sjoin.expression ());
484
525
return make_shared_ptr<JoinRelation>(TransformOp (sjoin.left ())->Alias (" left" ),
@@ -506,8 +547,8 @@ shared_ptr<Relation> SubstraitToDuckDB::TransformFilterOp(const substrait::Rel &
506
547
return make_shared_ptr<FilterRelation>(TransformOp (sfilter.input ()), TransformExpr (sfilter.condition ()));
507
548
}
508
549
509
- const substrait::RelCommon* GetCommon (const substrait::Rel &sop) {
510
- const substrait::RelCommon * common;
550
+ const substrait::RelCommon * GetCommon (const substrait::Rel &sop) {
551
+ const substrait::RelCommon *common;
511
552
switch (sop.rel_type_case ()) {
512
553
case substrait::Rel::RelTypeCase::kRead :
513
554
return &sop.read ().common ();
@@ -550,12 +591,12 @@ const substrait::RelCommon* GetCommon(const substrait::Rel &sop) {
550
591
case substrait::Rel::RelTypeCase::kDdl :
551
592
default :
552
593
throw NotImplementedException (" Unsupported relation type %s" ,
553
- substrait::Rel::GetDescriptor ()->FindFieldByNumber (sop.rel_type_case ())->name ());
594
+ substrait::Rel::GetDescriptor ()->FindFieldByNumber (sop.rel_type_case ())->name ());
554
595
}
555
596
}
556
597
557
- const google::protobuf::RepeatedField<int32_t >& GetOutputMapping (const substrait::Rel &sop) {
558
- const substrait::RelCommon* common = GetCommon (sop);
598
+ const google::protobuf::RepeatedField<int32_t > & GetOutputMapping (const substrait::Rel &sop) {
599
+ const substrait::RelCommon * common = GetCommon (sop);
559
600
if (!common->has_emit ()) {
560
601
static google::protobuf::RepeatedField<int32_t > empty_mapping;
561
602
return empty_mapping;
@@ -757,15 +798,15 @@ shared_ptr<Relation> SubstraitToDuckDB::TransformReadOp(const substrait::Rel &so
757
798
}
758
799
parameters.push_back (Value::UBIGINT (snapshot_id));
759
800
} else if (sget.iceberg_table ().direct ().has_snapshot_timestamp ()) {
760
- parameters.push_back ( Value::TIMESTAMP (timestamp_t (sget.iceberg_table ().direct ().snapshot_timestamp ())));
801
+ parameters.push_back (Value::TIMESTAMP (timestamp_t (sget.iceberg_table ().direct ().snapshot_timestamp ())));
761
802
}
762
803
shared_ptr<TableFunctionRelation> scan_rel;
763
804
if (acquire_lock) {
764
805
scan_rel = make_shared_ptr<TableFunctionRelation>(context, " iceberg_scan" , parameters,
765
- std::move (named_parameters));
806
+ std::move (named_parameters));
766
807
} else {
767
808
scan_rel = make_shared_ptr<TableFunctionRelation>(context_wrapper, " iceberg_scan" , parameters,
768
- std::move (named_parameters));
809
+ std::move (named_parameters));
769
810
}
770
811
auto rel = static_cast <Relation *>(scan_rel.get ());
771
812
scan = rel->Alias (name);
@@ -810,7 +851,8 @@ shared_ptr<Relation> SubstraitToDuckDB::GetValueRelationWithSingleBoolColumn() {
810
851
return scan;
811
852
}
812
853
813
- shared_ptr<Relation> SubstraitToDuckDB::GetValuesExpression (const google::protobuf::RepeatedPtrField<substrait::Expression_Nested_Struct> &expression_rows) {
854
+ shared_ptr<Relation> SubstraitToDuckDB::GetValuesExpression (
855
+ const google::protobuf::RepeatedPtrField<substrait::Expression_Nested_Struct> &expression_rows) {
814
856
vector<vector<unique_ptr<ParsedExpression>>> expressions;
815
857
for (auto &row : expression_rows) {
816
858
vector<unique_ptr<ParsedExpression>> expression_row;
@@ -852,7 +894,7 @@ static SetOperationType TransformSetOperationType(substrait::SetRel_SetOp setop)
852
894
}
853
895
default : {
854
896
throw NotImplementedException (" SetOperationType transform not implemented for SetRel_SetOp type %s" ,
855
- substrait::SetRel::GetDescriptor ()->FindFieldByNumber (setop)->name ());
897
+ substrait::SetRel::GetDescriptor ()->FindFieldByNumber (setop)->name ());
856
898
}
857
899
}
858
900
}
@@ -895,28 +937,30 @@ shared_ptr<Relation> SubstraitToDuckDB::TransformWriteOp(const substrait::Rel &s
895
937
}
896
938
auto input = TransformOp (swrite.input ());
897
939
switch (swrite.op ()) {
898
- case substrait::WriteRel::WriteOp::WriteRel_WriteOp_WRITE_OP_CTAS:
899
- return input->CreateRel (schema_name, table_name);
940
+ case substrait::WriteRel::WriteOp::WriteRel_WriteOp_WRITE_OP_CTAS:
941
+ return input->CreateRel (schema_name, table_name);
900
942
case substrait::WriteRel::WriteOp::WriteRel_WriteOp_WRITE_OP_INSERT:
901
943
return input->InsertRel (schema_name, table_name);
902
944
case substrait::WriteRel::WriteOp::WriteRel_WriteOp_WRITE_OP_DELETE: {
903
945
switch (input->type ) {
904
946
case RelationType::PROJECTION_RELATION: {
905
947
auto project = std::move (input.get ()->Cast <ProjectionRelation>());
906
948
auto filter = std::move (project.child ->Cast <FilterRelation>());
907
- return make_shared_ptr<DeleteRelation>(filter.context , std::move (filter.condition ), schema_name, table_name);
949
+ return make_shared_ptr<DeleteRelation>(filter.context , std::move (filter.condition ), schema_name,
950
+ table_name);
908
951
}
909
952
case RelationType::FILTER_RELATION: {
910
953
auto filter = std::move (input.get ()->Cast <FilterRelation>());
911
- return make_shared_ptr<DeleteRelation>(filter.context , std::move (filter.condition ), schema_name, table_name);
954
+ return make_shared_ptr<DeleteRelation>(filter.context , std::move (filter.condition ), schema_name,
955
+ table_name);
912
956
}
913
957
default :
914
958
throw NotImplementedException (" Unsupported relation type for delete operation" );
915
959
}
916
960
}
917
961
default :
918
962
throw NotImplementedException (" Unsupported write operation %s" ,
919
- substrait::WriteRel::GetDescriptor ()->FindFieldByNumber (swrite.op ())->name ());
963
+ substrait::WriteRel::GetDescriptor ()->FindFieldByNumber (swrite.op ())->name ());
920
964
}
921
965
}
922
966
@@ -945,7 +989,7 @@ shared_ptr<Relation> SubstraitToDuckDB::TransformOp(const substrait::Rel &sop,
945
989
return TransformWriteOp (sop);
946
990
default :
947
991
throw NotImplementedException (" Unsupported relation type %s" ,
948
- substrait::Rel::GetDescriptor ()->FindFieldByNumber (sop.rel_type_case ())->name ());
992
+ substrait::Rel::GetDescriptor ()->FindFieldByNumber (sop.rel_type_case ())->name ());
949
993
}
950
994
}
951
995
0 commit comments