xueyumusic 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_r244925100
 
 

 ##########
 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
+      'f0.shiftLeft(20),
+      "f0.shiftLeft(20)",
+      "SHIFTLEFT(CAST(1 AS TINYINT), 20)",
+      "1048576"
 
 Review comment:
   Thank you verfy much for review and suggestions, @pnowojski , I treated 
`TINYINT` as `INT` before fowllowing the behavior of 
[Hive](https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-MathematicalFunctions).
 After looking into the pg9.6 behavior you pointed I think pg9.6's way is 
interpretable and reasonable. I updated the code according to your feedback, 
thanks~

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to