herunkang2018 commented on code in PR #3319:
URL: https://github.com/apache/calcite/pull/3319#discussion_r1290150636


##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -815,6 +815,39 @@ public static int bitLength(ByteString s) {
     return s.length() * 8;
   }
 
+  /** SQL BIT_GET(value, position) function. */
+  public static int bitGet(long value, int position) {
+    checkPosition(position, java.lang.Long.SIZE);
+    return (int) ((value >> position) & 1);
+  }
+
+  /** SQL BIT_GET(value, position) function. */
+  public static int bitGet(int value, int position) {
+    checkPosition(position, java.lang.Integer.SIZE);
+    return (value >> position) & 1;
+  }
+
+  /** SQL BIT_GET(value, position) function. */
+  public static int bitGet(short value, int position) {
+    checkPosition(position, java.lang.Short.SIZE);
+    return (value >> position) & 1;
+  }
+
+  /** SQL BIT_GET(value, position) function. */
+  public static int bitGet(byte value, int position) {
+    checkPosition(position, java.lang.Byte.SIZE);
+    return (value >> position) & 1;
+  }
+
+  private static void checkPosition(int position, int size) {
+    if (position < 0) {
+      throw RESOURCE.illegalNegativeBitGetPosition().ex();
+    }
+    if (size <= position) {
+      throw RESOURCE.illegalBitGetPositionExceedsLimit().ex();

Review Comment:
   Good advice, I will update it soon.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to