Skip to content

Commit 5296d28

Browse files
Fix use full column id and view at the same time. (#4414) (#4757)
Co-authored-by: Tony-Romanov <[email protected]>
1 parent 1ef008a commit 5296d28

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

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

+5-3
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
}
@@ -694,7 +695,8 @@ class TTableSource: public IRealSource {
694695
}
695696

696697
bool ShouldUseSourceAsColumn(const TString& source) const override {
697-
return source && source != GetLabel();
698+
const auto& label = GetLabel();
699+
return source && source != label && !(label.StartsWith(source) && label[source.size()] == ':');
698700
}
699701

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

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

+11
Original file line numberDiff line numberDiff line change
@@ -6456,4 +6456,15 @@ Y_UNIT_TEST_SUITE(TViewSyntaxTest) {
64566456

64576457
UNIT_ASSERT_VALUES_EQUAL(elementStat["Write!"], 1);
64586458
}
6459+
6460+
Y_UNIT_TEST(UseViewAndFullColumnId) {
6461+
NYql::TAstParseResult res = SqlToYql("USE plato; SELECT Input.x FROM Input VIEW uitzicht;");
6462+
UNIT_ASSERT(res.Root);
6463+
6464+
TWordCountHive elementStat = {{TString("SqlAccess"), 0}, {"SqlProjectItem", 0}, {"Read!", 0}};
6465+
VerifyProgram(res, elementStat);
6466+
UNIT_ASSERT_VALUES_EQUAL(0, elementStat["SqlAccess"]);
6467+
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["SqlProjectItem"]);
6468+
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Read!"]);
6469+
}
64596470
}

0 commit comments

Comments
 (0)