@@ -542,6 +542,7 @@ unique_ptr<TableDescription> TableInfo(ClientContext &context, const string &sch
542
542
shared_ptr<Relation> SubstraitToDuckDB::TransformReadOp (const substrait::Rel &sop) {
543
543
auto &sget = sop.read ();
544
544
shared_ptr<Relation> scan;
545
+ auto context_wrapper = make_shared_ptr<RelationContextWrapper>(context);
545
546
if (sget.has_named_table ()) {
546
547
auto table_name = sget.named_table ().names (0 );
547
548
// If we can't find a table with that name, let's try a view.
@@ -550,9 +551,19 @@ shared_ptr<Relation> SubstraitToDuckDB::TransformReadOp(const substrait::Rel &so
550
551
if (!table_info) {
551
552
throw CatalogException (" Table '%s' does not exist!" , table_name);
552
553
}
553
- scan = make_shared_ptr<TableRelation>(context, std::move (table_info), acquire_lock);
554
+ if (acquire_lock) {
555
+ scan = make_shared_ptr<TableRelation>(context, std::move (table_info));
556
+
557
+ } else {
558
+ scan = make_shared_ptr<TableRelation>(context_wrapper, std::move (table_info));
559
+ }
554
560
} catch (...) {
555
- scan = make_shared_ptr<ViewRelation>(context, DEFAULT_SCHEMA, table_name, acquire_lock);
561
+ if (acquire_lock) {
562
+ scan = make_shared_ptr<ViewRelation>(context, DEFAULT_SCHEMA, table_name);
563
+
564
+ } else {
565
+ scan = make_shared_ptr<ViewRelation>(context_wrapper, DEFAULT_SCHEMA, table_name);
566
+ }
556
567
}
557
568
} else if (sget.has_local_files ()) {
558
569
vector<Value> parquet_files;
@@ -574,8 +585,15 @@ shared_ptr<Relation> SubstraitToDuckDB::TransformReadOp(const substrait::Rel &so
574
585
string name = " parquet_" + StringUtil::GenerateRandomName ();
575
586
named_parameter_map_t named_parameters ({{" binary_as_string" , Value::BOOLEAN (false )}});
576
587
vector<Value> parameters {Value::LIST (parquet_files)};
577
- auto scan_rel = make_shared_ptr<TableFunctionRelation>(
578
- context, " parquet_scan" , parameters, std::move (named_parameters), nullptr , true , acquire_lock);
588
+ shared_ptr<TableFunctionRelation> scan_rel;
589
+ if (acquire_lock) {
590
+ scan_rel = make_shared_ptr<TableFunctionRelation>(context, " parquet_scan" , parameters,
591
+ std::move (named_parameters));
592
+ } else {
593
+ scan_rel = make_shared_ptr<TableFunctionRelation>(context_wrapper, " parquet_scan" , parameters,
594
+ std::move (named_parameters));
595
+ }
596
+
579
597
auto rel = static_cast <Relation *>(scan_rel.get ());
580
598
scan = rel->Alias (name);
581
599
} else if (sget.has_virtual_table ()) {
@@ -591,7 +609,12 @@ shared_ptr<Relation> SubstraitToDuckDB::TransformReadOp(const substrait::Rel &so
591
609
expression_rows.emplace_back (expression_row);
592
610
}
593
611
vector<string> column_names;
594
- scan = make_shared_ptr<ValueRelation>(context, expression_rows, column_names, " values" , acquire_lock);
612
+ if (acquire_lock) {
613
+ scan = make_shared_ptr<ValueRelation>(context, expression_rows, column_names);
614
+
615
+ } else {
616
+ scan = make_shared_ptr<ValueRelation>(context_wrapper, expression_rows, column_names);
617
+ }
595
618
} else {
596
619
throw NotImplementedException (" Unsupported type of read operator for substrait" );
597
620
}
0 commit comments