@@ -331,31 +331,30 @@ unique_ptr<ParsedExpression> SubstraitToDuckDB::TransformNested(const substrait:
331
331
auto &nested_expression = sexpr.nested ();
332
332
if (nested_expression.has_struct_ ()) {
333
333
auto &struct_expression = nested_expression.struct_ ();
334
- vector<unique_ptr<ParsedExpression>> children;
335
- for (auto & child: struct_expression.fields ()) {
334
+ vector<unique_ptr<ParsedExpression>> children;
335
+ for (auto & child : struct_expression.fields ()) {
336
336
children.emplace_back (TransformExpr (child));
337
337
}
338
338
return make_uniq<FunctionExpression>(" row" , std::move (children));
339
339
} else if (nested_expression.has_list ()) {
340
340
auto &list_expression = nested_expression.list ();
341
- vector<unique_ptr<ParsedExpression>> children;
342
- for (auto & child: list_expression.values ()) {
341
+ vector<unique_ptr<ParsedExpression>> children;
342
+ for (auto & child : list_expression.values ()) {
343
343
children.emplace_back (TransformExpr (child));
344
344
}
345
345
return make_uniq<FunctionExpression>(" list_value" , std::move (children));
346
346
347
347
} else if (nested_expression.has_map ()) {
348
348
auto &map_expression = nested_expression.map ();
349
- vector<unique_ptr<ParsedExpression>> children;
349
+ vector<unique_ptr<ParsedExpression>> children;
350
350
auto key_value = map_expression.key_values ();
351
351
children.emplace_back (TransformExpr (key_value[0 ].key ()));
352
352
children.emplace_back (TransformExpr (key_value[0 ].value ()));
353
353
return make_uniq<FunctionExpression>(" map" , std::move (children));
354
354
355
- } else {
355
+ } else {
356
356
throw NotImplementedException (" Substrait nested expression is not yet implemented." );
357
357
}
358
-
359
358
}
360
359
361
360
unique_ptr<ParsedExpression> SubstraitToDuckDB::TransformExpr (const substrait::Expression &sexpr) {
@@ -663,25 +662,18 @@ int32_t SkipColumnNames(const LogicalType &type) {
663
662
return columns_to_skip;
664
663
}
665
664
666
- Relation *GetProjectionOrTableRelation (Relation &relation, string &error) {
667
- error += RelationTypeToString (relation.type );
665
+ Relation *GetProjection (Relation &relation) {
668
666
switch (relation.type ) {
669
- case RelationType::TABLE_RELATION:
670
667
case RelationType::PROJECTION_RELATION:
671
- error += " -> " ;
672
668
return &relation;
673
669
case RelationType::LIMIT_RELATION:
674
- error += " -> " ;
675
- return GetProjectionOrTableRelation (*relation.Cast <LimitRelation>().child , error);
670
+ return GetProjection (*relation.Cast <LimitRelation>().child );
676
671
case RelationType::ORDER_RELATION:
677
- error += " -> " ;
678
- return GetProjectionOrTableRelation (*relation.Cast <OrderRelation>().child , error);
672
+ return GetProjection (*relation.Cast <OrderRelation>().child );
679
673
case RelationType::SET_OPERATION_RELATION:
680
- error += " -> " ;
681
- return GetProjectionOrTableRelation (*relation.Cast <SetOpRelation>().right , error);
674
+ return GetProjection (*relation.Cast <SetOpRelation>().right );
682
675
default :
683
- throw NotImplementedException (
684
- " Relation %s is not yet implemented as a possible root chain type of from_substrait function" , error);
676
+ return nullptr ;
685
677
}
686
678
}
687
679
@@ -691,21 +683,23 @@ shared_ptr<Relation> SubstraitToDuckDB::TransformRootOp(const substrait::RelRoot
691
683
vector<unique_ptr<ParsedExpression>> expressions;
692
684
int id = 1 ;
693
685
auto child = TransformOp (sop.input ());
694
- string error;
695
- auto first_projection_or_table = GetProjectionOrTableRelation (*child, error);
696
- vector<ColumnDefinition> *column_definitions;
697
- if (first_projection_or_table->type == RelationType::PROJECTION_RELATION) {
698
- column_definitions = &first_projection_or_table->Cast <ProjectionRelation>().columns ;
686
+ auto first_projection_or_table = GetProjection (*child);
687
+ if (first_projection_or_table) {
688
+ vector<ColumnDefinition> *column_definitions = &first_projection_or_table->Cast <ProjectionRelation>().columns ;
689
+ int32_t i = 0 ;
690
+ for (auto &column : *column_definitions) {
691
+ aliases.push_back (column_names[i++]);
692
+ auto column_type = column.GetType ();
693
+ i += SkipColumnNames (column.GetType ());
694
+ expressions.push_back (make_uniq<PositionalReferenceExpression>(id++));
695
+ }
699
696
} else {
700
- column_definitions = &first_projection_or_table->Cast <TableRelation>().description ->columns ;
701
- }
702
- int32_t i = 0 ;
703
- for (auto &column : *column_definitions) {
704
- aliases.push_back (column_names[i++]);
705
- auto column_type = column.GetType ();
706
- i += SkipColumnNames (column.GetType ());
707
- expressions.push_back (make_uniq<PositionalReferenceExpression>(id++));
697
+ for (auto &column_name : column_names) {
698
+ aliases.push_back (column_name);
699
+ expressions.push_back (make_uniq<PositionalReferenceExpression>(id++));
700
+ }
708
701
}
702
+
709
703
return make_shared_ptr<ProjectionRelation>(child, std::move (expressions), aliases);
710
704
}
711
705
0 commit comments