Skip to content

Commit 1ef3674

Browse files
Tony-RomanovMrLolthe1st
authored andcommitted
Fix use full column id and view at the same time. (ydb-platform#4414)
1 parent 79e949f commit 1ef3674

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

ydb/library/yql/sql/v1/select.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,9 @@ class IRealSource: public ISource {
412412
}
413413

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

705706
bool ShouldUseSourceAsColumn(const TString& source) const override {
706-
return source && source != GetLabel();
707+
const auto& label = GetLabel();
708+
return source && source != label && !(label.StartsWith(source) && label[source.size()] == ':');
707709
}
708710

709711
TMaybe<bool> AddColumn(TContext& ctx, TColumnNode& column) override {

ydb/library/yql/sql/v1/sql_ut.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6709,4 +6709,15 @@ Y_UNIT_TEST_SUITE(TViewSyntaxTest) {
67096709

67106710
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["userschema"]);
67116711
}
6712+
6713+
Y_UNIT_TEST(UseViewAndFullColumnId) {
6714+
NYql::TAstParseResult res = SqlToYql("USE plato; SELECT Input.x FROM Input VIEW uitzicht;");
6715+
UNIT_ASSERT(res.Root);
6716+
6717+
TWordCountHive elementStat = {{TString("SqlAccess"), 0}, {"SqlProjectItem", 0}, {"Read!", 0}};
6718+
VerifyProgram(res, elementStat);
6719+
UNIT_ASSERT_VALUES_EQUAL(0, elementStat["SqlAccess"]);
6720+
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["SqlProjectItem"]);
6721+
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Read!"]);
6722+
}
67126723
}

0 commit comments

Comments
 (0)