This is an automated email from the ASF dual-hosted git repository.

jackietien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new a3b24dace4e Implement builtin bitwise scalar functions in TableModel
a3b24dace4e is described below

commit a3b24dace4ef01e43249c5f7ab23683035d17fe3
Author: waynextz <[email protected]>
AuthorDate: Tue Jul 29 11:11:11 2025 +0800

    Implement builtin bitwise scalar functions in TableModel
---
 .../scalar/IoTDBBitwiseFunctionTableIT.java        | 437 +++++++++++++++++++++
 .../relational/ColumnTransformerBuilder.java       |  96 +++++
 .../relational/metadata/TableMetadataImpl.java     |  41 ++
 .../scalar/AbstractBitwise2ColumnTransformer.java  |  71 ++++
 .../scalar/AbstractBitwiseColumnTransformer.java   |  62 +++
 .../unary/scalar/BitCount2ColumnTransformer.java   |  76 ++++
 .../unary/scalar/BitCountColumnTransformer.java    |  68 ++++
 .../unary/scalar/BitwiseAnd2ColumnTransformer.java |  44 +++
 .../unary/scalar/BitwiseAndColumnTransformer.java  |  42 ++
 .../scalar/BitwiseLeftShift2ColumnTransformer.java |  60 +++
 .../scalar/BitwiseLeftShiftColumnTransformer.java  |  47 +++
 .../unary/scalar/BitwiseNotColumnTransformer.java  |  63 +++
 .../unary/scalar/BitwiseOr2ColumnTransformer.java  |  44 +++
 .../unary/scalar/BitwiseOrColumnTransformer.java   |  42 ++
 .../BitwiseRightShift2ColumnTransformer.java       |  60 +++
 ...wiseRightShiftArithmetic2ColumnTransformer.java |  65 +++
 ...twiseRightShiftArithmeticColumnTransformer.java |  49 +++
 .../scalar/BitwiseRightShiftColumnTransformer.java |  47 +++
 .../unary/scalar/BitwiseXor2ColumnTransformer.java |  44 +++
 .../unary/scalar/BitwiseXorColumnTransformer.java  |  42 ++
 .../transformation/dag/util/BitwiseUtils.java      | 210 ++++++++++
 .../transformation/dag/util/BitwiseUtilsTest.java  | 131 ++++++
 .../relational/TableBuiltinScalarFunction.java     |   8 +
 23 files changed, 1849 insertions(+)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBBitwiseFunctionTableIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBBitwiseFunctionTableIT.java
