You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2020/05/11 01:41:15 UTC

[GitHub] [calcite] hsyuan commented on a change in pull request #1878: [CALCITE-3782]Bitwise agg operator Bit_And, Bit_OR and Bit_XOR support binary and varbinary type

hsyuan commented on a change in pull request #1878:
URL: https://github.com/apache/calcite/pull/1878#discussion_r422737926



##########
File path: core/src/main/java/org/apache/calcite/runtime/BitwiseFunctions.java
##########
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.runtime;
+
+import org.apache.calcite.avatica.util.ByteString;
+
+import java.util.stream.IntStream;
+
+import static org.apache.calcite.util.Static.RESOURCE;
+
+/**
+ * A collection of functions used in Bitwise processing.
+ */
+public class BitwiseFunctions {
+
+  private BitwiseFunctions(){}
+
+  // &
+  /** Helper function for implementing <code>BIT_AND</code> applied to integer values */
+  public static long bitAnd(long b0, long b1) {
+    return b0 & b1;
+  }
+
+  /** Helper function for implementing <code>BIT_AND</code> applied to binary values */
+  public static ByteString bitAnd(ByteString b0, ByteString b1) {
+
+    return binaryOperator(b0, b1, BitwiseOperators.BITAND);
+  }
+
+  // |
+  /** Helper function for implementing <code>BIT_OR</code> applied to integer values */
+  public static long bitOr(long b0, long b1) {
+    return b0 | b1;
+  }
+
+  /** Helper function for implementing <code>BIT_OR</code> applied to binary values */
+  public static ByteString bitOr(ByteString b0, ByteString b1) {
+    return binaryOperator(b0, b1, BitwiseOperators.BITOR);
+  }
+
+  // ^
+  /** Helper function for implementing <code>BIT_XOR</code> applied to integer values */
+  public static long bitXor(long b0, long b1) {
+    return b0 ^ b1;
+  }
+
+  /** Helper function for implementing <code>BIT_XOR</code> applied to binary values */
+  public static ByteString bitXor(ByteString b0, ByteString b1) {
+
+    return binaryOperator(b0, b1, BitwiseOperators.BITXOR);
+  }
+
+  /**
+   * Util for bitwise function applied to two byteString values.
+   * @param b0 The first byteString value operand of bitwise function.
+   * @param b1 The second byteString value operand of bitwise function.
+   * @param operator BitWise Operator.
+   * @return
+   */
+  private static ByteString binaryOperator(
+      ByteString b0, ByteString b1, BitwiseOperators operator) {

Review comment:
       Can you cherry-pick this patch https://github.com/hsyuan/calcite/commit/af0d164eeaa615e489c58439afc3d109d98e7810 to your pull request?




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