ColinLeeo commented on code in PR #18875:
URL: https://github.com/apache/iotdb/pull/18875#discussion_r4309744355
##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/transformation/dag/column/binary/LogicBinaryColumnTransformerTest.java:
##########
@@ -113,4 +113,60 @@ public void testInputType() {
}
}
+
+ @Test
+ public void testLogicAndWithNullsAndSelection() {
+ assertSelectedAnd(false);
+ }
+
+ @Test
+ public void testLogicAndWithNullsAndPartialSelection() {
+ assertSelectedAnd(true);
+ }
+
+ private void assertSelectedAnd(boolean partial) {
+ Boolean[] values = {null, false, true};
+ Boolean[] expected = {null, false, null, false, false, false, null, false,
true};
+ TsBlockBuilder builder =
+ new TsBlockBuilder(9, Arrays.asList(TSDataType.BOOLEAN,
TSDataType.BOOLEAN));
+ for (Boolean left : values) {
+ for (Boolean right : values) {
+ builder.getTimeColumnBuilder().writeLong(0);
+ if (left == null) {
+ builder.getColumnBuilder(0).appendNull();
+ } else {
+ builder.getColumnBuilder(0).writeBoolean(left);
+ }
+ if (right == null) {
+ builder.getColumnBuilder(1).appendNull();
+ } else {
+ builder.getColumnBuilder(1).writeBoolean(right);
+ }
+ builder.declarePosition();
+ }
+ }
+ TsBlock block = builder.build();
+ IdentityColumnTransformer left = new IdentityColumnTransformer(returnType,
0);
+ IdentityColumnTransformer right = new
IdentityColumnTransformer(returnType, 1);
+ left.addReferenceCount();
+ right.addReferenceCount();
+ left.initFromTsBlock(block);
+ right.initFromTsBlock(block);
+ LogicAndColumnTransformer transformer = new
LogicAndColumnTransformer(returnType, left, right);
+ transformer.addReferenceCount();
+ boolean[] selection = new boolean[9];
+ for (int i = 0; i < selection.length; i++) {
+ selection[i] = !partial || i % 2 == 0;
+ }
+ transformer.evaluateWithSelection(selection);
+ Column result = transformer.getColumn();
+ Assert.assertEquals(expected.length, result.getPositionCount());
+ for (int i = 0; i < expected.length; i++) {
+ if (!selection[i] || expected[i] == null) {
+ Assert.assertTrue(result.isNull(i));
+ } else {
+ Assert.assertEquals(expected[i], result.getBoolean(i));
Review Comment:
Addressed in 3316fa6716: added explicit non-null and selection immutability
assertions, and kept the right-FALSE rows selected in the partial mask.
##########
integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBCaseWhenThenIT.java:
##########
@@ -928,4 +928,20 @@ public void testThenWithBinarySameConstant() {
new String[] {"0,0.0,", "1000000,11.0,", "20000000,22.0,",
"210000000,33.0,"};
resultSetEqualTest(sql, expectedHeader, retArray);
}
+
+ @Test
+ public void testNullableAndInLaterCaseBranch() {
+ prepareData(
+ new String[] {
+ "CREATE TIMESERIES root.sg.case_null.s1 WITH DATATYPE=INT32,
ENCODING=PLAIN",
+ "CREATE TIMESERIES root.sg.case_null.s2 WITH DATATYPE=INT32,
ENCODING=PLAIN",
+ "INSERT INTO root.sg.case_null(time, s2) VALUES (1, 1)",
+ "INSERT INTO root.sg.case_null(time, s1, s2) VALUES (2, 1, 1), (3,
0, 1), (4, 101, 1)"
+ });
+ resultSetEqualTest(
+ "SELECT CASE WHEN s1 > 100 THEN 1 WHEN s1 > 0 AND s2 > 0 THEN 2 ELSE 3
END AS result "
Review Comment:
Added both suggested SQL cases in 3316fa6716. The targeted integration test
passes.
##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/transformation/dag/column/binary/LogicBinaryColumnTransformerTest.java:
##########
@@ -113,4 +113,60 @@ public void testInputType() {
}
}
+
+ @Test
+ public void testLogicAndWithNullsAndSelection() {
+ assertSelectedAnd(false);
+ }
+
+ @Test
+ public void testLogicAndWithNullsAndPartialSelection() {
+ assertSelectedAnd(true);
+ }
+
+ private void assertSelectedAnd(boolean partial) {
+ Boolean[] values = {null, false, true};
+ Boolean[] expected = {null, false, null, false, false, false, null, false,
true};
+ TsBlockBuilder builder =
+ new TsBlockBuilder(9, Arrays.asList(TSDataType.BOOLEAN,
TSDataType.BOOLEAN));
+ for (Boolean left : values) {
+ for (Boolean right : values) {
+ builder.getTimeColumnBuilder().writeLong(0);
+ if (left == null) {
+ builder.getColumnBuilder(0).appendNull();
+ } else {
+ builder.getColumnBuilder(0).writeBoolean(left);
+ }
+ if (right == null) {
+ builder.getColumnBuilder(1).appendNull();
+ } else {
+ builder.getColumnBuilder(1).writeBoolean(right);
+ }
+ builder.declarePosition();
+ }
+ }
+ TsBlock block = builder.build();
+ IdentityColumnTransformer left = new IdentityColumnTransformer(returnType,
0);
+ IdentityColumnTransformer right = new
IdentityColumnTransformer(returnType, 1);
+ left.addReferenceCount();
+ right.addReferenceCount();
+ left.initFromTsBlock(block);
+ right.initFromTsBlock(block);
+ LogicAndColumnTransformer transformer = new
LogicAndColumnTransformer(returnType, left, right);
Review Comment:
Generalized the helper for AND/OR with full and partial selection in
3316fa6716. All 7 unit tests pass.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]