alex-plekhanov commented on code in PR #11649: URL: https://github.com/apache/ignite/pull/11649#discussion_r1848632505
########## modules/calcite/src/test/sql/aggregate/aggregates/test_bit_and.test: ########## @@ -5,22 +5,18 @@ # test on scalar values query II -SELECT BIT_AND(3), BIT_AND(NULL) +SELECT BIT_AND(3), BIT_AND(NULL::INT) Review Comment: We don't need any special cast, for example, for `SUM`, so BIT_AND should also work this way. ########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/AggregatesIntegrationTest.java: ########## @@ -174,6 +176,204 @@ public void testGroupingByAlias() { .check(); } + /** */ + @Test + public void testBitwiseTypesBounds() { + assumeNoTransactions(); + + try { + sql("CREATE TABLE tbl (t TINYINT, s SMALLINT, i INT, b BIGINT)"); Review Comment: For each test: - Remove `assumeNoTransactions();` - Add atomicity: `sql("CREATE TABLE tbl (t TINYINT, s SMALLINT, i INT, b BIGINT) WITH " + atomicity());` - Remove DROP TABLE ########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/AggregatesIntegrationTest.java: ########## @@ -174,6 +176,204 @@ public void testGroupingByAlias() { .check(); } + /** */ + @Test + public void testBitwiseTypesBounds() { + assumeNoTransactions(); + + try { + sql("CREATE TABLE tbl (t TINYINT, s SMALLINT, i INT, b BIGINT)"); + + sql("INSERT INTO tbl values (?, ?, ?, ?)", Byte.MAX_VALUE, 0, 1000, 0); + sql("INSERT INTO tbl values (?, ?, ?, ?)", Byte.MIN_VALUE, 0, 1001, 0); + sql("INSERT INTO tbl values (?, ?, ?, ?)", 0, Short.MAX_VALUE, 1002, 0); + sql("INSERT INTO tbl values (?, ?, ?, ?)", 0, Short.MIN_VALUE, 1003, 0); + sql("INSERT INTO tbl values (?, ?, ?, ?)", 0, 0, Integer.MIN_VALUE, 0); + sql("INSERT INTO tbl values (?, ?, ?, ?)", 0, 0, Integer.MAX_VALUE, 0); + sql("INSERT INTO tbl values (?, ?, ?, ?)", 0, 0, 1006, Long.MAX_VALUE); + sql("INSERT INTO tbl values (?, ?, ?, ?)", 0, 0, 1007, Long.MIN_VALUE); + + assertQuery("SELECT BIT_AND(t) FROM tbl WHERE i=? or i=?").withParams(1000, 1001).returns((byte)0).check(); + assertQuery("SELECT BIT_OR(t) FROM tbl WHERE i=? or i=?").withParams(1000, 1001).returns((byte)-1).check(); + assertQuery("SELECT BIT_XOR(t) FROM tbl WHERE i=? or i=?").withParams(1000, 1001).returns((byte)-1).check(); + + assertQuery("SELECT BIT_AND(s) FROM tbl WHERE i=? or i=?").withParams(1002, 1003).returns((short)0).check(); + assertQuery("SELECT BIT_OR(s) FROM tbl WHERE i=? or i=?").withParams(1002, 1003).returns((short)-1).check(); + assertQuery("SELECT BIT_XOR(s) FROM tbl WHERE i=? or i=?").withParams(1002, 1003).returns((short)-1).check(); + + assertQuery("SELECT BIT_AND(i) FROM tbl WHERE i=? or i=?").withParams(Integer.MAX_VALUE, Integer.MIN_VALUE) + .returns(0).check(); + assertQuery("SELECT BIT_OR(i) FROM tbl WHERE i=? or i=?").withParams(Integer.MAX_VALUE, Integer.MIN_VALUE) + .returns(-1).check(); + assertQuery("SELECT BIT_XOR(i) FROM tbl WHERE i=? or i=?").withParams(Integer.MAX_VALUE, Integer.MIN_VALUE) + .returns(-1).check(); + + assertQuery("SELECT BIT_AND(b) FROM tbl WHERE i=? or i=?").withParams(1006, 1007).returns(0L).check(); + assertQuery("SELECT BIT_OR(b) FROM tbl WHERE i=? or i=?").withParams(1006, 1007).returns(-1L).check(); + assertQuery("SELECT BIT_XOR(b) FROM tbl WHERE i=? or i=?").withParams(1006, 1007).returns(-1L).check(); + } + finally { + sql("DROP TABLE IF EXISTS tbl"); + } + } + + /** */ + @Test + public void testBitwiseBasics() { + assumeNoTransactions(); + + Object[] nullRes = new Object[] {null}; Review Comment: AbstractBasicIntegrationTest#NULL_RESULT ########## modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/Accumulators.java: ########## @@ -143,6 +148,19 @@ private static <Row> Supplier<Accumulator<Row>> avgFactory(AggregateCall call, R } } + /** */ + private static <Row> Supplier<Accumulator<Row>> bitWiseAcc(AggregateCall call, RowHandler<Row> hnd) { + switch (call.type.getSqlTypeName()) { + case BIGINT: + case INTEGER: + case SMALLINT: + case TINYINT: + return () -> new BitWiseAcc<>(call, hnd); Review Comment: ``` case NULL: ``` ########## modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/Accumulators.java: ########## @@ -143,6 +148,19 @@ private static <Row> Supplier<Accumulator<Row>> avgFactory(AggregateCall call, R } } + /** */ + private static <Row> Supplier<Accumulator<Row>> bitWiseAcc(AggregateCall call, RowHandler<Row> hnd) { Review Comment: Perhaps it's better to keep naming identical to other accumulators. For example `bitWiseFactory` for method name and `BitWise` for accumulator class name. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org