IMPALA-5591: set should handle negative values The parser didn't account for the possibility of negative numeric literals.
Testing: Added a test that sets a negative value. Query tests send the whole "set" statement to the backend for execution so exercise the parser. Ran core tests. Change-Id: I5c415dbed6ba1122919be75f5811444d88ee03b4 Reviewed-on: http://gerrit.cloudera.org:8080/7316 Reviewed-by: Tim Armstrong <[email protected]> Tested-by: Impala Public Jenkins Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/6311f39c Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/6311f39c Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/6311f39c Branch: refs/heads/master Commit: 6311f39cd4a6ce71dc60547e4482e38383bc3b60 Parents: 7e4f235 Author: Tim Armstrong <[email protected]> Authored: Tue Jun 27 16:32:14 2017 -0700 Committer: Impala Public Jenkins <[email protected]> Committed: Thu Jun 29 05:26:56 2017 +0000 ---------------------------------------------------------------------- fe/src/main/cup/sql-parser.cup | 12 +++++++++++- .../functional-query/queries/QueryTest/set.test | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/6311f39c/fe/src/main/cup/sql-parser.cup ---------------------------------------------------------------------- diff --git a/fe/src/main/cup/sql-parser.cup b/fe/src/main/cup/sql-parser.cup index d3180ab..0eaa68e 100644 --- a/fe/src/main/cup/sql-parser.cup +++ b/fe/src/main/cup/sql-parser.cup @@ -356,6 +356,7 @@ nonterminal AnalyticWindow opt_window_clause; nonterminal AnalyticWindow.Type window_type; nonterminal AnalyticWindow.Boundary window_boundary; nonterminal LiteralExpr literal; +nonterminal NumericLiteral numeric_literal; nonterminal CaseExpr case_expr; nonterminal ArrayList<CaseWhenClause> case_when_clause_list; nonterminal FunctionParams function_params; @@ -2287,6 +2288,10 @@ select_clause ::= set_stmt ::= KW_SET ident_or_default:key EQUAL literal:l {: RESULT = new SetStmt(key, l.getStringValue()); :} + | KW_SET ident_or_default:key EQUAL SUBTRACT numeric_literal:l + {: + l.swapSign(); + RESULT = new SetStmt(key, l.getStringValue()); :} | KW_SET ident_or_default:key EQUAL ident_or_default:ident {: RESULT = new SetStmt(key, ident); :} | KW_SET @@ -2859,11 +2864,16 @@ timestamp_arithmetic_expr ::= :} ; -literal ::= +numeric_literal ::= INTEGER_LITERAL:l {: RESULT = new NumericLiteral(l); :} | DECIMAL_LITERAL:l {: RESULT = new NumericLiteral(l); :} + ; + +literal ::= + numeric_literal:l + {: RESULT = l; :} | STRING_LITERAL:l {: RESULT = new StringLiteral(l); :} | KW_TRUE http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/6311f39c/testdata/workloads/functional-query/queries/QueryTest/set.test ---------------------------------------------------------------------- diff --git a/testdata/workloads/functional-query/queries/QueryTest/set.test b/testdata/workloads/functional-query/queries/QueryTest/set.test index 1dd1396..12b8df6 100644 --- a/testdata/workloads/functional-query/queries/QueryTest/set.test +++ b/testdata/workloads/functional-query/queries/QueryTest/set.test @@ -256,3 +256,7 @@ explain select count(distinct double_col) from functional.alltypesagg; '01:AGGREGATE' '00:SCAN HDFS [functional.alltypesagg]' ==== +---- QUERY +# IMPALA-5591: This shouldn't throw an error. +set scratch_limit=-1; +====
