gortiz commented on code in PR #16570:
URL: https://github.com/apache/pinot/pull/16570#discussion_r2269740933


##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/SetOperator.java:
##########
@@ -154,9 +176,9 @@ protected StatMap<?> copyStatMaps() {
   }
 
   /**
-   * Returns true if the row is matched.
-   * Also updates the right row set based on the Operator.
-   * @param row
+   * Returns true if the row is matched. Also updates the right row set based 
on the Operator.

Review Comment:
   nit: probably the older doc included a line break because the first phrase 
(defined as up to the first dot) is rendered in a different way in javaodoc.



##########
pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/operator/IntersectOperatorTest.java:
##########
@@ -115,4 +116,40 @@ public void testDedup() {
       Assert.assertEquals(resultRows.get(i), expectedRows.get(i));
     }
   }
+
+  @Test
+  public void testErrorBlockRightChild() {
+    DataSchema schema = new DataSchema(new String[]{"int_col", "string_col"}, 
new DataSchema.ColumnDataType[]{
+        DataSchema.ColumnDataType.INT, DataSchema.ColumnDataType.STRING
+    });
+    Mockito.when(_leftOperator.nextBlock())
+        .thenReturn(OperatorTestUtil.block(schema, new Object[]{1, "AA"}, new 
Object[]{2, "BB"}))
+        .thenReturn(SuccessMseBlock.INSTANCE);
+    Mockito.when(_rightOperator.nextBlock())
+        .thenReturn(ErrorMseBlock.fromException(new RuntimeException("Error in 
right operator")));

Review Comment:
   nit: it is better to use BlockListMultiStageOperator instead of mocking.



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/UnionAllOperator.java:
##########
@@ -0,0 +1,70 @@
+/**
+ * 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.pinot.query.runtime.operator;
+
+import java.util.List;
+import org.apache.pinot.common.utils.DataSchema;
+import org.apache.pinot.query.runtime.blocks.MseBlock;
+import org.apache.pinot.query.runtime.plan.OpChainExecutionContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Union operator for UNION ALL queries.
+ */
+public class UnionAllOperator extends SetOperator {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(UnionAllOperator.class);
+  private static final String EXPLAIN_NAME = "UNION_ALL";
+
+  public UnionAllOperator(OpChainExecutionContext opChainExecutionContext, 
List<MultiStageOperator> inputOperators,
+      DataSchema dataSchema) {
+    super(opChainExecutionContext, inputOperators, dataSchema);
+  }
+
+  @Override
+  protected Logger logger() {
+    return LOGGER;
+  }
+
+  @Override
+  public Type getOperatorType() {
+    return Type.UNION;
+  }
+
+  @Override
+  public String toExplainString() {
+    return EXPLAIN_NAME;
+  }
+
+  @Override
+  protected MseBlock processRightOperator() {
+    return _rightChildOperator.nextBlock();
+  }
+
+  @Override
+  protected MseBlock processLeftOperator() {
+    return _leftChildOperator.nextBlock();
+  }
+
+  @Override
+  protected boolean handleRowMatched(Object[] row) {
+    throw new UnsupportedOperationException("UNION ALL operator does not 
support row matching");

Review Comment:
   nit: I know it wasn't added in this PR, but this is a code smell. In the 
future we should refactor these classes to make `processLeftOperator` (and 
probably `processRightOperator`) abstract and therefore doesn't declare 
`handleRowMatched`. Then have another abstract class that implements 
`processLeftOperator` using `handleRowMatched`.
   
   The current implementation is a bit unsafe to use and definetively error 
prone 



##########
pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/operator/UnionAllOperatorTest.java:
##########
@@ -0,0 +1,135 @@
+/**
+ * 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.pinot.query.runtime.operator;
+
+import com.google.common.collect.ImmutableList;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.pinot.common.utils.DataSchema;
+import org.apache.pinot.query.routing.VirtualServerAddress;
+import org.apache.pinot.query.runtime.blocks.ErrorMseBlock;
+import org.apache.pinot.query.runtime.blocks.MseBlock;
+import org.apache.pinot.query.runtime.blocks.SuccessMseBlock;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+
+public class UnionAllOperatorTest {
+  private AutoCloseable _mocks;
+
+  @Mock
+  private MultiStageOperator _leftOperator;
+
+  @Mock
+  private MultiStageOperator _rightOperator;
+
+  @Mock
+  private VirtualServerAddress _serverAddress;
+
+  @BeforeMethod
+  public void setUp() {
+    _mocks = MockitoAnnotations.openMocks(this);
+    Mockito.when(_serverAddress.toString()).thenReturn(new 
VirtualServerAddress("mock", 80, 0).toString());
+  }
+
+  @AfterMethod
+  public void tearDown()
+      throws Exception {
+    _mocks.close();
+  }
+
+  @Test
+  public void testUnionOperator() {
+    DataSchema schema = new DataSchema(new String[]{"int_col", "string_col"}, 
new DataSchema.ColumnDataType[]{
+        DataSchema.ColumnDataType.INT, DataSchema.ColumnDataType.STRING
+    });
+    Mockito.when(_leftOperator.nextBlock())
+        .thenReturn(OperatorTestUtil.block(schema, new Object[]{1, "AA"}, new 
Object[]{2, "BB"}))
+        .thenReturn(SuccessMseBlock.INSTANCE);
+    Mockito.when(_rightOperator.nextBlock()).thenReturn(
+            OperatorTestUtil.block(schema, new Object[]{3, "aa"}, new 
Object[]{4, "bb"}, new Object[]{5, "cc"}))
+        .thenReturn(SuccessMseBlock.INSTANCE);
+
+    UnionAllOperator unionAllOperator =
+        new UnionAllOperator(OperatorTestUtil.getTracingContext(), 
ImmutableList.of(_leftOperator, _rightOperator),
+            schema);
+    List<Object[]> resultRows = new ArrayList<>();
+    MseBlock result = unionAllOperator.nextBlock();
+    while (result.isData()) {
+      resultRows.addAll(((MseBlock.Data) result).asRowHeap().getRows());
+      result = unionAllOperator.nextBlock();
+    }
+    // Note that UNION ALL does not guarantee the order of rows, and our 
implementation adds rows from the right child
+    // first
+    List<Object[]> expectedRows =
+        Arrays.asList(new Object[]{3, "aa"}, new Object[]{4, "bb"}, new 
Object[]{5, "cc"}, new Object[]{1, "AA"},
+            new Object[]{2, "BB"});
+    Assert.assertEquals(resultRows.size(), expectedRows.size());
+    for (int i = 0; i < resultRows.size(); i++) {
+      Assert.assertEquals(resultRows.get(i), expectedRows.get(i));
+    }
+  }
+
+  @Test
+  public void testErrorBlockRightChild() {
+    DataSchema schema = new DataSchema(new String[]{"int_col", "string_col"}, 
new DataSchema.ColumnDataType[]{
+        DataSchema.ColumnDataType.INT, DataSchema.ColumnDataType.STRING
+    });
+    Mockito.when(_leftOperator.nextBlock())
+        .thenReturn(OperatorTestUtil.block(schema, new Object[]{1, "AA"}, new 
Object[]{2, "BB"}))
+        .thenReturn(SuccessMseBlock.INSTANCE);
+    Mockito.when(_rightOperator.nextBlock())
+        .thenReturn(ErrorMseBlock.fromException(new RuntimeException("Error in 
right operator")));
+
+    UnionAllOperator unionAllOperator =
+        new UnionAllOperator(OperatorTestUtil.getTracingContext(), 
ImmutableList.of(_leftOperator, _rightOperator),
+            schema);
+    MseBlock result = unionAllOperator.nextBlock();
+    Assert.assertTrue(result.isError());
+  }
+
+  @Test
+  public void testErrorBlockLeftChild() {
+    DataSchema schema = new DataSchema(new String[]{"int_col", "string_col"}, 
new DataSchema.ColumnDataType[]{
+        DataSchema.ColumnDataType.INT, DataSchema.ColumnDataType.STRING
+    });
+    Mockito.when(_leftOperator.nextBlock())
+        .thenReturn(ErrorMseBlock.fromException(new RuntimeException("Error in 
left operator")));
+    Mockito.when(_rightOperator.nextBlock())
+        .thenReturn(OperatorTestUtil.block(schema, new Object[]{3, "aa"}, new 
Object[]{4, "bb"}))
+        .thenReturn(SuccessMseBlock.INSTANCE);
+
+    UnionAllOperator unionAllOperator =
+        new UnionAllOperator(OperatorTestUtil.getTracingContext(), 
ImmutableList.of(_leftOperator, _rightOperator),
+            schema);
+    MseBlock result = unionAllOperator.nextBlock();
+    // The first block will be the regular data block from the right operator
+    Assert.assertFalse(result.isError());
+    Assert.assertTrue(result.isData());
+    // The second block should be the error block from the left operator
+    result = unionAllOperator.nextBlock();
+    Assert.assertTrue(result.isError());

Review Comment:
   I think this kind of tests is bound too much to the actual implementation. 
In my opinion, the test should verify that if there is an error on the left 
side, the last block returned is an error. Whether it is the first block or the 
third is implementation-dependent.
   
   The same happen with some other tests



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to