Skip to content

Commit

Permalink
Fix use full column id and view at the same time. (#4414)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony-Romanov authored May 9, 2024
1 parent 0e415cd commit 49abee7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ydb/library/yql/sql/v1/select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,9 @@ class IRealSource: public ISource {
}

TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
auto& label = *column.GetSourceName();
if (!label.empty() && label != GetLabel()) {
const auto& label = *column.GetSourceName();
const auto& source = GetLabel();
if (!label.empty() && label != source && !(source.StartsWith(label) && source[label.size()] == ':')) {
if (column.IsReliable()) {
ctx.Error(column.GetPos()) << "Unknown correlation name: " << label;
}
Expand Down Expand Up @@ -703,7 +704,8 @@ class TTableSource: public IRealSource {
}

bool ShouldUseSourceAsColumn(const TString& source) const override {
return source && source != GetLabel();
const auto& label = GetLabel();
return source && source != label && !(label.StartsWith(source) && label[source.size()] == ':');
}

TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {
Expand Down
11 changes: 11 additions & 0 deletions ydb/library/yql/sql/v1/sql_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6709,4 +6709,15 @@ Y_UNIT_TEST_SUITE(TViewSyntaxTest) {

UNIT_ASSERT_VALUES_EQUAL(1, elementStat["userschema"]);
}

Y_UNIT_TEST(UseViewAndFullColumnId) {
NYql::TAstParseResult res = SqlToYql("USE plato; SELECT Input.x FROM Input VIEW uitzicht;");
UNIT_ASSERT(res.Root);

TWordCountHive elementStat = {{TString("SqlAccess"), 0}, {"SqlProjectItem", 0}, {"Read!", 0}};
VerifyProgram(res, elementStat);
UNIT_ASSERT_VALUES_EQUAL(0, elementStat["SqlAccess"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["SqlProjectItem"]);
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Read!"]);
}
}

0 comments on commit 49abee7

Please sign in to comment.