Skip to content

Commit 0ee8cb7

Browse files
authored
YDB FQ: introduce new TGenTable expr node (#14228)
1 parent 877eef3 commit 0ee8cb7

File tree

6 files changed

+56
-15
lines changed

6 files changed

+56
-15
lines changed

ydb/library/yql/providers/generic/expr_nodes/yql_generic_expr_nodes.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,23 @@
2424
{"Index": 1, "Name": "DataSource", "Type": "TGenDataSource"}
2525
]
2626
},
27+
{
28+
"Name": "TGenTable",
29+
"Base": "TCallable",
30+
"Match": {"Type": "Callable", "Name": "GenTable"},
31+
"Children": [
32+
{"Index": 0, "Name": "Name", "Type": "TCoAtom"},
33+
{"Index": 1, "Name": "Splits", "Type": "TExprBase"}
34+
]
35+
},
2736
{
2837
"Name": "TGenReadTable",
2938
"Base": "TCallable",
3039
"Match": {"Type": "Callable", "Name": "GenReadTable!"},
3140
"Children": [
3241
{"Index": 0, "Name": "World", "Type": "TExprBase"},
3342
{"Index": 1, "Name": "DataSource", "Type": "TGenDataSource"},
34-
{"Index": 2, "Name": "Table", "Type": "TCoAtom"},
43+
{"Index": 2, "Name": "Table", "Type": "TGenTable"},
3544
{"Index": 3, "Name": "Columns", "Type": "TExprBase"},
3645
{"Index": 4, "Name": "FilterPredicate", "Type": "TCoLambda"}
3746
]

ydb/library/yql/providers/generic/provider/yql_generic_datasource.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ namespace NYql {
126126
auto cluster = dataSource.Cast().Cluster();
127127
tableNameBuilder << cluster.Value() << ".";
128128
}
129-
tableNameBuilder << '`' << maybeTable.Cast().Value() << '`';
129+
tableNameBuilder << '`' << maybeTable.Cast().Name().Value() << '`';
130130
inputs.push_back(
131131
TPinInfo(maybeRead.DataSource().Raw(), nullptr, maybeTable.Cast().Raw(), tableNameBuilder, false));
132132
return 1;

ydb/library/yql/providers/generic/provider/yql_generic_datasource_type_ann.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace NYql {
2727
{
2828
using TSelf = TGenericDataSourceTypeAnnotationTransformer;
2929
AddHandler({TCoConfigure::CallableName()}, Hndl(&TSelf::HandleConfig));
30+
AddHandler({TGenTable::CallableName()}, Hndl(&TSelf::HandleTable));
3031
AddHandler({TGenReadTable::CallableName()}, Hndl(&TSelf::HandleReadTable));
3132
AddHandler({TGenSourceSettings::CallableName()}, Hndl(&TSelf::HandleSourceSettings));
3233
}
@@ -48,6 +49,19 @@ namespace NYql {
4849
return TStatus::Ok;
4950
}
5051

52+
TStatus HandleTable(const TExprNode::TPtr& input, TExprContext& ctx) {
53+
if (!EnsureArgsCount(*input, 2, ctx)) {
54+
return TStatus::Error;
55+
}
56+
57+
if (!EnsureAtom(*input->Child(TGenTable::idx_Name), ctx)) {
58+
return TStatus::Error;
59+
}
60+
61+
input->SetTypeAnn(ctx.MakeType<TUnitExprType>());
62+
return TStatus::Ok;
63+
}
64+
5165
TStatus HandleSourceSettings(const TExprNode::TPtr& input, TExprContext& ctx) {
5266
if (!EnsureArgsCount(*input, 6, ctx)) {
5367
return TStatus::Error;
@@ -131,7 +145,7 @@ namespace NYql {
131145
return TStatus::Error;
132146
}
133147

134-
if (!EnsureAtom(*input->Child(TGenReadTable::idx_Table), ctx)) {
148+
if (!EnsureCallable(*input->Child(TGenReadTable::idx_Table), ctx)) {
135149
return TStatus::Error;
136150
}
137151

@@ -157,9 +171,21 @@ namespace NYql {
157171
}
158172
}
159173

174+
// Determine cluster name
160175
TString clusterName{input->Child(TGenReadTable::idx_DataSource)->Child(1)->Content()};
161-
TString tableName{input->Child(TGenReadTable::idx_Table)->Content()};
162176

177+
// Determine table name
178+
const auto tableNode = input->Child(TGenReadTable::idx_Table);
179+
if (!TGenTable::Match(tableNode)) {
180+
ctx.AddError(TIssue(ctx.GetPosition(tableNode->Pos()),
181+
TStringBuilder() << "Expected " << TGenTable::CallableName()));
182+
return TStatus::Error;
183+
}
184+
185+
TGenTable table(tableNode);
186+
const auto tableName = table.Name().StringValue();
187+
188+
// Extract table metadata
163189
auto [tableMeta, issue] = State_->GetTable(clusterName, tableName, ctx.GetPosition(input->Pos()));
164190
if (issue.has_value()) {
165191
ctx.AddError(issue.value());

ydb/library/yql/providers/generic/provider/yql_generic_dq_integration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ namespace NYql {
9191
.Input<TGenSourceSettings>()
9292
.World(genReadTable.World())
9393
.Cluster(genReadTable.DataSource().Cluster())
94-
.Table(genReadTable.Table())
94+
.Table(genReadTable.Table().Name())
9595
.Token<TCoSecureParam>()
9696
.Name().Build(token)
9797
.Build()

ydb/library/yql/providers/generic/provider/yql_generic_load_meta.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ namespace NYql {
2525
using namespace NKikimr;
2626
using namespace NKikimr::NMiniKQL;
2727

28-
struct TGenericTableDescription {
29-
using TPtr = std::shared_ptr<TGenericTableDescription>;
30-
31-
NYql::TGenericDataSourceInstance DataSourceInstance;
32-
std::optional<NConnector::NApi::TDescribeTableResponse> Response;
33-
};
3428

3529
class TGenericLoadTableMetadataTransformer: public TGraphTransformerBase {
30+
struct TTableDescription {
31+
using TPtr = std::shared_ptr<TTableDescription>;
32+
33+
NYql::TGenericDataSourceInstance DataSourceInstance;
34+
std::optional<NConnector::NApi::TDescribeTableResponse> Response;
35+
};
36+
3637
using TMapType =
37-
std::unordered_map<TGenericState::TTableAddress, TGenericTableDescription::TPtr, THash<TGenericState::TTableAddress>>;
38+
std::unordered_map<TGenericState::TTableAddress, TTableDescription::TPtr, THash<TGenericState::TTableAddress>>;
3839

3940
public:
4041
TGenericLoadTableMetadataTransformer(TGenericState::TPtr state)
@@ -101,7 +102,7 @@ namespace NYql {
101102
handles.emplace_back(promise.GetFuture());
102103

103104
// preserve data source instance for the further usage
104-
auto emplaceIt = Results_.emplace(std::make_pair(item, std::make_shared<TGenericTableDescription>()));
105+
auto emplaceIt = Results_.emplace(std::make_pair(item, std::make_shared<TTableDescription>()));
105106
auto desc = emplaceIt.first->second;
106107
desc->DataSourceInstance = request.data_source_instance();
107108

@@ -171,17 +172,22 @@ namespace NYql {
171172
auto row = Build<TCoArgument>(ctx, read.Pos())
172173
.Name("row")
173174
.Done();
175+
174176
auto emptyPredicate = Build<TCoLambda>(ctx, read.Pos())
175177
.Args({row})
176178
.Body<TCoBool>()
177179
.Literal().Build("true")
178180
.Build()
179181
.Done().Ptr();
180182

183+
auto table = Build<TGenTable>(ctx, read.Pos())
184+
.Name().Value(tableName).Build()
185+
.Splits<TCoVoid>().Build().Done();
186+
181187
ins.first->second = Build<TGenReadTable>(ctx, read.Pos())
182188
.World(read.World())
183189
.DataSource(read.DataSource())
184-
.Table().Value(tableName).Build()
190+
.Table(table)
185191
.Columns<TCoVoid>().Build()
186192
.FilterPredicate(emptyPredicate)
187193
.Done().Ptr();

ydb/library/yql/providers/generic/provider/yql_generic_physical_opt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ namespace NYql {
7272
// Get table metadata
7373
const auto [tableMeta, issue] = State_->GetTable(
7474
read.DataSource().Cluster().Value(),
75-
read.Table().Value(),
75+
read.Table().Name().Value(),
7676
ctx.GetPosition(node.Pos()));
7777
if (issue.has_value()) {
7878
ctx.AddError(issue.value());

0 commit comments

Comments
 (0)