JackieTien97 commented on code in PR #15972:
URL: https://github.com/apache/iotdb/pull/15972#discussion_r2218162520


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java:
##########
@@ -570,6 +570,47 @@ && isIntegerNumber(argumentTypes.get(2)))) {
                 + " must have at least two arguments, and all type must be the 
same.");
       }
       return argumentTypes.get(0);
+    } else if 
(TableBuiltinScalarFunction.BIT_COUNT.getFunctionName().equalsIgnoreCase(functionName)
+        || 
TableBuiltinScalarFunction.BITWISE_AND.getFunctionName().equalsIgnoreCase(functionName)
+        || 
TableBuiltinScalarFunction.BITWISE_OR.getFunctionName().equalsIgnoreCase(functionName)
+        || TableBuiltinScalarFunction.BITWISE_XOR
+            .getFunctionName()
+            .equalsIgnoreCase(functionName)) {
+      if (argumentTypes.size() != 2
+          || !(isIntegerNumber(argumentTypes.get(0)) && 
isIntegerNumber(argumentTypes.get(1)))) {
+        throw new SemanticException(
+            "Scalar function "
+                + functionName.toLowerCase(Locale.ENGLISH)
+                + " only accepts two arguments and they must be Int32 or Int64 
data type.");
+      }
+      return INT64;

Review Comment:
   return type should be INT32 if both are INT32



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/relational/ColumnTransformerBuilder.java:
##########
@@ -999,6 +1003,57 @@ private ColumnTransformer getFunctionColumnTransformer(
       Type returnType = columnTransformers.get(0).getType();
       return AbstractGreatestLeastColumnTransformer.getLeastColumnTransformer(
           returnType, columnTransformers);
+    } else if (TableBuiltinScalarFunction.BIT_COUNT
+        .getFunctionName()
+        .equalsIgnoreCase(functionName)) {
+      ColumnTransformer first = this.process(children.get(0), context);
+      if (isLongLiteral(children.get(1))) {
+        final long bits = ((LongLiteral) children.get(1)).getParsedValue();
+        return new BitCountColumnTransformer(INT64, first, bits);
+      } else {
+        return new BitCount2ColumnTransformer(INT64, first, 
this.process(children.get(1), context));
+      }
+    } else if (TableBuiltinScalarFunction.BITWISE_AND
+            .getFunctionName()
+            .equalsIgnoreCase(functionName)
+        || 
TableBuiltinScalarFunction.BITWISE_NOT.getFunctionName().equalsIgnoreCase(functionName)
+        || 
TableBuiltinScalarFunction.BITWISE_OR.getFunctionName().equalsIgnoreCase(functionName)
+        || TableBuiltinScalarFunction.BITWISE_XOR

Review Comment:
   implement different ColumnTransformer for each function, you can extract 
common logics in the super class, and only leave different process logic in 
each sub class.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/relational/ColumnTransformerBuilder.java:
##########
@@ -999,6 +1003,57 @@ private ColumnTransformer getFunctionColumnTransformer(
       Type returnType = columnTransformers.get(0).getType();
       return AbstractGreatestLeastColumnTransformer.getLeastColumnTransformer(
           returnType, columnTransformers);
+    } else if (TableBuiltinScalarFunction.BIT_COUNT
+        .getFunctionName()
+        .equalsIgnoreCase(functionName)) {
+      ColumnTransformer first = this.process(children.get(0), context);
+      if (isLongLiteral(children.get(1))) {
+        final long bits = ((LongLiteral) children.get(1)).getParsedValue();
+        return new BitCountColumnTransformer(INT64, first, bits);
+      } else {
+        return new BitCount2ColumnTransformer(INT64, first, 
this.process(children.get(1), context));
+      }
+    } else if (TableBuiltinScalarFunction.BITWISE_AND
+            .getFunctionName()
+            .equalsIgnoreCase(functionName)
+        || 
TableBuiltinScalarFunction.BITWISE_NOT.getFunctionName().equalsIgnoreCase(functionName)
+        || 
TableBuiltinScalarFunction.BITWISE_OR.getFunctionName().equalsIgnoreCase(functionName)
+        || TableBuiltinScalarFunction.BITWISE_XOR
+            .getFunctionName()
+            .equalsIgnoreCase(functionName)) {
+      ColumnTransformer first = this.process(children.get(0), context);
+      if (children.size() == 1) {
+        return new BitwiseColumnTransformer(INT64, first);
+      } else if (children.size() == 2) {
+        if (isLongLiteral(children.get(1))) {
+          final long rightValue = ((LongLiteral) 
children.get(1)).getParsedValue();
+          return new BitwiseColumnTransformer(INT64, first, rightValue, 
functionName);
+        } else {
+          return new Bitwise2ColumnTransformer(
+              INT64, first, this.process(children.get(1), context), 
functionName);
+        }
+      }
+    } else if (TableBuiltinScalarFunction.BITWISE_LEFT_SHIFT
+            .getFunctionName()
+            .equalsIgnoreCase(functionName)
+        || TableBuiltinScalarFunction.BITWISE_RIGHT_SHIFT
+            .getFunctionName()
+            .equalsIgnoreCase(functionName)
+        || TableBuiltinScalarFunction.BITWISE_RIGHT_SHIFT_ARITHMETIC
+            .getFunctionName()
+            .equalsIgnoreCase(functionName)) {

Review Comment:
   implement different ColumnTransformer for each function, you can extract 
common logics in the super class, and only leave different process logic in 
each sub class.



##########
integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBBitwiseFunctionTableIT.java:
##########
@@ -0,0 +1,285 @@
+/*
+ * 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.iotdb.relational.it.query.old.builtinfunction.scalar;
+
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.TableClusterIT;
+import org.apache.iotdb.itbase.category.TableLocalStandaloneIT;
+import org.apache.iotdb.itbase.env.BaseEnv;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.sql.*;
+
+import static org.apache.iotdb.db.it.utils.TestUtils.assertTableTestFail;
+import static org.apache.iotdb.db.it.utils.TestUtils.tableResultSetEqualTest;
+
+@RunWith(IoTDBTestRunner.class)
+@Category({TableLocalStandaloneIT.class, TableClusterIT.class})
+public class IoTDBBitwiseFunctionTableIT {

Review Comment:
   IT 中增加对于其他数据类型的错误校验



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