Skip to content

Commit 21733f5

Browse files
committed
YQL-19264 relaxed check for assume order by
commit_hash:29ee6c53b63771357492cc2e4f7ceac15c5a86b1
1 parent fb73633 commit 21733f5

File tree

6 files changed

+48
-2
lines changed

6 files changed

+48
-2
lines changed

yql/essentials/sql/v1/builtin.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,10 @@ class TTableRow final : public INode {
19071907
return new TTableRow<Join>(Pos, ArgsCount);
19081908
}
19091909

1910+
bool IsTableRow() const final {
1911+
return true;
1912+
}
1913+
19101914
private:
19111915
const size_t ArgsCount;
19121916
TNodePtr Node;

yql/essentials/sql/v1/node.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ const TString* INode::GetColumnName() const {
172172
return nullptr;
173173
}
174174

175+
bool INode::IsPlainColumn() const {
176+
return GetColumnName() != nullptr;
177+
}
178+
179+
bool INode::IsTableRow() const {
180+
return false;
181+
}
182+
175183
void INode::AssumeColumn() {
176184
}
177185

@@ -466,6 +474,14 @@ const TString* IProxyNode::GetColumnName() const {
466474
return Inner->GetColumnName();
467475
}
468476

477+
bool IProxyNode::IsPlainColumn() const {
478+
return Inner->IsPlainColumn();
479+
}
480+
481+
bool IProxyNode::IsTableRow() const {
482+
return Inner->IsTableRow();
483+
}
484+
469485
void IProxyNode::AssumeColumn() {
470486
Inner->AssumeColumn();
471487
}
@@ -2480,6 +2496,18 @@ class TAccessNode: public INode {
24802496
return ColumnOnly ? Ids[0].Expr->GetColumnName() : nullptr;
24812497
}
24822498

2499+
bool IsPlainColumn() const override {
2500+
if (GetColumnName()) {
2501+
return true;
2502+
}
2503+
2504+
if (Ids[0].Expr->IsTableRow()) {
2505+
return true;
2506+
}
2507+
2508+
return false;
2509+
}
2510+
24832511
const TString* GetSourceName() const override {
24842512
return Ids[0].Expr->GetSourceName();
24852513
}

yql/essentials/sql/v1/node.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ namespace NSQLTranslationV1 {
168168
virtual TString GetOpName() const;
169169
virtual const TString* GetLiteral(const TString& type) const;
170170
virtual const TString* GetColumnName() const;
171+
virtual bool IsPlainColumn() const;
172+
virtual bool IsTableRow() const;
171173
virtual void AssumeColumn();
172174
virtual const TString* GetSourceName() const;
173175
virtual const TString* GetAtomContent() const;
@@ -299,6 +301,8 @@ namespace NSQLTranslationV1 {
299301
virtual TString GetOpName() const override;
300302
virtual const TString* GetLiteral(const TString &type) const override;
301303
virtual const TString* GetColumnName() const override;
304+
virtual bool IsPlainColumn() const override;
305+
virtual bool IsTableRow() const override;
302306
virtual void AssumeColumn() override;
303307
virtual const TString* GetSourceName() const override;
304308
virtual const TString* GetAtomContent() const override;

yql/essentials/sql/v1/select.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ TSourcePtr BuildInnerSource(TPosition pos, TNodePtr node, const TString& service
912912
}
913913

914914
static bool IsComparableExpression(TContext& ctx, const TNodePtr& expr, bool assume, const char* sqlConstruction) {
915-
if (assume && !expr->GetColumnName()) {
915+
if (assume && !expr->IsPlainColumn()) {
916916
ctx.Error(expr->GetPos()) << "Only column names can be used in " << sqlConstruction;
917917
return false;
918918
}
@@ -925,7 +925,7 @@ static bool IsComparableExpression(TContext& ctx, const TNodePtr& expr, bool ass
925925
ctx.Error(expr->GetPos()) << "Unable to " << sqlConstruction << " aggregated values";
926926
return false;
927927
}
928-
if (expr->GetColumnName()) {
928+
if (expr->IsPlainColumn()) {
929929
return true;
930930
}
931931
if (expr->GetOpName().empty()) {

yql/essentials/sql/v1/sql_ut.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,11 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
630630
UNIT_ASSERT(res.Root);
631631
}
632632

633+
Y_UNIT_TEST(SelectAssumeOrderByTableRowAccess) {
634+
NYql::TAstParseResult res = SqlToYql("$key = 'foo';select * from plato.Input assume order by TableRow().$key");
635+
UNIT_ASSERT(res.Root);
636+
}
637+
633638
Y_UNIT_TEST(SelectOrderByDuplicateLabels) {
634639
NYql::TAstParseResult res = SqlToYql("select a from plato.Input order by a, a");
635640
UNIT_ASSERT(res.Root);

yql/essentials/sql/v1/sql_ut_antlr4.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,11 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
630630
UNIT_ASSERT(res.Root);
631631
}
632632

633+
Y_UNIT_TEST(SelectAssumeOrderByTableRowAccess) {
634+
NYql::TAstParseResult res = SqlToYql("$key = 'foo';select * from plato.Input assume order by TableRow().$key");
635+
UNIT_ASSERT(res.Root);
636+
}
637+
633638
Y_UNIT_TEST(SelectOrderByDuplicateLabels) {
634639
NYql::TAstParseResult res = SqlToYql("select a from plato.Input order by a, a");
635640
UNIT_ASSERT(res.Root);

0 commit comments

Comments
 (0)