pnowojski commented on a change in pull request #6445: [FLINK-8302] [table] Add
SHIFT_LEFT and SHIFT_RIGHT
URL: https://github.com/apache/flink/pull/6445#discussion_r245056827
##########
File path:
flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/ScalarOperatorsTest.scala
##########
@@ -74,6 +74,238 @@ class ScalarOperatorsTest extends ScalarOperatorsTestBase {
"true")
}
+ @Test
+ def testShiftLeft(): Unit = {
+ testAllApis(
+ 3.shiftLeft(3),
+ "3.shiftLeft(3)",
+ "SHIFTLEFT(3,3)",
+ "24"
+ )
+
+ testAllApis(
+ 2147483647.shiftLeft(-2147483648),
+ "2147483647.shiftLeft(-2147483648)",
+ "SHIFTLEFT(2147483647,-2147483648)",
+ "2147483647"
+ )
+
+ testAllApis(
+ -2147483648.shiftLeft(2147483647),
+ "-2147483648.shiftLeft(2147483647)",
+ "SHIFTLEFT(-2147483648,2147483647)",
+ "0"
+ )
+
+ testAllApis(
+ 9223372036854775807L.shiftLeft(-2147483648),
+ "9223372036854775807L.shiftLeft(-2147483648)",
+ "SHIFTLEFT(9223372036854775807,-2147483648)",
+ "9223372036854775807"
+ )
+
+ testAllApis(
+ 'f3.shiftLeft(5),
+ "f3.shiftLeft(5)",
+ "SHIFTLEFT(f3,5)",
+ "32"
+ )
+
+ testAllApis(
+ 1.shiftLeft(Null(Types.INT)),
+ "1.shiftLeft(Null(INT))",
+ "SHIFTLEFT(1, CAST(NULL AS INT))",
+ "null"
+ )
+
+ testAllApis( // test tinyint
Review comment:
regarding the tinyint, smallint, int and bigint tests. I think we need the
following tests that show the quirky nature of java bit shifts:
```
select cast(1 as tinyint) << 9, cast(1 as tinyint) << 17;
select cast(1 as smallint) << 17, cast(1 as smallint) << 33;
select 1 << 17, 1 << 33,
select cast(1 as bigint) << 33, cast(1 as bigint) << 65;
```
expected results:
```
0, 2
0, 2
131072, 2
8589934592, 2
```
Bonus points for anyone that understands those results 😜 For me the most
confusing part is why `select cast(1 as smallint) << 17` returns `0`, while
`select 1 << 33` returns 2...
Also we need the same test cases (shifting by 9, 17, 33 and 65) for both
versions of right shifts, but instead of right shifting `1`, right shift min
values (`Byte.MIN_VALUE`, `Short.MIN_VALUE`, ...) (and results should also be
different)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services