vlsi commented on a change in pull request #1795:
URL: https://github.com/apache/calcite/pull/1795#discussion_r492986042



##########
File path: core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
##########
@@ -1066,12 +1067,53 @@ private static RuntimeException notComparable(String 
op, Object b0,
         op, b1.getClass().toString()).ex();
   }
 
-  // &
-  /** Helper function for implementing <code>BIT_AND</code> */
+  // BITAND
+
+  /** SQL <code>BITAND</code> operator applied to long values */
   public static long bitAnd(long b0, long b1) {
     return b0 & b1;
   }
 
+  /** SQL <code>BITAND</code> operator applied to ByteString values */
+  public static ByteString bitAnd(ByteString b0, ByteString b1) {
+
+    if (b0.length() != b1.length()) {
+      throw RESOURCE.invalidInputForBitwiseBinaryValue().ex();
+    }
+    byte[] bytes0 = b0.getBytes();
+    byte[] bytes1 = b1.getBytes();
+    byte[] result = new byte[b0.length()];
+
+    IntStream.range(0, bytes0.length).forEach(i -> {

Review comment:
       Frankly speaking, a good old `for` loop would look better here, and it 
looks like streams add complexity without much benefits.

##########
File path: core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java
##########
@@ -410,6 +411,7 @@ public int size() {
   public static final SqlReturnTypeInference INTEGER_QUOTIENT_NULLABLE =
       chain(ARG0_INTERVAL_NULLABLE, LEAST_RESTRICTIVE);
 
+

Review comment:
       Please refrain from altering non-related lines

##########
File path: core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
##########
@@ -1066,12 +1067,53 @@ private static RuntimeException notComparable(String 
op, Object b0,
         op, b1.getClass().toString()).ex();
   }
 
-  // &
-  /** Helper function for implementing <code>BIT_AND</code> */
+  // BITAND
+
+  /** SQL <code>BITAND</code> operator applied to long values */
   public static long bitAnd(long b0, long b1) {
     return b0 & b1;
   }
 
+  /** SQL <code>BITAND</code> operator applied to ByteString values */
+  public static ByteString bitAnd(ByteString b0, ByteString b1) {
+
+    if (b0.length() != b1.length()) {
+      throw RESOURCE.invalidInputForBitwiseBinaryValue().ex();
+    }
+    byte[] bytes0 = b0.getBytes();
+    byte[] bytes1 = b1.getBytes();
+    byte[] result = new byte[b0.length()];
+
+    IntStream.range(0, bytes0.length).forEach(i -> {

Review comment:
       Frankly speaking, a good old `for` loop would look better here, and it 
looks like streams add complexity without much benefits.
   ```suggestion
       for (int i = 0; i < bytes0.length; i++) {
   ```

##########
File path: core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
##########
@@ -1066,12 +1067,53 @@ private static RuntimeException notComparable(String 
op, Object b0,
         op, b1.getClass().toString()).ex();
   }
 
-  // &
-  /** Helper function for implementing <code>BIT_AND</code> */
+  // BITAND
+
+  /** SQL <code>BITAND</code> operator applied to long values */
   public static long bitAnd(long b0, long b1) {
     return b0 & b1;
   }
 
+  /** SQL <code>BITAND</code> operator applied to ByteString values */
+  public static ByteString bitAnd(ByteString b0, ByteString b1) {
+
+    if (b0.length() != b1.length()) {
+      throw RESOURCE.invalidInputForBitwiseBinaryValue().ex();
+    }
+    byte[] bytes0 = b0.getBytes();
+    byte[] bytes1 = b1.getBytes();
+    byte[] result = new byte[b0.length()];

Review comment:
       Technically speaking, `b0.getBytes()` clones the byte array, so there's 
no need to allocate `new byte[...]` for the result. I believe `bytes0` would 
work just fine for the resulting array.




----------------------------------------------------------------
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.

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


Reply via email to