From 4bdccc1bce860f4b6d2044622cc6b1c063c86167 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 8 May 2024 21:31:56 +0200 Subject: [PATCH] Fix use full column id and view at the same time. --- ydb/library/yql/sql/v1/select.cpp | 8 +++++--- ydb/library/yql/sql/v1/sql_ut.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ydb/library/yql/sql/v1/select.cpp b/ydb/library/yql/sql/v1/select.cpp index 75f8f839f45b..f37b4167eb64 100644 --- a/ydb/library/yql/sql/v1/select.cpp +++ b/ydb/library/yql/sql/v1/select.cpp @@ -412,8 +412,9 @@ class IRealSource: public ISource { } TMaybe 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; } @@ -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 AddColumn(TContext& ctx, TColumnNode& column) override { diff --git a/ydb/library/yql/sql/v1/sql_ut.cpp b/ydb/library/yql/sql/v1/sql_ut.cpp index 0fb807d88c37..361808578b41 100644 --- a/ydb/library/yql/sql/v1/sql_ut.cpp +++ b/ydb/library/yql/sql/v1/sql_ut.cpp @@ -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!"]); + } }