From 5c9829a9860e7bad90329e6c6259cf953f6f6f22 Mon Sep 17 00:00:00 2001 From: Tony-Romanov <150126326+Tony-Romanov@users.noreply.github.com> Date: Thu, 9 May 2024 11:26:41 +0200 Subject: [PATCH] Fix use full column id and view at the same time. (#4414) --- 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 c32307cd6469..1dd8713be08e 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; } @@ -694,7 +695,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 ee7420fcef41..69cffe43f8e0 100644 --- a/ydb/library/yql/sql/v1/sql_ut.cpp +++ b/ydb/library/yql/sql/v1/sql_ut.cpp @@ -6456,4 +6456,15 @@ Y_UNIT_TEST_SUITE(TViewSyntaxTest) { UNIT_ASSERT_VALUES_EQUAL(elementStat["Write!"], 1); } + + 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!"]); + } }