Skip to content

Commit

Permalink
Merge pull request #30 from project-tsurugi/wip/select-alias
Browse files Browse the repository at this point in the history
fix derived column rule (enable omit `AS`).
  • Loading branch information
ashigeru authored Oct 2, 2023
2 parents f8b65c5 + 29e11c2 commit 7249eaa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion parser/src/grammar/SqlParserRules.g4
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ selectSublist
;

derivedColumn
: expression (K_AS columnName)?
: expression (K_AS? columnName)?
;

tableExpression
Expand Down
11 changes: 11 additions & 0 deletions parser/test/ParserQueryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ TEST_F(ParserQueryTest, select_projection_alias) {
EXPECT_TRUE(equals(f.Name("C1"), c1v->name()));
}

TEST_F(ParserQueryTest, select_projection_alias_noas) {
auto select = parse_select("SELECT C1 x FROM TBL");
auto projection = dynamic_pointer_cast<ProjectionExpression>(select->source());
ASSERT_EQ(1U, projection->columns().size());

auto c1 = projection->columns()[0];
EXPECT_TRUE(equals(f.Name("x"), c1->alias()));
auto c1v = dynamic_pointer_cast<VariableReference>(c1->value());
EXPECT_TRUE(equals(f.Name("C1"), c1v->name()));
}

TEST_F(ParserQueryTest, select_projection_many) {
auto select = parse_select("SELECT 1, 2, 3, 4, 5 FROM TBL");
auto projection = dynamic_pointer_cast<ProjectionExpression>(select->source());
Expand Down

0 comments on commit 7249eaa

Please sign in to comment.