21
21
22
22
#include " duckdb/parser/expression/comparison_expression.hpp"
23
23
24
- #include " substrait/plan.pb.h"
25
- #include " google/protobuf/util/json_util.h"
26
24
#include " duckdb/main/client_data.hpp"
25
+ #include " google/protobuf/util/json_util.h"
26
+ #include " substrait/plan.pb.h"
27
+
28
+ #include < duckdb/main/relation/table_relation.hpp>
27
29
28
30
namespace duckdb {
29
31
const std::unordered_map<std::string, std::string> SubstraitToDuckDB::function_names_remap = {
@@ -625,21 +627,22 @@ int32_t SkipColumnNames(const LogicalType &type) {
625
627
return columns_to_skip;
626
628
}
627
629
628
- Relation *GetProjectionRelation (Relation &relation, string &error) {
630
+ Relation *GetProjectionOrTableRelation (Relation &relation, string &error) {
629
631
error += RelationTypeToString (relation.type );
630
632
switch (relation.type ) {
633
+ case RelationType::TABLE_RELATION:
631
634
case RelationType::PROJECTION_RELATION:
632
635
error += " -> " ;
633
636
return &relation;
634
637
case RelationType::LIMIT_RELATION:
635
638
error += " -> " ;
636
- return GetProjectionRelation (*relation.Cast <LimitRelation>().child , error);
639
+ return GetProjectionOrTableRelation (*relation.Cast <LimitRelation>().child , error);
637
640
case RelationType::ORDER_RELATION:
638
641
error += " -> " ;
639
- return GetProjectionRelation (*relation.Cast <OrderRelation>().child , error);
642
+ return GetProjectionOrTableRelation (*relation.Cast <OrderRelation>().child , error);
640
643
case RelationType::SET_OPERATION_RELATION:
641
644
error += " -> " ;
642
- return GetProjectionRelation (*relation.Cast <SetOpRelation>().right , error);
645
+ return GetProjectionOrTableRelation (*relation.Cast <SetOpRelation>().right , error);
643
646
default :
644
647
throw NotImplementedException (
645
648
" Relation %s is not yet implemented as a possible root chain type of from_substrait function" , error);
@@ -648,15 +651,20 @@ Relation *GetProjectionRelation(Relation &relation, string &error) {
648
651
649
652
shared_ptr<Relation> SubstraitToDuckDB::TransformRootOp (const substrait::RelRoot &sop) {
650
653
vector<string> aliases;
651
- auto column_names = sop.names ();
654
+ const auto & column_names = sop.names ();
652
655
vector<unique_ptr<ParsedExpression>> expressions;
653
656
int id = 1 ;
654
657
auto child = TransformOp (sop.input ());
655
658
string error;
656
- auto first_projection = GetProjectionRelation (*child, error);
657
- auto &columns = first_projection->Cast <ProjectionRelation>().columns ;
659
+ auto first_projection_or_table = GetProjectionOrTableRelation (*child, error);
660
+ vector<ColumnDefinition> *column_definitions;
661
+ if (first_projection_or_table->type == RelationType::PROJECTION_RELATION) {
662
+ column_definitions = &first_projection_or_table->Cast <ProjectionRelation>().columns ;
663
+ } else {
664
+ column_definitions = &first_projection_or_table->Cast <TableRelation>().description ->columns ;
665
+ }
658
666
int32_t i = 0 ;
659
- for (auto &column : columns ) {
667
+ for (auto &column : *column_definitions ) {
660
668
aliases.push_back (column_names[i++]);
661
669
auto column_type = column.GetType ();
662
670
i += SkipColumnNames (column.GetType ());
0 commit comments