diff --git a/sql/api/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBaseParser.g4 b/sql/api/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBaseParser.g4 index f0c0adb881212..4552c17e0cf14 100644 --- a/sql/api/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBaseParser.g4 +++ b/sql/api/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBaseParser.g4 @@ -986,11 +986,11 @@ valueExpression | operator=(MINUS | PLUS | TILDE) valueExpression #arithmeticUnary | left=valueExpression operator=(ASTERISK | SLASH | PERCENT | DIV) right=valueExpression #arithmeticBinary | left=valueExpression operator=(PLUS | MINUS | CONCAT_PIPE) right=valueExpression #arithmeticBinary + | left=valueExpression shiftOperator right=valueExpression #shiftExpression | left=valueExpression operator=AMPERSAND right=valueExpression #arithmeticBinary | left=valueExpression operator=HAT right=valueExpression #arithmeticBinary | left=valueExpression operator=PIPE right=valueExpression #arithmeticBinary | left=valueExpression comparisonOperator right=valueExpression #comparison - | left=valueExpression shiftOperator right=valueExpression #shiftExpression ; shiftOperator diff --git a/sql/core/src/test/resources/sql-tests/analyzer-results/bitwise.sql.out b/sql/core/src/test/resources/sql-tests/analyzer-results/bitwise.sql.out index fee226c0c3411..1267a984565ad 100644 --- a/sql/core/src/test/resources/sql-tests/analyzer-results/bitwise.sql.out +++ b/sql/core/src/test/resources/sql-tests/analyzer-results/bitwise.sql.out @@ -418,3 +418,24 @@ select cast(null as map>), 20181117 >> 2 -- !query analysis Project [cast(null as map>) AS NULL#x, (20181117 >> 2) AS (20181117 >> 2)#x] +- OneRowRelation + + +-- !query +select 1 << 1 + 2 as plus_over_shift +-- !query analysis +Project [(1 << (1 + 2)) AS plus_over_shift#x] ++- OneRowRelation + + +-- !query +select 2 >> 1 << 1 as left_to_right +-- !query analysis +Project [((2 >> 1) << 1) AS left_to_right#x] ++- OneRowRelation + + +-- !query +select 1 & 2 >> 1 as shift_over_ampersand +-- !query analysis +Project [(1 & (2 >> 1)) AS shift_over_ampersand#x] ++- OneRowRelation diff --git a/sql/core/src/test/resources/sql-tests/inputs/bitwise.sql b/sql/core/src/test/resources/sql-tests/inputs/bitwise.sql index 5823b22ef6453..e080fdd32a4aa 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/bitwise.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/bitwise.sql @@ -86,4 +86,8 @@ SELECT 20181117 <<< 2; SELECT 20181117 >>>> 2; select cast(null as array>), 20181117 >> 2; select cast(null as array>), 20181117 >>> 2; -select cast(null as map>), 20181117 >> 2; \ No newline at end of file +select cast(null as map>), 20181117 >> 2; + +select 1 << 1 + 2 as plus_over_shift; -- if correct, the result is 8. otherwise, 4 +select 2 >> 1 << 1 as left_to_right; -- if correct, the result is 2. otherwise, 0 +select 1 & 2 >> 1 as shift_over_ampersand; -- if correct, the result is 1. otherwise, 0 diff --git a/sql/core/src/test/resources/sql-tests/results/bitwise.sql.out b/sql/core/src/test/resources/sql-tests/results/bitwise.sql.out index a7ebaea293bf9..7233b0d0ae499 100644 --- a/sql/core/src/test/resources/sql-tests/results/bitwise.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/bitwise.sql.out @@ -450,3 +450,27 @@ select cast(null as map>), 20181117 >> 2 struct>,(20181117 >> 2):int> -- !query output NULL 5045279 + + +-- !query +select 1 << 1 + 2 as plus_over_shift +-- !query schema +struct +-- !query output +8 + + +-- !query +select 2 >> 1 << 1 as left_to_right +-- !query schema +struct +-- !query output +2 + + +-- !query +select 1 & 2 >> 1 as shift_over_ampersand +-- !query schema +struct +-- !query output +1