new file mode 100644
index 00000000000..b25d7d897ff
--- /dev/null
+++ 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBBitwiseFunctionTableIT.java
@@ -0,0 +1,437 @@
+/*
+ * 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 {
+  private static final String DATABASE_NAME = "db";
+
+  private static final String[] SQLs =
+      new String[] {
+        "CREATE DATABASE " + DATABASE_NAME,
+        "use " + DATABASE_NAME,
+        // bit_count_normal
+        "create table bit_count_normal_table(device_id STRING TAG, s1 TEXT 
FIELD, s2 INT32 FIELD, s3 INT64 FIELD, s4 FLOAT FIELD)",
+        "INSERT INTO bit_count_normal_table(Time,device_id,s1,s2,s3,s4) 
values(1, 'd1', 'a', 9, 64, 1)",
+        "INSERT INTO bit_count_normal_table(Time,device_id,s1,s2,s3,s4) 
values(2, 'd1', 'a', 9, 8, 1)",
+        "INSERT INTO bit_count_normal_table(Time,device_id,s1,s2,s3,s4) 
values(3, 'd1', 'a', -7, 64, 1)",
+        "INSERT INTO bit_count_normal_table(Time,device_id,s1) values(4, 'd1', 
'a')",
+        // bit_count_error
+        "create table bit_count_error_table(device_id STRING TAG, s1 TEXT 
FIELD, s2 INT32 FIELD, s3 INT64 FIELD, s4 FLOAT FIELD)",
+        "INSERT INTO bit_count_error_table(Time,device_id,s1,s2,s3,s4) 
values(1, 'd1', 'a', 9, 64, 1)",
+        "INSERT INTO bit_count_error_table(Time,device_id,s1,s2,s3,s4) 
values(2, 'd1', 'a', 9, 2, 1)",
+        "INSERT INTO bit_count_error_table(Time,device_id,s1) values(3, 'd1', 
'a')",
+        // bitwise_and
+        "create table bitwise_and_table(device_id STRING TAG, s1 TEXT FIELD, 
s2 INT32 FIELD, s3 INT64 FIELD, s4 FLOAT FIELD)",
+        "INSERT INTO bitwise_and_table(Time,device_id,s1,s2,s3,s4) values(1, 
'd1', 'a', 19, 25, 1)",
+        "INSERT INTO bitwise_and_table(Time,device_id,s1) values(2, 'd1', 
'a')",
+        // bitwise_not
+        "create table bitwise_not_table(device_id STRING TAG, s1 TEXT FIELD, 
s2 INT32 FIELD, s3 INT64 FIELD, s4 FLOAT FIELD)",
+        "INSERT INTO bitwise_not_table(Time,device_id,s1,s2,s3,s4) values(1, 
'd1', 'a', -12, 25, 1)",
+        "INSERT INTO bitwise_not_table(Time,device_id,s1,s2,s3,s4) values(2, 
'd1', 'a', 19, 25, 1)",
+        "INSERT INTO bitwise_not_table(Time,device_id,s1,s2,s3,s4) values(3, 
'd1', 'a', 25, 25, 1)",
+        "INSERT INTO bitwise_not_table(Time,device_id,s1) values(4, 'd1', 
'a')",
+        // bitwise_or
+        "create table bitwise_or_table(device_id STRING TAG, s1 TEXT FIELD, s2 
INT32 FIELD, s3 INT64 FIELD, s4 FLOAT FIELD)",
+        "INSERT INTO bitwise_or_table(Time,device_id,s1,s2,s3,s4) values(1, 
'd1', 'a', 19, 25, 1)",
+        "INSERT INTO bitwise_or_table(Time,device_id,s1) values(2, 'd1', 'a')",
+        // bitwise_xor
+        "create table bitwise_xor_table(device_id STRING TAG, s1 TEXT FIELD, 
s2 INT32 FIELD, s3 INT64 FIELD, s4 FLOAT FIELD)",
+        "INSERT INTO bitwise_xor_table(Time,device_id,s1,s2,s3,s4) values(1, 
'd1', 'a', 19, 25, 1)",
+        "INSERT INTO bitwise_xor_table(Time,device_id,s1) values(2, 'd1', 
'a')",
+        // bitwise_left_shift
+        "create table bitwise_left_shift_table(device_id STRING TAG, s1 TEXT 
FIELD, s2 INT32 FIELD, s3 INT64 FIELD, s4 FLOAT FIELD)",
+        "INSERT INTO bitwise_left_shift_table(Time,device_id,s1,s2,s3,s4) 
values(1, 'd1', 'a', 1, 2, 1)",
+        "INSERT INTO bitwise_left_shift_table(Time,device_id,s1,s2,s3,s4) 
values(2, 'd1', 'a', 5, 2, 1)",
+        "INSERT INTO bitwise_left_shift_table(Time,device_id,s1,s2,s3,s4) 
values(3, 'd1', 'a', 20, 0, 1)",
+        "INSERT INTO bitwise_left_shift_table(Time,device_id,s1,s2,s3,s4) 
values(4, 'd1', 'a', 42, 0, 1)",
+        "INSERT INTO bitwise_left_shift_table(Time,device_id,s1,s2,s3,s4) 
values(5, 'd1', 'a', 0, 1, 1)",
+        "INSERT INTO bitwise_left_shift_table(Time,device_id,s1,s2,s3,s4) 
values(6, 'd1', 'a', 0, 2, 1)",
+        "INSERT INTO bitwise_left_shift_table(Time,device_id,s1) values(7, 
'd1', 'a')",
+        // bitwise_right_shift
+        "create table bitwise_right_shift_table(device_id STRING TAG, s1 TEXT 
FIELD, s2 INT32 FIELD, s3 INT64 FIELD, s4 FLOAT FIELD)",
+        "INSERT INTO bitwise_right_shift_table(Time,device_id,s1,s2,s3,s4) 
values(1, 'd1', 'a', 8, 3, 1)",
+        "INSERT INTO bitwise_right_shift_table(Time,device_id,s1,s2,s3,s4) 
values(2, 'd1', 'a', 9, 1, 1)",
+        "INSERT INTO bitwise_right_shift_table(Time,device_id,s1,s2,s3,s4) 
values(3, 'd1', 'a', 20, 0, 1)",
+        "INSERT INTO bitwise_right_shift_table(Time,device_id,s1,s2,s3,s4) 
values(4, 'd1', 'a', 42, 0, 1)",
+        "INSERT INTO bitwise_right_shift_table(Time,device_id,s1,s2,s3,s4) 
values(5, 'd1', 'a', 12, 64, 1)",
+        "INSERT INTO bitwise_right_shift_table(Time,device_id,s1,s2,s3,s4) 
values(6, 'd1', 'a', -45, 64, 1)",
+        "INSERT INTO bitwise_right_shift_table(Time,device_id,s1,s2,s3,s4) 
values(7, 'd1', 'a', 0, 1, 1)",
+        "INSERT INTO bitwise_right_shift_table(Time,device_id,s1,s2,s3,s4) 
values(8, 'd1', 'a', 0, 2, 1)",
+        "INSERT INTO bitwise_right_shift_table(Time,device_id,s1) values(9, 
'd1', 'a')",
+        // bitwise_right_shift_arithmetic
+        "create table bitwise_right_shift_arithmetic_table(device_id STRING 
TAG, s1 TEXT FIELD, s2 INT32 FIELD, s3 INT64 FIELD, s4 FLOAT FIELD)",
+        "INSERT INTO 
bitwise_right_shift_arithmetic_table(Time,device_id,s1,s2,s3,s4) values(1, 
'd1', 'a', 12, 64, 1)",
+        "INSERT INTO 
bitwise_right_shift_arithmetic_table(Time,device_id,s1,s2,s3,s4) values(2, 
'd1', 'a', -45, 64, 1)",
+        "INSERT INTO bitwise_right_shift_arithmetic_table(Time,device_id,s1) 
values(3, 'd1', 'a')",
+      };
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    EnvFactory.getEnv().initClusterEnvironment();
+    insertData();
+  }
+
+  protected static void insertData() {
+    try (Connection connection = 
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
+        Statement statement = connection.createStatement()) {
+
+      for (String sql : SQLs) {
+        statement.execute(sql);
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanClusterEnvironment();
+  }
+
+  @Test
+  public void bitCountTestNormal() {
+    String[] expectedHeader = new String[] {"time", "s2", "s3", "_col3", 
"_col4", "_col5"};
+    String[] expectedAns =
+        new String[] {
+          "1970-01-01T00:00:00.001Z,9,64,2,2,2,",
+          "1970-01-01T00:00:00.002Z,9,8,2,2,2,",
+          "1970-01-01T00:00:00.003Z,-7,64,2,62,62,",
+          "1970-01-01T00:00:00.004Z,null,null,2,null,null,"
+        };
+    tableResultSetEqualTest(
+        "select time,s2,s3,bit_count(9,64),bit_count(s2,64),bit_count(s2,s3) 
from bit_count_normal_table",
+        expectedHeader,
+        expectedAns,
+        DATABASE_NAME);
+  }
+
+  @Test
+  public void bitCountTestError1() {
+    assertTableTestFail(
+        EnvFactory.getEnv(),
+        "select time,s2,s3,bit_count(9,64),bit_count(s2,64),bit_count(s2,s3) 
from bit_count_error_table",
+        "Argument exception, the scalar function num must be representable 
with the bits specified. 9 cannot be represented with 2 bits.",
+        "root",
+        "root",
+        DATABASE_NAME);
+  }
+
+  @Test
+  public void bitCountTestError2() {
+    assertTableTestFail(
+        EnvFactory.getEnv(),
+        "select time,s2,s3,bit_count(9,1),bit_count(s2,1),bit_count(s2,s3) 
from bit_count_error_table",
+        "Argument exception, the scalar function bit_count bits must be 
between 2 and 64.",
+        "root",
+        "root",
+        DATABASE_NAME);
+  }
+
+  @Test
+  public void bitCountTestWithNonInteger() {
+    assertTableTestFail(
+        EnvFactory.getEnv(),
+        "select time, bit_count(s4) from bit_count_error_table",
+        "701: Scalar function bit_count only accepts two arguments and they 
must be Int32 or Int64 data type.",
+        "root",
+        "root",
+        DATABASE_NAME);
+
+    assertTableTestFail(
+        EnvFactory.getEnv(),
+        "select time, bit_count(s1,s4) from bit_count_error_table",
+        "701: Scalar function bit_count only accepts two arguments and they 
must be Int32 or Int64 data type.",
+        "root",
+        "root",
+        DATABASE_NAME);
+  }
+
+  @Test
+  public void bitwiseAndTestNormal() {
+    String[] expectedHeader = new String[] {"time", "s2", "s3", "_col3", 
"_col4", "_col5"};
+    String[] expectedAns =
+        new String[] {
+          "1970-01-01T00:00:00.001Z,19,25,17,17,17,",
+          "1970-01-01T00:00:00.002Z,null,null,17,null,null,"
+        };
+    tableResultSetEqualTest(
+        "select 
time,s2,s3,bitwise_and(19,25),bitwise_and(s2,25),bitwise_and(s2,s3) from 
bitwise_and_table",
+        expectedHeader,
+        expectedAns,
+        DATABASE_NAME);
+  }
+
+  @Test
+  public void bitwiseAndTestWithNonInteger() {
+    assertTableTestFail(
+        EnvFactory.getEnv(),
+        "select time, bitwise_and(s4) from bitwise_and_table",
+        "701: Scalar function bitwise_and only accepts two arguments and they 
must be Int32 or Int64 data type.",
+        "root",
+        "root",
+        DATABASE_NAME);
+
+    assertTableTestFail(
+        EnvFactory.getEnv(),
+        "select time, bitwise_and(s1,s4) from bitwise_and_table",
+        "701: Scalar function bitwise_and only accepts two arguments and they 
must be Int32 or Int64 data type.",
+        "root",
+        "root",
+        DATABASE_NAME);
+  }
+
+  @Test
+  public void bitwiseNotTestNormal() {
+    String[] expectedHeader = new String[] {"time", "s2", "s3", "_col3", 
"_col4"};
+    String[] expectedAns =
+        new String[] {
+          "1970-01-01T00:00:00.001Z,-12,25,11,11,",
+          "1970-01-01T00:00:00.002Z,19,25,11,-20,",
+          "1970-01-01T00:00:00.003Z,25,25,11,-26,",
+          "1970-01-01T00:00:00.004Z,null,null,11,null,"
+        };
+    tableResultSetEqualTest(
+        "select time,s2,s3,bitwise_not(-12),bitwise_not(s2) from 
bitwise_not_table",
+        expectedHeader,
+        expectedAns,
+        DATABASE_NAME);
+  }
+
+  @Test
+  public void bitwiseNotTestWithNonInteger() {
+    assertTableTestFail(
+        EnvFactory.getEnv(),
+        "select time, bitwise_not(s4) from bitwise_not_table",
+        "701: Scalar function bitwise_not only accepts one argument and it 
must be Int32 or Int64 data type.",
+        "root",
+        "root",
+        DATABASE_NAME);
+
+    assertTableTestFail(
+        EnvFactory.getEnv(),
+        "select time, bitwise_not(s1,s4) from bitwise_not_table",
+        "701: Scalar function bitwise_not only accepts one argument and it 
must be Int32 or Int64 data type.",
+        "root",
+        "root",
+        DATABASE_NAME);
+  }
+
+  @Test
+  public void bitwiseOrTestNormal() {
+    String[] expectedHeader = new String[] {"time", "s2", "s3", "_col3", 
"_col4", "_col5"};
+    String[] expectedAns =
+        new String[] {
+          "1970-01-01T00:00:00.001Z,19,25,27,27,27,",
+          "1970-01-01T00:00:00.002Z,null,null,27,null,null,"
+        };
+    tableResultSetEqualTest(
+        "select 
time,s2,s3,bitwise_or(19,25),bitwise_or(s2,25),bitwise_or(s2,s3) from 
bitwise_or_table",
+        expectedHeader,
+        expectedAns,
+        DATABASE_NAME);
+  }
+
+  @Test
+  public void bitwiseOrTestWithNonInteger() {
+    assertTableTestFail(
+        EnvFactory.getEnv(),
+        "select time, bitwise_or(s4) from bitwise_or_table",
+        "701: Scalar function bitwise_or only accepts two arguments and they 
must be Int32 or Int64 data type.",
+        "root",
+        "root",
+        DATABASE_NAME);
+
+    assertTableTestFail(
+        EnvFactory.getEnv(),
+        "select time, bitwise_or(s1,s4) from bitwise_or_table",
+        "701: Scalar function bitwise_or only accepts two arguments and they 
must be Int32 or Int64 data type.",
+        "root",
+        "root",
+        DATABASE_NAME);
+  }
+
+  @Test
+  public void bitwiseXorTestNormal() {
+    String[] expectedHeader = new String[] {"time", "s2", "s3", "_col3", 
"_col4", "_col5"};
+    String[] expectedAns =
+        new String[] {
+          "1970-01-01T00:00:00.001Z,19,25,10,10,10,",
+          "1970-01-01T00:00:00.002Z,null,null,10,null,null,"
+        };
+    tableResultSetEqualTest(
+        "select 
time,s2,s3,bitwise_xor(19,25),bitwise_xor(s2,25),bitwise_xor(s2,s3) from 
bitwise_xor_table",
+        expectedHeader,
+        expectedAns,
+        DATABASE_NAME);
+  }
+
+  @Test
+  public void bitwiseXorTestWithNonInteger() {
+    assertTableTestFail(
+        EnvFactory.getEnv(),
+        "select time, bitwise_xor(s4) from bitwise_xor_table",
+        "701: Scalar function bitwise_xor only accepts two arguments and they 
must be Int32 or Int64 data type.",
+        "root",
+        "root",
+        DATABASE_NAME);
+
+    assertTableTestFail(
+        EnvFactory.getEnv(),
+        "select time, bitwise_xor(s1,s4) from bitwise_xor_table",
+        "701: Scalar function bitwise_xor only accepts two arguments and they 
must be Int32 or Int64 data type.",
+        "root",
+        "root",
+        DATABASE_NAME);
+  }
+
+  @Test
+  public void bitwiseLeftShiftTestNormal() {
+    String[] expectedHeader = new String[] {"time", "s2", "s3", "_col3", 
"_col4"};
+    String[] expectedAns =
+        new String[] {
+          "1970-01-01T00:00:00.001Z,1,2,4,4,",
+          "1970-01-01T00:00:00.002Z,5,2,4,20,",
+          "1970-01-01T00:00:00.003Z,20,0,4,20,",
+          "1970-01-01T00:00:00.004Z,42,0,4,42,",
+          "1970-01-01T00:00:00.005Z,0,1,4,0,",
+          "1970-01-01T00:00:00.006Z,0,2,4,0,",
+          "1970-01-01T00:00:00.007Z,null,null,4,null,"
+        };
+    tableResultSetEqualTest(
+        "select time,s2,s3,bitwise_left_shift(1,2),bitwise_left_shift(s2,s3) 
from bitwise_left_shift_table",
+        expectedHeader,
+        expectedAns,
+        DATABASE_NAME);
+  }
+
+  @Test
+  public void bitwiseLeftShiftTestWithNonInteger() {
+    assertTableTestFail(
+        EnvFactory.getEnv(),
+        "select time, bitwise_left_shift(s4) from bitwise_left_shift_table",
+        "701: Scalar function bitwise_left_shift only accepts two arguments 
and they must be Int32 or Int64 data type.",
+        "root",
+        "root",
+        DATABASE_NAME);
+
+    assertTableTestFail(
+        EnvFactory.getEnv(),
+        "select time, bitwise_left_shift(s1,s4) from bitwise_left_shift_table",
+        "701: Scalar function bitwise_left_shift only accepts two arguments 
and they must be Int32 or Int64 data type.",
+        "root",
+        "root",
+        DATABASE_NAME);
+  }
+
+  @Test
+  public void bitwiseRightShiftTestNormal() {
+    String[] expectedHeader = new String[] {"time", "s2", "s3", "_col3", 
"_col4"};
+    String[] expectedAns =
+        new String[] {
+          "1970-01-01T00:00:00.001Z,8,3,1,1,",
+          "1970-01-01T00:00:00.002Z,9,1,1,4,",
+          "1970-01-01T00:00:00.003Z,20,0,1,20,",
+          "1970-01-01T00:00:00.004Z,42,0,1,42,",
+          "1970-01-01T00:00:00.005Z,12,64,1,0,",
+          "1970-01-01T00:00:00.006Z,-45,64,1,0,",
+          "1970-01-01T00:00:00.007Z,0,1,1,0,",
+          "1970-01-01T00:00:00.008Z,0,2,1,0,",
+          "1970-01-01T00:00:00.009Z,null,null,1,null,"
+        };
+    tableResultSetEqualTest(
+        "select time,s2,s3,bitwise_right_shift(8,3),bitwise_right_shift(s2,s3) 
from bitwise_right_shift_table",
+        expectedHeader,
+        expectedAns,
+        DATABASE_NAME);
+  }
+
+  @Test
+  public void bitwiseRightShiftTestWithNonInteger() {
+    assertTableTestFail(
+        EnvFactory.getEnv(),
+        "select time, bitwise_right_shift(s4) from bitwise_right_shift_table",
+        "701: Scalar function bitwise_right_shift only accepts two arguments 
and they must be Int32 or Int64 data type.",
+        "root",
+        "root",
+        DATABASE_NAME);
+
+    assertTableTestFail(
+        EnvFactory.getEnv(),
+        "select time, bitwise_right_shift(s1,s4) from 
bitwise_right_shift_table",
+        "701: Scalar function bitwise_right_shift only accepts two arguments 
and they must be Int32 or Int64 data type.",
+        "root",
+        "root",
+        DATABASE_NAME);
+  }
+
+  @Test
+  public void bitwiseRightShiftArithmeticTestNormal() {
+    String[] expectedHeader = new String[] {"time", "s2", "s3", "_col3", 
"_col4"};
+    String[] expectedAns =
+        new String[] {
+          "1970-01-01T00:00:00.001Z,12,64,0,0,",
+          "1970-01-01T00:00:00.002Z,-45,64,0,-1,",
+          "1970-01-01T00:00:00.003Z,null,null,0,null,"
+        };
+    tableResultSetEqualTest(
+        "select 
time,s2,s3,bitwise_right_shift_arithmetic(19,25),bitwise_right_shift_arithmetic(s2,s3)
 from bitwise_right_shift_arithmetic_table",
+        expectedHeader,
+        expectedAns,
+        DATABASE_NAME);
+  }
+
+  @Test
+  public void bitwiseRightShiftArithmeticTestWithNonInteger() {
+    assertTableTestFail(
+        EnvFactory.getEnv(),
+        "select time, bitwise_right_shift_arithmetic(s4) from 
bitwise_right_shift_arithmetic_table",
+        "701: Scalar function bitwise_right_shift_arithmetic only accepts two 
arguments and they must be Int32 or Int64 data type.",
+        "root",
+        "root",
+        DATABASE_NAME);
+
+    assertTableTestFail(
+        EnvFactory.getEnv(),
+        "select time, bitwise_right_shift_arithmetic(s1,s4) from 
bitwise_right_shift_arithmetic_table",
+        "701: Scalar function bitwise_right_shift_arithmetic only accepts two 
arguments and they must be Int32 or Int64 data type.",
+        "root",
+        "root",
+        DATABASE_NAME);
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/relational/ColumnTransformerBuilder.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/relational/ColumnTransformerBuilder.java
index 0e915ab258c..455172993dc 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/relational/ColumnTransformerBuilder.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/relational/ColumnTransformerBuilder.java
@@ -109,6 +109,21 @@ import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.Ab
 import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.AcosColumnTransformer;
 import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.AsinColumnTransformer;
 import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.AtanColumnTransformer;
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.BitCount2ColumnTransformer;
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.BitCountColumnTransformer;
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.BitwiseAnd2ColumnTransformer;
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.BitwiseAndColumnTransformer;
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.BitwiseLeftShift2ColumnTransformer;
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.BitwiseLeftShiftColumnTransformer;
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.BitwiseNotColumnTransformer;
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.BitwiseOr2ColumnTransformer;
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.BitwiseOrColumnTransformer;
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.BitwiseRightShift2ColumnTransformer;
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.BitwiseRightShiftArithmetic2ColumnTransformer;
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.BitwiseRightShiftArithmeticColumnTransformer;
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.BitwiseRightShiftColumnTransformer;
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.BitwiseXor2ColumnTransformer;
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.BitwiseXorColumnTransformer;
 import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.CastFunctionColumnTransformer;
 import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.CeilColumnTransformer;
 import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar.Concat2ColumnTransformer;
@@ -1022,6 +1037,87 @@ public class ColumnTransformerBuilder
       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)) {
+      ColumnTransformer first = this.process(children.get(0), context);
+      if (isLongLiteral(children.get(1))) {
+        final long rightValue = ((LongLiteral) 
children.get(1)).getParsedValue();
+        return new BitwiseAndColumnTransformer(INT64, first, rightValue);
+      } else {
+        return new BitwiseAnd2ColumnTransformer(
+            INT64, first, this.process(children.get(1), context));
+      }
+    } else if (TableBuiltinScalarFunction.BITWISE_NOT
+        .getFunctionName()
+        .equalsIgnoreCase(functionName)) {
+      ColumnTransformer first = this.process(children.get(0), context);
+      return new BitwiseNotColumnTransformer(INT64, first);
+    } else if (TableBuiltinScalarFunction.BITWISE_OR
+        .getFunctionName()
+        .equalsIgnoreCase(functionName)) {
+      ColumnTransformer first = this.process(children.get(0), context);
+      if (isLongLiteral(children.get(1))) {
+        final long rightValue = ((LongLiteral) 
children.get(1)).getParsedValue();
+        return new BitwiseOrColumnTransformer(INT64, first, rightValue);
+      } else {
+        return new BitwiseOr2ColumnTransformer(
+            INT64, first, this.process(children.get(1), context));
+      }
+    } else if (TableBuiltinScalarFunction.BITWISE_XOR
+        .getFunctionName()
+        .equalsIgnoreCase(functionName)) {
+      ColumnTransformer first = this.process(children.get(0), context);
+      if (isLongLiteral(children.get(1))) {
+        final long rightValue = ((LongLiteral) 
children.get(1)).getParsedValue();
+        return new BitwiseXorColumnTransformer(INT64, first, rightValue);
+      } else {
+        return new BitwiseXor2ColumnTransformer(
+            INT64, first, this.process(children.get(1), context));
+      }
+    } else if (TableBuiltinScalarFunction.BITWISE_LEFT_SHIFT
+        .getFunctionName()
+        .equalsIgnoreCase(functionName)) {
+      ColumnTransformer first = this.process(children.get(0), context);
+      if (isLongLiteral(children.get(1))) {
+        final long rightValue = ((LongLiteral) 
children.get(1)).getParsedValue();
+        return new BitwiseLeftShiftColumnTransformer(first.getType(), first, 
rightValue);
+      } else {
+        return new BitwiseLeftShift2ColumnTransformer(
+            first.getType(), first, this.process(children.get(1), context));
+      }
+    } else if (TableBuiltinScalarFunction.BITWISE_RIGHT_SHIFT
+        .getFunctionName()
+        .equalsIgnoreCase(functionName)) {
+      ColumnTransformer first = this.process(children.get(0), context);
+      if (isLongLiteral(children.get(1))) {
+        final long rightValue = ((LongLiteral) 
children.get(1)).getParsedValue();
+        return new BitwiseRightShiftColumnTransformer(first.getType(), first, 
rightValue);
+      } else {
+        return new BitwiseRightShift2ColumnTransformer(
+            first.getType(), first, this.process(children.get(1), context));
+      }
+    } else if (TableBuiltinScalarFunction.BITWISE_RIGHT_SHIFT_ARITHMETIC
+        .getFunctionName()
+        .equalsIgnoreCase(functionName)) {
+      ColumnTransformer first = this.process(children.get(0), context);
+      if (isLongLiteral(children.get(1))) {
+        final long rightValue = ((LongLiteral) 
children.get(1)).getParsedValue();
+        return new 
BitwiseRightShiftArithmeticColumnTransformer(first.getType(), first, 
rightValue);
+      } else {
+        return new BitwiseRightShiftArithmetic2ColumnTransformer(
+            first.getType(), first, this.process(children.get(1), context));
+      }
     } else {
       // user defined function
       if (TableUDFUtils.isScalarFunction(functionName)) {
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java
index 8934de172e9..4417bbccf7b 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java
@@ -570,6 +570,47 @@ public class TableMetadataImpl implements Metadata {
                 + " 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(
+            String.format(
+                "Scalar function %s only accepts two arguments and they must 
be Int32 or Int64 data type.",
+                functionName));
+      }
+      return INT64;
+    } else if (TableBuiltinScalarFunction.BITWISE_NOT
+        .getFunctionName()
+        .equalsIgnoreCase(functionName)) {
+      if (argumentTypes.size() != 1 || !isIntegerNumber(argumentTypes.get(0))) 
{
+        throw new SemanticException(
+            String.format(
+                "Scalar function %s only accepts one argument and it must be 
Int32 or Int64 data type.",
+                functionName));
+      }
+      return INT64;
+    } else if (TableBuiltinScalarFunction.BITWISE_LEFT_SHIFT
+            .getFunctionName()
+            .equalsIgnoreCase(functionName)
+        || TableBuiltinScalarFunction.BITWISE_RIGHT_SHIFT
+            .getFunctionName()
+            .equalsIgnoreCase(functionName)
+        || TableBuiltinScalarFunction.BITWISE_RIGHT_SHIFT_ARITHMETIC
+            .getFunctionName()
+            .equalsIgnoreCase(functionName)) {
+      if (argumentTypes.size() != 2
+          || !(isIntegerNumber(argumentTypes.get(0)) && 
isIntegerNumber(argumentTypes.get(1)))) {
+        throw new SemanticException(
+            String.format(
+                "Scalar function %s only accepts two arguments and they must 
be Int32 or Int64 data type.",
+                functionName));
+      }
+      return argumentTypes.get(0);
     }
 
     // builtin aggregation function
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/AbstractBitwise2ColumnTransformer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/AbstractBitwise2ColumnTransformer.java
new file mode 100644
index 00000000000..dfc7a233351
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/AbstractBitwise2ColumnTransformer.java
@@ -0,0 +1,71 @@
+/*
+ * 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.db.queryengine.transformation.dag.column.unary.scalar;
+
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.ColumnTransformer;
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.binary.BinaryColumnTransformer;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.read.common.type.Type;
+
+public abstract class AbstractBitwise2ColumnTransformer extends 
BinaryColumnTransformer {
+
+  public AbstractBitwise2ColumnTransformer(
+      Type returnType, ColumnTransformer leftTransformer, ColumnTransformer 
rightTransformer) {
+    super(returnType, leftTransformer, rightTransformer);
+  }
+
+  @Override
+  protected void checkType() {
+    // do nothing
+  }
+
+  @Override
+  protected void doTransform(
+      Column leftColumn, Column rightColumn, ColumnBuilder builder, int 
positionCount) {
+    for (int i = 0; i < positionCount; i++) {
+      if (!leftColumn.isNull(i) && !rightColumn.isNull(i)) {
+        transform(leftColumn, rightColumn, builder, i);
+      } else {
+        builder.appendNull();
+      }
+    }
+  }
+
+  @Override
+  protected void doTransform(
+      Column leftColumn,
+      Column rightColumn,
+      ColumnBuilder builder,
+      int positionCount,
+      boolean[] selection) {
+    for (int i = 0; i < positionCount; i++) {
+      if (selection[i] && !leftColumn.isNull(i) && !rightColumn.isNull(i)) {
+        transform(leftColumn, rightColumn, builder, i);
+      } else {
+        builder.appendNull();
+      }
+    }
+  }
+
+  protected abstract void transform(
+      Column leftColumn, Column rightColumn, ColumnBuilder columnBuilder, int 
i);
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/AbstractBitwiseColumnTransformer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/AbstractBitwiseColumnTransformer.java
new file mode 100644
index 00000000000..c4d1cd8f317
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/AbstractBitwiseColumnTransformer.java
@@ -0,0 +1,62 @@
+/*
+ * 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.db.queryengine.transformation.dag.column.unary.scalar;
+
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.ColumnTransformer;
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.UnaryColumnTransformer;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.read.common.type.Type;
+
+public abstract class AbstractBitwiseColumnTransformer extends 
UnaryColumnTransformer {
+
+  protected final long rightValue;
+
+  public AbstractBitwiseColumnTransformer(
+      Type returnType, ColumnTransformer childColumnTransformer, long 
rightValue) {
+    super(returnType, childColumnTransformer);
+    this.rightValue = rightValue;
+  }
+
+  @Override
+  protected void doTransform(Column column, ColumnBuilder columnBuilder) {
+    for (int i = 0, n = column.getPositionCount(); i < n; i++) {
+      if (!column.isNull(i)) {
+        transform(column, columnBuilder, i);
+      } else {
+        columnBuilder.appendNull();
+      }
+    }
+  }
+
+  @Override
+  protected void doTransform(Column column, ColumnBuilder columnBuilder, 
boolean[] selection) {
+    for (int i = 0, n = column.getPositionCount(); i < n; i++) {
+      if (selection[i] && !column.isNull(i)) {
+        transform(column, columnBuilder, i);
+      } else {
+        columnBuilder.appendNull();
+      }
+    }
+  }
+
+  protected abstract void transform(Column column, ColumnBuilder 
columnBuilder, int i);
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitCount2ColumnTransformer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitCount2ColumnTransformer.java
new file mode 100644
index 00000000000..04ffea29c63
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitCount2ColumnTransformer.java
@@ -0,0 +1,76 @@
+/*
+ * 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.db.queryengine.transformation.dag.column.unary.scalar;
+
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.ColumnTransformer;
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.binary.BinaryColumnTransformer;
+import org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.read.common.type.Type;
+
+public class BitCount2ColumnTransformer extends BinaryColumnTransformer {
+  public BitCount2ColumnTransformer(
+      Type returnType, ColumnTransformer leftTransformer, ColumnTransformer 
rightTransformer) {
+    super(returnType, leftTransformer, rightTransformer);
+  }
+
+  @Override
+  protected void checkType() {
+    // do nothing
+  }
+
+  @Override
+  protected void doTransform(
+      Column leftColumn, Column rightColumn, ColumnBuilder builder, int 
positionCount) {
+    for (int i = 0; i < positionCount; i++) {
+      if (!leftColumn.isNull(i) && !rightColumn.isNull(i)) {
+        transform(leftColumn, rightColumn, builder, i);
+      } else {
+        builder.appendNull();
+      }
+    }
+  }
+
+  @Override
+  protected void doTransform(
+      Column leftColumn,
+      Column rightColumn,
+      ColumnBuilder builder,
+      int positionCount,
+      boolean[] selection) {
+    for (int i = 0; i < positionCount; i++) {
+      if (selection[i] && !leftColumn.isNull(i) && !rightColumn.isNull(i)) {
+        transform(leftColumn, rightColumn, builder, i);
+      } else {
+        builder.appendNull();
+      }
+    }
+  }
+
+  private void transform(
+      Column leftColumn, Column rightColumn, ColumnBuilder columnBuilder, int 
i) {
+    long num = leftColumn.getLong(i);
+    long bits = rightColumn.getLong(i);
+    long currentValue = BitwiseUtils.bitCountTransform(num, bits);
+    columnBuilder.writeLong(currentValue);
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitCountColumnTransformer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitCountColumnTransformer.java
new file mode 100644
index 00000000000..87a928ef16b
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitCountColumnTransformer.java
@@ -0,0 +1,68 @@
+/*
+ * 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.db.queryengine.transformation.dag.column.unary.scalar;
+
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.ColumnTransformer;
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.UnaryColumnTransformer;
+import org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.read.common.type.Type;
+
+public class BitCountColumnTransformer extends UnaryColumnTransformer {
+
+  private final long bits;
+
+  public BitCountColumnTransformer(
+      Type returnType, ColumnTransformer childColumnTransformer, long bits) {
+    super(returnType, childColumnTransformer);
+    this.bits = bits;
+    BitwiseUtils.bitCountCheckBits(bits);
+  }
+
+  @Override
+  protected void doTransform(Column column, ColumnBuilder columnBuilder) {
+    for (int i = 0, n = column.getPositionCount(); i < n; i++) {
+      if (!column.isNull(i)) {
+        transform(column, columnBuilder, i);
+      } else {
+        columnBuilder.appendNull();
+      }
+    }
+  }
+
+  @Override
+  protected void doTransform(Column column, ColumnBuilder columnBuilder, 
boolean[] selection) {
+    for (int i = 0, n = column.getPositionCount(); i < n; i++) {
+      if (selection[i] && !column.isNull(i)) {
+        transform(column, columnBuilder, i);
+      } else {
+        columnBuilder.appendNull();
+      }
+    }
+  }
+
+  private void transform(Column column, ColumnBuilder columnBuilder, int i) {
+    long num = column.getLong(i);
+    long currentValue = BitwiseUtils.bitCountTransform(num, bits);
+    columnBuilder.writeLong(currentValue);
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseAnd2ColumnTransformer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseAnd2ColumnTransformer.java
new file mode 100644
index 00000000000..3be14f412b3
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseAnd2ColumnTransformer.java
@@ -0,0 +1,44 @@
+/*
+ * 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.db.queryengine.transformation.dag.column.unary.scalar;
+
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.ColumnTransformer;
+import org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.read.common.type.Type;
+
+public class BitwiseAnd2ColumnTransformer extends 
AbstractBitwise2ColumnTransformer {
+
+  public BitwiseAnd2ColumnTransformer(
+      Type returnType, ColumnTransformer leftTransformer, ColumnTransformer 
rightTransformer) {
+    super(returnType, leftTransformer, rightTransformer);
+  }
+
+  @Override
+  protected void transform(
+      Column leftColumn, Column rightColumn, ColumnBuilder columnBuilder, int 
i) {
+    long leftValue = leftColumn.getLong(i);
+    long rightValue = rightColumn.getLong(i);
+    long currentValue = BitwiseUtils.bitwiseAndTransform(leftValue, 
rightValue);
+    columnBuilder.writeLong(currentValue);
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseAndColumnTransformer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseAndColumnTransformer.java
new file mode 100644
index 00000000000..57676824bb9
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseAndColumnTransformer.java
@@ -0,0 +1,42 @@
+/*
+ * 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.db.queryengine.transformation.dag.column.unary.scalar;
+
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.ColumnTransformer;
+import org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.read.common.type.Type;
+
+public class BitwiseAndColumnTransformer extends 
AbstractBitwiseColumnTransformer {
+
+  public BitwiseAndColumnTransformer(
+      Type returnType, ColumnTransformer childColumnTransformer, long 
rightValue) {
+    super(returnType, childColumnTransformer, rightValue);
+  }
+
+  @Override
+  protected void transform(Column column, ColumnBuilder columnBuilder, int i) {
+    long leftValue = column.getLong(i);
+    long currentValue = BitwiseUtils.bitwiseAndTransform(leftValue, 
rightValue);
+    columnBuilder.writeLong(currentValue);
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseLeftShift2ColumnTransformer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseLeftShift2ColumnTransformer.java
new file mode 100644
index 00000000000..8c42d788878
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseLeftShift2ColumnTransformer.java
@@ -0,0 +1,60 @@
+/*
+ * 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.db.queryengine.transformation.dag.column.unary.scalar;
+
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.ColumnTransformer;
+import org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.type.Type;
+
+public class BitwiseLeftShift2ColumnTransformer extends 
AbstractBitwise2ColumnTransformer {
+
+  public BitwiseLeftShift2ColumnTransformer(
+      Type returnType, ColumnTransformer leftTransformer, ColumnTransformer 
rightTransformer) {
+    super(returnType, leftTransformer, rightTransformer);
+  }
+
+  @Override
+  protected void transform(
+      Column leftColumn, Column rightColumn, ColumnBuilder columnBuilder, int 
i) {
+    if (TSDataType.INT32.equals(leftColumn.getDataType())) {
+      int leftValue = leftColumn.getInt(i);
+      if (TSDataType.INT32.equals(rightColumn.getDataType())) {
+        int rightValue = rightColumn.getInt(i);
+        
columnBuilder.writeInt(BitwiseUtils.bitwiseLeftShiftTransform(leftValue, 
rightValue));
+      } else if (TSDataType.INT64.equals(rightColumn.getDataType())) {
+        long rightValue = rightColumn.getLong(i);
+        
columnBuilder.writeInt(BitwiseUtils.bitwiseLeftShiftTransform(leftValue, 
rightValue));
+      }
+    } else if (TSDataType.INT64.equals(leftColumn.getDataType())) {
+      long leftValue = leftColumn.getLong(i);
+      if (TSDataType.INT32.equals(rightColumn.getDataType())) {
+        int rightValue = rightColumn.getInt(i);
+        
columnBuilder.writeLong(BitwiseUtils.bitwiseLeftShiftTransform(leftValue, 
rightValue));
+      } else if (TSDataType.INT64.equals(rightColumn.getDataType())) {
+        long rightValue = rightColumn.getLong(i);
+        
columnBuilder.writeLong(BitwiseUtils.bitwiseLeftShiftTransform(leftValue, 
rightValue));
+      }
+    }
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseLeftShiftColumnTransformer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseLeftShiftColumnTransformer.java
new file mode 100644
index 00000000000..40651076dfc
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseLeftShiftColumnTransformer.java
@@ -0,0 +1,47 @@
+/*
+ * 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.db.queryengine.transformation.dag.column.unary.scalar;
+
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.ColumnTransformer;
+import org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.type.Type;
+
+public class BitwiseLeftShiftColumnTransformer extends 
AbstractBitwiseColumnTransformer {
+
+  public BitwiseLeftShiftColumnTransformer(
+      Type returnType, ColumnTransformer childColumnTransformer, long 
rightValue) {
+    super(returnType, childColumnTransformer, rightValue);
+  }
+
+  @Override
+  protected void transform(Column column, ColumnBuilder columnBuilder, int i) {
+    if (TSDataType.INT32.equals(column.getDataType())) {
+      int leftValue = column.getInt(i);
+      columnBuilder.writeInt(BitwiseUtils.bitwiseLeftShiftTransform(leftValue, 
rightValue));
+    } else if (TSDataType.INT64.equals(column.getDataType())) {
+      long leftValue = column.getLong(i);
+      
columnBuilder.writeLong(BitwiseUtils.bitwiseLeftShiftTransform(leftValue, 
rightValue));
+    }
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseNotColumnTransformer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseNotColumnTransformer.java
new file mode 100644
index 00000000000..8649cdbdb6b
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseNotColumnTransformer.java
@@ -0,0 +1,63 @@
+/*
+ * 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.db.queryengine.transformation.dag.column.unary.scalar;
+
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.ColumnTransformer;
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.unary.UnaryColumnTransformer;
+import org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.read.common.type.Type;
+
+public class BitwiseNotColumnTransformer extends UnaryColumnTransformer {
+
+  public BitwiseNotColumnTransformer(Type returnType, ColumnTransformer 
childColumnTransformer) {
+    super(returnType, childColumnTransformer);
+  }
+
+  @Override
+  protected void doTransform(Column column, ColumnBuilder columnBuilder) {
+    for (int i = 0, n = column.getPositionCount(); i < n; i++) {
+      if (!column.isNull(i)) {
+        transform(column, columnBuilder, i);
+      } else {
+        columnBuilder.appendNull();
+      }
+    }
+  }
+
+  @Override
+  protected void doTransform(Column column, ColumnBuilder columnBuilder, 
boolean[] selection) {
+    for (int i = 0, n = column.getPositionCount(); i < n; i++) {
+      if (selection[i] && !column.isNull(i)) {
+        transform(column, columnBuilder, i);
+      } else {
+        columnBuilder.appendNull();
+      }
+    }
+  }
+
+  private void transform(Column column, ColumnBuilder columnBuilder, int i) {
+    long leftValue = column.getLong(i);
+    long currentValue = BitwiseUtils.bitwiseNotTransform(leftValue);
+    columnBuilder.writeLong(currentValue);
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseOr2ColumnTransformer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseOr2ColumnTransformer.java
new file mode 100644
index 00000000000..d54ff7b1607
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseOr2ColumnTransformer.java
@@ -0,0 +1,44 @@
+/*
+ * 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.db.queryengine.transformation.dag.column.unary.scalar;
+
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.ColumnTransformer;
+import org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.read.common.type.Type;
+
+public class BitwiseOr2ColumnTransformer extends 
AbstractBitwise2ColumnTransformer {
+
+  public BitwiseOr2ColumnTransformer(
+      Type returnType, ColumnTransformer leftTransformer, ColumnTransformer 
rightTransformer) {
+    super(returnType, leftTransformer, rightTransformer);
+  }
+
+  @Override
+  protected void transform(
+      Column leftColumn, Column rightColumn, ColumnBuilder columnBuilder, int 
i) {
+    long leftValue = leftColumn.getLong(i);
+    long rightValue = rightColumn.getLong(i);
+    long currentValue = BitwiseUtils.bitwiseOrTransform(leftValue, rightValue);
+    columnBuilder.writeLong(currentValue);
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseOrColumnTransformer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseOrColumnTransformer.java
new file mode 100644
index 00000000000..e6be0927f46
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseOrColumnTransformer.java
@@ -0,0 +1,42 @@
+/*
+ * 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.db.queryengine.transformation.dag.column.unary.scalar;
+
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.ColumnTransformer;
+import org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.read.common.type.Type;
+
+public class BitwiseOrColumnTransformer extends 
AbstractBitwiseColumnTransformer {
+
+  public BitwiseOrColumnTransformer(
+      Type returnType, ColumnTransformer childColumnTransformer, long 
rightValue) {
+    super(returnType, childColumnTransformer, rightValue);
+  }
+
+  @Override
+  protected void transform(Column column, ColumnBuilder columnBuilder, int i) {
+    long leftValue = column.getLong(i);
+    long currentValue = BitwiseUtils.bitwiseOrTransform(leftValue, rightValue);
+    columnBuilder.writeLong(currentValue);
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseRightShift2ColumnTransformer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseRightShift2ColumnTransformer.java
new file mode 100644
index 00000000000..8d717c6c883
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseRightShift2ColumnTransformer.java
@@ -0,0 +1,60 @@
+/*
+ * 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.db.queryengine.transformation.dag.column.unary.scalar;
+
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.ColumnTransformer;
+import org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.type.Type;
+
+public class BitwiseRightShift2ColumnTransformer extends 
AbstractBitwise2ColumnTransformer {
+
+  public BitwiseRightShift2ColumnTransformer(
+      Type returnType, ColumnTransformer leftTransformer, ColumnTransformer 
rightTransformer) {
+    super(returnType, leftTransformer, rightTransformer);
+  }
+
+  @Override
+  protected void transform(
+      Column leftColumn, Column rightColumn, ColumnBuilder columnBuilder, int 
i) {
+    if (TSDataType.INT32.equals(leftColumn.getDataType())) {
+      int leftValue = leftColumn.getInt(i);
+      if (TSDataType.INT32.equals(rightColumn.getDataType())) {
+        int rightValue = rightColumn.getInt(i);
+        
columnBuilder.writeInt(BitwiseUtils.bitwiseRightShiftTransform(leftValue, 
rightValue));
+      } else if (TSDataType.INT64.equals(rightColumn.getDataType())) {
+        long rightValue = rightColumn.getLong(i);
+        
columnBuilder.writeInt(BitwiseUtils.bitwiseRightShiftTransform(leftValue, 
rightValue));
+      }
+    } else if (TSDataType.INT64.equals(leftColumn.getDataType())) {
+      long leftValue = leftColumn.getLong(i);
+      if (TSDataType.INT32.equals(rightColumn.getDataType())) {
+        int rightValue = rightColumn.getInt(i);
+        
columnBuilder.writeLong(BitwiseUtils.bitwiseRightShiftTransform(leftValue, 
rightValue));
+      } else if (TSDataType.INT64.equals(rightColumn.getDataType())) {
+        long rightValue = rightColumn.getLong(i);
+        
columnBuilder.writeLong(BitwiseUtils.bitwiseRightShiftTransform(leftValue, 
rightValue));
+      }
+    }
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseRightShiftArithmetic2ColumnTransformer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseRightShiftArithmetic2ColumnTransformer.java
new file mode 100644
index 00000000000..402d38d40c8
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseRightShiftArithmetic2ColumnTransformer.java
@@ -0,0 +1,65 @@
+/*
+ * 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.db.queryengine.transformation.dag.column.unary.scalar;
+
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.ColumnTransformer;
+import org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.type.Type;
+
+public class BitwiseRightShiftArithmetic2ColumnTransformer
+    extends AbstractBitwise2ColumnTransformer {
+
+  public BitwiseRightShiftArithmetic2ColumnTransformer(
+      Type returnType, ColumnTransformer leftTransformer, ColumnTransformer 
rightTransformer) {
+    super(returnType, leftTransformer, rightTransformer);
+  }
+
+  @Override
+  protected void transform(
+      Column leftColumn, Column rightColumn, ColumnBuilder columnBuilder, int 
i) {
+    if (TSDataType.INT32.equals(leftColumn.getDataType())) {
+      int leftValue = leftColumn.getInt(i);
+      if (TSDataType.INT32.equals(rightColumn.getDataType())) {
+        int rightValue = rightColumn.getInt(i);
+        columnBuilder.writeInt(
+            BitwiseUtils.bitwiseRightShiftArithmeticTransform(leftValue, 
rightValue));
+      } else if (TSDataType.INT64.equals(rightColumn.getDataType())) {
+        long rightValue = rightColumn.getLong(i);
+        columnBuilder.writeInt(
+            BitwiseUtils.bitwiseRightShiftArithmeticTransform(leftValue, 
rightValue));
+      }
+    } else if (TSDataType.INT64.equals(leftColumn.getDataType())) {
+      long leftValue = leftColumn.getLong(i);
+      if (TSDataType.INT32.equals(rightColumn.getDataType())) {
+        int rightValue = rightColumn.getInt(i);
+        columnBuilder.writeLong(
+            BitwiseUtils.bitwiseRightShiftArithmeticTransform(leftValue, 
rightValue));
+      } else if (TSDataType.INT64.equals(rightColumn.getDataType())) {
+        long rightValue = rightColumn.getLong(i);
+        columnBuilder.writeLong(
+            BitwiseUtils.bitwiseRightShiftArithmeticTransform(leftValue, 
rightValue));
+      }
+    }
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseRightShiftArithmeticColumnTransformer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseRightShiftArithmeticColumnTransformer.java
new file mode 100644
index 00000000000..5042d83d4c0
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseRightShiftArithmeticColumnTransformer.java
@@ -0,0 +1,49 @@
+/*
+ * 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.db.queryengine.transformation.dag.column.unary.scalar;
+
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.ColumnTransformer;
+import org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.type.Type;
+
+public class BitwiseRightShiftArithmeticColumnTransformer extends 
AbstractBitwiseColumnTransformer {
+
+  public BitwiseRightShiftArithmeticColumnTransformer(
+      Type returnType, ColumnTransformer childColumnTransformer, long 
rightValue) {
+    super(returnType, childColumnTransformer, rightValue);
+  }
+
+  @Override
+  protected void transform(Column column, ColumnBuilder columnBuilder, int i) {
+    if (TSDataType.INT32.equals(column.getDataType())) {
+      int leftValue = column.getInt(i);
+      columnBuilder.writeInt(
+          BitwiseUtils.bitwiseRightShiftArithmeticTransform(leftValue, 
rightValue));
+    } else if (TSDataType.INT64.equals(column.getDataType())) {
+      long leftValue = column.getLong(i);
+      columnBuilder.writeLong(
+          BitwiseUtils.bitwiseRightShiftArithmeticTransform(leftValue, 
rightValue));
+    }
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseRightShiftColumnTransformer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseRightShiftColumnTransformer.java
new file mode 100644
index 00000000000..5f77af2e87c
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseRightShiftColumnTransformer.java
@@ -0,0 +1,47 @@
+/*
+ * 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.db.queryengine.transformation.dag.column.unary.scalar;
+
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.ColumnTransformer;
+import org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.type.Type;
+
+public class BitwiseRightShiftColumnTransformer extends 
AbstractBitwiseColumnTransformer {
+
+  public BitwiseRightShiftColumnTransformer(
+      Type returnType, ColumnTransformer childColumnTransformer, long 
rightValue) {
+    super(returnType, childColumnTransformer, rightValue);
+  }
+
+  @Override
+  protected void transform(Column column, ColumnBuilder columnBuilder, int i) {
+    if (TSDataType.INT32.equals(column.getDataType())) {
+      int leftValue = column.getInt(i);
+      
columnBuilder.writeInt(BitwiseUtils.bitwiseRightShiftTransform(leftValue, 
rightValue));
+    } else if (TSDataType.INT64.equals(column.getDataType())) {
+      long leftValue = column.getLong(i);
+      
columnBuilder.writeLong(BitwiseUtils.bitwiseRightShiftTransform(leftValue, 
rightValue));
+    }
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseXor2ColumnTransformer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseXor2ColumnTransformer.java
new file mode 100644
index 00000000000..8ab1c754f28
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseXor2ColumnTransformer.java
@@ -0,0 +1,44 @@
+/*
+ * 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.db.queryengine.transformation.dag.column.unary.scalar;
+
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.ColumnTransformer;
+import org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.read.common.type.Type;
+
+public class BitwiseXor2ColumnTransformer extends 
AbstractBitwise2ColumnTransformer {
+
+  public BitwiseXor2ColumnTransformer(
+      Type returnType, ColumnTransformer leftTransformer, ColumnTransformer 
rightTransformer) {
+    super(returnType, leftTransformer, rightTransformer);
+  }
+
+  @Override
+  protected void transform(
+      Column leftColumn, Column rightColumn, ColumnBuilder columnBuilder, int 
i) {
+    long leftValue = leftColumn.getLong(i);
+    long rightValue = rightColumn.getLong(i);
+    long currentValue = BitwiseUtils.bitwiseXorTransform(leftValue, 
rightValue);
+    columnBuilder.writeLong(currentValue);
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseXorColumnTransformer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseXorColumnTransformer.java
new file mode 100644
index 00000000000..0d648b3e26e
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/BitwiseXorColumnTransformer.java
@@ -0,0 +1,42 @@
+/*
+ * 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.db.queryengine.transformation.dag.column.unary.scalar;
+
+import 
org.apache.iotdb.db.queryengine.transformation.dag.column.ColumnTransformer;
+import org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils;
+
+import org.apache.tsfile.block.column.Column;
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.read.common.type.Type;
+
+public class BitwiseXorColumnTransformer extends 
AbstractBitwiseColumnTransformer {
+
+  public BitwiseXorColumnTransformer(
+      Type returnType, ColumnTransformer childColumnTransformer, long 
rightValue) {
+    super(returnType, childColumnTransformer, rightValue);
+  }
+
+  @Override
+  protected void transform(Column column, ColumnBuilder columnBuilder, int i) {
+    long leftValue = column.getLong(i);
+    long currentValue = BitwiseUtils.bitwiseXorTransform(leftValue, 
rightValue);
+    columnBuilder.writeLong(currentValue);
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/util/BitwiseUtils.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/util/BitwiseUtils.java
new file mode 100644
index 00000000000..97038b20e0e
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/util/BitwiseUtils.java
@@ -0,0 +1,210 @@
+/*
+ * 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.db.queryengine.transformation.dag.util;
+
+import org.apache.iotdb.db.exception.sql.SemanticException;
+
+public class BitwiseUtils {
+  private static final long TINYINT_MASK = 0b1111_1111L;
+  private static final long TINYINT_SIGNED_BIT = 0b1000_0000L;
+  private static final long SMALLINT_MASK = 0b1111_1111_1111_1111L;
+  private static final long SMALLINT_SIGNED_BIT = 0b1000_0000_0000_0000L;
+  private static final int TINYINT_MASK_IN_INT = 0b1111_1111;
+  private static final int TINYINT_SIGNED_BIT_IN_INT = 0b1000_0000;
+  private static final int SMALLINT_MASK_IN_INT = 0b1111_1111_1111_1111;
+  private static final int SMALLINT_SIGNED_BIT_IN_INT = 0b1000_0000_0000_0000;
+  private static final long INTEGER_MASK = 0x00_00_00_00_ff_ff_ff_ffL;
+  private static final long INTEGER_SIGNED_BIT = 0x00_00_00_00_00_80_00_00_00L;
+
+  public static void bitCountCheck(long num, long bits) {
+    bitCountCheckBits(bits);
+
+    // set the least (bits - 1) bits
+    final long lowBitsMask = (1L << (bits - 1)) - 1;
+    if (num > lowBitsMask || num < ~lowBitsMask) {
+      throw new SemanticException(
+          String.format(
+              "Argument exception, the scalar function num must be 
representable with the bits specified. %s cannot be represented with %s bits.",
+              num, bits));
+    }
+  }
+
+  public static void bitCountCheckBits(long bits) {
+    if (bits <= 1 || bits > 64) {
+      throw new SemanticException(
+          "Argument exception, the scalar function bit_count bits must be 
between 2 and 64.");
+    }
+  }
+
+  public static long bitCountTransform(long num, long bits) {
+    bitCountCheck(num, bits);
+
+    if (bits == 64) {
+      return Long.bitCount(num);
+    }
+
+    final long mask = (1L << bits) - 1;
+    return Long.bitCount(num & mask);
+  }
+
+  public static long bitwiseAndTransform(long leftValue, long rightValue) {
+    return leftValue & rightValue;
+  }
+
+  public static long bitwiseNotTransform(long leftValue) {
+    return ~leftValue;
+  }
+
+  public static long bitwiseOrTransform(long leftValue, long rightValue) {
+    return leftValue | rightValue;
+  }
+
+  public static long bitwiseXorTransform(long leftValue, long rightValue) {
+    return leftValue ^ rightValue;
+  }
+
+  public static int bitwiseLeftShiftTransform(int value, long shift) {
+    if (shift >= 32) {
+      return 0;
+    }
+    int shifted = (value << shift);
+    if (isTinyInt(value)) {
+      return preserveSign(shifted, TINYINT_MASK_IN_INT, 
TINYINT_SIGNED_BIT_IN_INT);
+    } else if (isSmallInt(value)) {
+      return preserveSign(shifted, SMALLINT_MASK_IN_INT, 
SMALLINT_SIGNED_BIT_IN_INT);
+    } else {
+      return shifted;
+    }
+  }
+
+  public static long bitwiseLeftShiftTransform(long value, long shift) {
+    if (shift >= 64) {
+      return 0L;
+    }
+    long shifted = (value << shift);
+    if (isTinyInt(value)) {
+      return preserveSign(shifted, TINYINT_MASK, TINYINT_SIGNED_BIT);
+    } else if (isSmallInt(value)) {
+      return preserveSign(shifted, SMALLINT_MASK, SMALLINT_SIGNED_BIT);
+    } else if (isInt32(value)) {
+      return preserveSign(shifted, INTEGER_MASK, INTEGER_SIGNED_BIT);
+    } else {
+      return shifted;
+    }
+  }
+
+  public static int bitwiseRightShiftTransform(int value, long shift) {
+    if (shift >= 32) {
+      return 0;
+    }
+    if (shift == 0) {
+      return value;
+    }
+    if (isTinyInt(value)) {
+      return (value & TINYINT_MASK_IN_INT) >>> shift;
+    } else if (isSmallInt(value)) {
+      return (value & SMALLINT_MASK_IN_INT) >>> shift;
+    } else {
+      return value >>> shift;
+    }
+  }
+
+  public static long bitwiseRightShiftTransform(long value, long shift) {
+    if (shift >= 64) {
+      return 0L;
+    }
+    if (shift == 0) {
+      return value;
+    }
+    if (isTinyInt(value)) {
+      return (value & TINYINT_MASK) >>> shift;
+    } else if (isSmallInt(value)) {
+      return (value & SMALLINT_MASK) >>> shift;
+    } else if (isInt32(value)) {
+      return (value & INTEGER_MASK) >>> shift;
+    } else {
+      return value >>> shift;
+    }
+  }
+
+  public static int bitwiseRightShiftArithmeticTransform(int value, long 
shift) {
+    if (shift >= 32) {
+      if (value >= 0) {
+        return 0;
+      }
+      return -1;
+    }
+    if (isTinyInt(value)) {
+      return preserveSign(value, TINYINT_MASK_IN_INT, 
TINYINT_SIGNED_BIT_IN_INT) >> shift;
+    } else if (isSmallInt(value)) {
+      return preserveSign(value, SMALLINT_MASK_IN_INT, 
SMALLINT_SIGNED_BIT_IN_INT) >> shift;
+    } else {
+      return value >> shift;
+    }
+  }
+
+  public static long bitwiseRightShiftArithmeticTransform(long value, long 
shift) {
+    if (shift >= 64) {
+      if (value >= 0) {
+        return 0L;
+      }
+      return -1L;
+    }
+    if (isTinyInt(value)) {
+      return preserveSign(value, TINYINT_MASK, TINYINT_SIGNED_BIT) >> shift;
+    } else if (isSmallInt(value)) {
+      return preserveSign(value, SMALLINT_MASK, SMALLINT_SIGNED_BIT) >> shift;
+    } else if (isInt32(value)) {
+      return preserveSign(value, INTEGER_MASK, INTEGER_SIGNED_BIT) >> shift;
+    } else {
+      return value >> shift;
+    }
+  }
+
+  private static long preserveSign(long shiftedValue, long mask, long 
signedBit) {
+    // Preserve the sign in 2's complement format
+    if ((shiftedValue & signedBit) != 0) {
+      return shiftedValue | ~mask;
+    }
+
+    return shiftedValue & mask;
+  }
+
+  private static int preserveSign(int shiftedValue, int mask, int signedBit) {
+    // Preserve the sign in 2's complement format
+    if ((shiftedValue & signedBit) != 0) {
+      return shiftedValue | ~mask;
+    }
+
+    return shiftedValue & mask;
+  }
+
+  private static boolean isTinyInt(long value) {
+    return ((value + 128L) & ~0xFFL) == 0L;
+  }
+
+  private static boolean isSmallInt(long value) {
+    return ((value + 32_768L) & ~0xFFFFL) == 0L;
+  }
+
+  private static boolean isInt32(long value) {
+    return ((value + 2_147_483_648L) & ~0xFFFF_FFFFL) == 0L;
+  }
+}
diff --git 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/transformation/dag/util/BitwiseUtilsTest.java
 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/transformation/dag/util/BitwiseUtilsTest.java
new file mode 100644
index 00000000000..04a611f07c4
--- /dev/null
+++ 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/transformation/dag/util/BitwiseUtilsTest.java
@@ -0,0 +1,131 @@
+/*
+ * 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.db.queryengine.transformation.dag.util;
+
+import org.apache.iotdb.db.exception.sql.SemanticException;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import static 
org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils.bitCountCheck;
+import static 
org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils.bitwiseAndTransform;
+import static 
org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils.bitwiseLeftShiftTransform;
+import static 
org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils.bitwiseNotTransform;
+import static 
org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils.bitwiseOrTransform;
+import static 
org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils.bitwiseRightShiftArithmeticTransform;
+import static 
org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils.bitwiseRightShiftTransform;
+import static 
org.apache.iotdb.db.queryengine.transformation.dag.util.BitwiseUtils.bitwiseXorTransform;
+
+public class BitwiseUtilsTest {
+  @Test
+  public void testBitCountCheck() {
+    Assert.assertThrows(SemanticException.class, () -> bitCountCheck(0, 0));
+    Assert.assertThrows(SemanticException.class, () -> bitCountCheck(7, 1));
+    Assert.assertThrows(SemanticException.class, () -> bitCountCheck(7, 2));
+    Assert.assertThrows(SemanticException.class, () -> bitCountCheck(128, 7));
+    Assert.assertThrows(SemanticException.class, () -> bitCountCheck(128, 8));
+  }
+
+  @Test
+  public void testBitCountFunctions() {
+    Assert.assertEquals(2, BitwiseUtils.bitCountTransform(5, 8));
+    Assert.assertEquals(7, BitwiseUtils.bitCountTransform(-5, 8));
+    Assert.assertEquals(2, BitwiseUtils.bitCountTransform(9, 64));
+    Assert.assertEquals(2, BitwiseUtils.bitCountTransform(9, 8));
+    Assert.assertEquals(62, BitwiseUtils.bitCountTransform(-7, 64));
+    Assert.assertEquals(6, BitwiseUtils.bitCountTransform(-7, 8));
+    Assert.assertEquals(1, BitwiseUtils.bitCountTransform(128, 9));
+    Assert.assertEquals(1, BitwiseUtils.bitCountTransform(128, 10));
+    Assert.assertEquals(1, BitwiseUtils.bitCountTransform(128, 11));
+    Assert.assertEquals(1, BitwiseUtils.bitCountTransform(128, 12));
+    Assert.assertEquals(1, BitwiseUtils.bitCountTransform(128, 32));
+    Assert.assertEquals(1, BitwiseUtils.bitCountTransform(128, 64));
+  }
+
+  @Test
+  public void testBitwiseAndTransform() {
+    Assert.assertEquals(17, bitwiseAndTransform(19, 25));
+  }
+
+  @Test
+  public void testBitwiseNotTransform() {
+    Assert.assertEquals(-6, bitwiseNotTransform(5));
+    Assert.assertEquals(11, bitwiseNotTransform(-12));
+    Assert.assertEquals(-20, bitwiseNotTransform(19));
+    Assert.assertEquals(-26, bitwiseNotTransform(25));
+  }
+
+  @Test
+  public void testBitwiseOrTransform() {
+    Assert.assertEquals(27, bitwiseOrTransform(19, 25));
+  }
+
+  @Test
+  public void testBitwiseXorTransform() {
+    Assert.assertEquals(10, bitwiseXorTransform(19, 25));
+  }
+
+  @Test
+  public void testBitwiseLeftShiftTransform() {
+    Assert.assertEquals(4, bitwiseLeftShiftTransform(1, 2));
+    Assert.assertEquals(20, bitwiseLeftShiftTransform(5, 2));
+    Assert.assertEquals(20, bitwiseLeftShiftTransform(20, 0));
+    Assert.assertEquals(42, bitwiseLeftShiftTransform(42, 0));
+    Assert.assertEquals(0, bitwiseLeftShiftTransform(0, 1));
+    Assert.assertEquals(0, bitwiseLeftShiftTransform(0, 2));
+
+    Assert.assertEquals(4L, bitwiseLeftShiftTransform(1L, 2));
+    Assert.assertEquals(20L, bitwiseLeftShiftTransform(5L, 2));
+    Assert.assertEquals(20L, bitwiseLeftShiftTransform(20L, 0));
+    Assert.assertEquals(42L, bitwiseLeftShiftTransform(42L, 0));
+    Assert.assertEquals(0L, bitwiseLeftShiftTransform(0L, 1));
+    Assert.assertEquals(0L, bitwiseLeftShiftTransform(0L, 2));
+  }
+
+  @Test
+  public void testBitwiseRightShiftTransform() {
+    Assert.assertEquals(1, bitwiseRightShiftTransform(8, 3));
+    Assert.assertEquals(4, bitwiseRightShiftTransform(9, 1));
+    Assert.assertEquals(20, bitwiseRightShiftTransform(20, 0));
+    Assert.assertEquals(42, bitwiseRightShiftTransform(42, 0));
+    Assert.assertEquals(0, bitwiseRightShiftTransform(0, 1));
+    Assert.assertEquals(0, bitwiseRightShiftTransform(0, 2));
+    Assert.assertEquals(0, bitwiseRightShiftTransform(12, 64));
+    Assert.assertEquals(0, bitwiseRightShiftTransform(-45, 64));
+
+    Assert.assertEquals(1L, bitwiseRightShiftTransform(8L, 3));
+    Assert.assertEquals(4L, bitwiseRightShiftTransform(9L, 1));
+    Assert.assertEquals(20L, bitwiseRightShiftTransform(20L, 0));
+    Assert.assertEquals(42L, bitwiseRightShiftTransform(42L, 0));
+    Assert.assertEquals(0L, bitwiseRightShiftTransform(0L, 1));
+    Assert.assertEquals(0L, bitwiseRightShiftTransform(0L, 2));
+    Assert.assertEquals(0L, bitwiseRightShiftTransform(12L, 64));
+    Assert.assertEquals(0L, bitwiseRightShiftTransform(-45L, 64));
+  }
+
+  @Test
+  public void testBitwiseRightShiftArithmeticTransform() {
+    Assert.assertEquals(0, bitwiseRightShiftArithmeticTransform(12, 64));
+    Assert.assertEquals(-1, bitwiseRightShiftArithmeticTransform(-45, 64));
+
+    Assert.assertEquals(0L, bitwiseRightShiftArithmeticTransform(12L, 64));
+    Assert.assertEquals(-1L, bitwiseRightShiftArithmeticTransform(-45L, 64));
+  }
+}
diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/relational/TableBuiltinScalarFunction.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/relational/TableBuiltinScalarFunction.java
index 6d5b1ef4721..dfad12adafc 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/relational/TableBuiltinScalarFunction.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/relational/TableBuiltinScalarFunction.java
@@ -67,6 +67,14 @@ public enum TableBuiltinScalarFunction {
   FORMAT("format"),
   GREATEST("greatest"),
   LEAST("least"),
+  BIT_COUNT("bit_count"),
+  BITWISE_AND("bitwise_and"),
+  BITWISE_NOT("bitwise_not"),
+  BITWISE_OR("bitwise_or"),
+  BITWISE_XOR("bitwise_xor"),
+  BITWISE_LEFT_SHIFT("bitwise_left_shift"),
+  BITWISE_RIGHT_SHIFT("bitwise_right_shift"),
+  BITWISE_RIGHT_SHIFT_ARITHMETIC("bitwise_right_shift_arithmetic"),
   ;
 
   private final String functionName;


Reply via email to