You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/11/09 18:34:39 UTC

[GitHub] [pinot] agavra opened a new pull request, #9769: [multistage] add test coverage for SortOperator

agavra opened a new pull request, #9769:
URL: https://github.com/apache/pinot/pull/9769

   follow up to #9767 but for `SortOperator` (also addresses some leftover comments on `AggregateOperator`)


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] walterddr merged pull request #9769: [multistage] add test coverage for SortOperator

Posted by GitBox <gi...@apache.org>.
walterddr merged PR #9769:
URL: https://github.com/apache/pinot/pull/9769


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] agavra commented on a diff in pull request #9769: [multistage] add test coverage for SortOperator

Posted by GitBox <gi...@apache.org>.
agavra commented on code in PR #9769:
URL: https://github.com/apache/pinot/pull/9769#discussion_r1019444148


##########
pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/operator/SortOperatorTest.java:
##########
@@ -0,0 +1,363 @@
+/**
+ * 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.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.calcite.rel.RelFieldCollation.Direction;
+import org.apache.pinot.common.datablock.DataBlock;
+import org.apache.pinot.common.utils.DataSchema;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.query.planner.logical.RexExpression;
+import org.apache.pinot.query.runtime.blocks.TransferableBlock;
+import org.apache.pinot.query.runtime.blocks.TransferableBlockUtils;
+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;
+
+import static org.apache.pinot.common.utils.DataSchema.ColumnDataType.INT;
+import static org.apache.pinot.common.utils.DataSchema.ColumnDataType.STRING;
+
+
+public class SortOperatorTest {
+
+  private AutoCloseable _mocks;
+
+  @Mock
+  private Operator<TransferableBlock> _input;
+
+  @BeforeMethod
+  public void setUp() {
+    _mocks = MockitoAnnotations.openMocks(this);
+  }
+
+  @AfterMethod
+  public void tearDown()
+      throws Exception {
+    _mocks.close();
+  }
+
+  @Test
+  public void shouldHandleUpstreamErrorBlock() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(TransferableBlockUtils.getErrorTransferableBlock(new Exception("foo!")));
+
+    // When:
+    TransferableBlock block = op.nextBlock();
+
+    // Then:
+    Assert.assertTrue(block.isErrorBlock(), "expected error block to propagate");
+  }
+
+  @Test
+  public void shouldHandleUpstreamNoOpBlock() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock()).thenReturn(TransferableBlockUtils.getNoOpTransferableBlock());
+
+    // When:
+    TransferableBlock block = op.nextBlock();
+
+    // Then:
+    Assert.assertTrue(block.isNoOpBlock(), "expected noop block to propagate");
+  }
+
+  @Test
+  public void shouldCreateEmptyBlockOnUpstreamEOS() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock()).thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    TransferableBlock block = op.nextBlock();
+
+    // Then:
+    Assert.assertTrue(block.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldConsumeAndSortInputOneBlockWithTwoRows() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}, new Object[]{1}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 2);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{1});
+    Assert.assertEquals(block.getContainer().get(1), new Object[]{2});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldConsumeAndSortInputOneBlockWithTwoRowsNonNumeric() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{STRING});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{"b"}, new Object[]{"a"}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 2);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{"a"});
+    Assert.assertEquals(block.getContainer().get(1), new Object[]{"b"});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldConsumeAndSortDescending() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.DESCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}, new Object[]{1}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 2);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{2});
+    Assert.assertEquals(block.getContainer().get(1), new Object[]{1});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldOffsetSortInputOneBlockWithThreeRows() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 1, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}, new Object[]{1}, new Object[]{3}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 2);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{2});
+    Assert.assertEquals(block.getContainer().get(1), new Object[]{3});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldOffsetLimitSortInputOneBlockWithThreeRows() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 1, 1, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}, new Object[]{1}, new Object[]{3}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 1);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{2});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldRespectMaxLimit() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 2, 0, schema, 1);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}, new Object[]{1}, new Object[]{3}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 1, "expected 1 element even though fetch is 2 because of max limit");
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{1});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldFetchAllWithNegativeFetch() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, -1, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}, new Object[]{1}, new Object[]{3}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 3);
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldConsumeAndSortTwoInputBlocksWithOneRowEach() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}))
+        .thenReturn(block(schema, new Object[]{1}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 2);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{1});
+    Assert.assertEquals(block.getContainer().get(1), new Object[]{2});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldBreakTiesUsingSecondCollationKey() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"first", "second"}, new DataSchema.ColumnDataType[]{INT, INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{1, 2}, new Object[]{1, 1}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 2);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{1, 1});
+    Assert.assertEquals(block.getContainer().get(1), new Object[]{1, 2});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldHandleNoOpUpstreamBlockWhileConstructing() {
+    // Given:
+    List<RexExpression> collation = collation(0);

Review Comment:
   🤦 I added a test for this (`shouldBreakTiesUsingSecondCollationKey`) but I didn't add the second collation key at all! It passed because of sheer luck haha. Fixed and added a mixed ASCENDING/DESCENDING test



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] siddharthteotia commented on a diff in pull request #9769: [multistage] add test coverage for SortOperator

Posted by GitBox <gi...@apache.org>.
siddharthteotia commented on code in PR #9769:
URL: https://github.com/apache/pinot/pull/9769#discussion_r1018484797


##########
pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/operator/SortOperatorTest.java:
##########
@@ -0,0 +1,363 @@
+/**
+ * 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.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.calcite.rel.RelFieldCollation.Direction;
+import org.apache.pinot.common.datablock.DataBlock;
+import org.apache.pinot.common.utils.DataSchema;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.query.planner.logical.RexExpression;
+import org.apache.pinot.query.runtime.blocks.TransferableBlock;
+import org.apache.pinot.query.runtime.blocks.TransferableBlockUtils;
+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;
+
+import static org.apache.pinot.common.utils.DataSchema.ColumnDataType.INT;
+import static org.apache.pinot.common.utils.DataSchema.ColumnDataType.STRING;
+
+
+public class SortOperatorTest {
+
+  private AutoCloseable _mocks;
+
+  @Mock
+  private Operator<TransferableBlock> _input;
+
+  @BeforeMethod
+  public void setUp() {
+    _mocks = MockitoAnnotations.openMocks(this);
+  }
+
+  @AfterMethod
+  public void tearDown()
+      throws Exception {
+    _mocks.close();
+  }
+
+  @Test
+  public void shouldHandleUpstreamErrorBlock() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(TransferableBlockUtils.getErrorTransferableBlock(new Exception("foo!")));
+
+    // When:
+    TransferableBlock block = op.nextBlock();
+
+    // Then:
+    Assert.assertTrue(block.isErrorBlock(), "expected error block to propagate");
+  }
+
+  @Test
+  public void shouldHandleUpstreamNoOpBlock() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock()).thenReturn(TransferableBlockUtils.getNoOpTransferableBlock());
+
+    // When:
+    TransferableBlock block = op.nextBlock();
+
+    // Then:
+    Assert.assertTrue(block.isNoOpBlock(), "expected noop block to propagate");
+  }
+
+  @Test
+  public void shouldCreateEmptyBlockOnUpstreamEOS() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock()).thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    TransferableBlock block = op.nextBlock();
+
+    // Then:
+    Assert.assertTrue(block.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldConsumeAndSortInputOneBlockWithTwoRows() {

Review Comment:
   Is there any gotcha we are trying to test for `"one block with 2 rows"` scenario ?



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] siddharthteotia commented on a diff in pull request #9769: [multistage] add test coverage for SortOperator

Posted by GitBox <gi...@apache.org>.
siddharthteotia commented on code in PR #9769:
URL: https://github.com/apache/pinot/pull/9769#discussion_r1018484429


##########
pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/operator/SortOperatorTest.java:
##########
@@ -0,0 +1,363 @@
+/**
+ * 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.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.calcite.rel.RelFieldCollation.Direction;
+import org.apache.pinot.common.datablock.DataBlock;
+import org.apache.pinot.common.utils.DataSchema;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.query.planner.logical.RexExpression;
+import org.apache.pinot.query.runtime.blocks.TransferableBlock;
+import org.apache.pinot.query.runtime.blocks.TransferableBlockUtils;
+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;
+
+import static org.apache.pinot.common.utils.DataSchema.ColumnDataType.INT;
+import static org.apache.pinot.common.utils.DataSchema.ColumnDataType.STRING;
+
+
+public class SortOperatorTest {
+
+  private AutoCloseable _mocks;
+
+  @Mock
+  private Operator<TransferableBlock> _input;
+
+  @BeforeMethod
+  public void setUp() {
+    _mocks = MockitoAnnotations.openMocks(this);
+  }
+
+  @AfterMethod
+  public void tearDown()
+      throws Exception {
+    _mocks.close();
+  }
+
+  @Test
+  public void shouldHandleUpstreamErrorBlock() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(TransferableBlockUtils.getErrorTransferableBlock(new Exception("foo!")));
+
+    // When:
+    TransferableBlock block = op.nextBlock();
+
+    // Then:
+    Assert.assertTrue(block.isErrorBlock(), "expected error block to propagate");
+  }
+
+  @Test
+  public void shouldHandleUpstreamNoOpBlock() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock()).thenReturn(TransferableBlockUtils.getNoOpTransferableBlock());
+
+    // When:
+    TransferableBlock block = op.nextBlock();
+
+    // Then:
+    Assert.assertTrue(block.isNoOpBlock(), "expected noop block to propagate");
+  }
+
+  @Test
+  public void shouldCreateEmptyBlockOnUpstreamEOS() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock()).thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    TransferableBlock block = op.nextBlock();
+
+    // Then:
+    Assert.assertTrue(block.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldConsumeAndSortInputOneBlockWithTwoRows() {

Review Comment:
   I may be missing something. Curious why this test is specialized for 2 rows ?



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] walterddr commented on a diff in pull request #9769: [multistage] add test coverage for SortOperator

Posted by GitBox <gi...@apache.org>.
walterddr commented on code in PR #9769:
URL: https://github.com/apache/pinot/pull/9769#discussion_r1019308867


##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/SortOperator.java:
##########
@@ -52,14 +52,23 @@ public class SortOperator extends BaseOperator<TransferableBlock> {
 
   public SortOperator(Operator<TransferableBlock> upstreamOperator, List<RexExpression> collationKeys,
       List<RelFieldCollation.Direction> collationDirections, int fetch, int offset, DataSchema dataSchema) {
+    this(upstreamOperator, collationKeys, collationDirections, fetch, offset, dataSchema,
+        SelectionOperatorUtils.MAX_ROW_HOLDER_INITIAL_CAPACITY);
+  }
+
+  @VisibleForTesting
+  SortOperator(Operator<TransferableBlock> upstreamOperator, List<RexExpression> collationKeys,
+      List<RelFieldCollation.Direction> collationDirections, int fetch, int offset, DataSchema dataSchema,
+      int maxHolderCapacity) {

Review Comment:
   +1. good idea to test configurable constrains



##########
pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/operator/SortOperatorTest.java:
##########
@@ -0,0 +1,363 @@
+/**
+ * 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.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.calcite.rel.RelFieldCollation.Direction;
+import org.apache.pinot.common.datablock.DataBlock;
+import org.apache.pinot.common.utils.DataSchema;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.query.planner.logical.RexExpression;
+import org.apache.pinot.query.runtime.blocks.TransferableBlock;
+import org.apache.pinot.query.runtime.blocks.TransferableBlockUtils;
+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;
+
+import static org.apache.pinot.common.utils.DataSchema.ColumnDataType.INT;
+import static org.apache.pinot.common.utils.DataSchema.ColumnDataType.STRING;
+
+
+public class SortOperatorTest {
+
+  private AutoCloseable _mocks;
+
+  @Mock
+  private Operator<TransferableBlock> _input;
+
+  @BeforeMethod
+  public void setUp() {
+    _mocks = MockitoAnnotations.openMocks(this);
+  }
+
+  @AfterMethod
+  public void tearDown()
+      throws Exception {
+    _mocks.close();
+  }
+
+  @Test
+  public void shouldHandleUpstreamErrorBlock() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(TransferableBlockUtils.getErrorTransferableBlock(new Exception("foo!")));
+
+    // When:
+    TransferableBlock block = op.nextBlock();
+
+    // Then:
+    Assert.assertTrue(block.isErrorBlock(), "expected error block to propagate");
+  }
+
+  @Test
+  public void shouldHandleUpstreamNoOpBlock() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock()).thenReturn(TransferableBlockUtils.getNoOpTransferableBlock());
+
+    // When:
+    TransferableBlock block = op.nextBlock();
+
+    // Then:
+    Assert.assertTrue(block.isNoOpBlock(), "expected noop block to propagate");
+  }
+
+  @Test
+  public void shouldCreateEmptyBlockOnUpstreamEOS() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock()).thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    TransferableBlock block = op.nextBlock();
+
+    // Then:
+    Assert.assertTrue(block.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldConsumeAndSortInputOneBlockWithTwoRows() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}, new Object[]{1}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 2);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{1});
+    Assert.assertEquals(block.getContainer().get(1), new Object[]{2});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldConsumeAndSortInputOneBlockWithTwoRowsNonNumeric() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{STRING});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{"b"}, new Object[]{"a"}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 2);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{"a"});
+    Assert.assertEquals(block.getContainer().get(1), new Object[]{"b"});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldConsumeAndSortDescending() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.DESCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}, new Object[]{1}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 2);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{2});
+    Assert.assertEquals(block.getContainer().get(1), new Object[]{1});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldOffsetSortInputOneBlockWithThreeRows() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 1, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}, new Object[]{1}, new Object[]{3}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 2);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{2});
+    Assert.assertEquals(block.getContainer().get(1), new Object[]{3});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldOffsetLimitSortInputOneBlockWithThreeRows() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 1, 1, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}, new Object[]{1}, new Object[]{3}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 1);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{2});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldRespectMaxLimit() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 2, 0, schema, 1);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}, new Object[]{1}, new Object[]{3}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 1, "expected 1 element even though fetch is 2 because of max limit");
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{1});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldFetchAllWithNegativeFetch() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, -1, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}, new Object[]{1}, new Object[]{3}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 3);
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldConsumeAndSortTwoInputBlocksWithOneRowEach() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}))
+        .thenReturn(block(schema, new Object[]{1}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 2);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{1});
+    Assert.assertEquals(block.getContainer().get(1), new Object[]{2});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldBreakTiesUsingSecondCollationKey() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"first", "second"}, new DataSchema.ColumnDataType[]{INT, INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{1, 2}, new Object[]{1, 1}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 2);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{1, 1});
+    Assert.assertEquals(block.getContainer().get(1), new Object[]{1, 2});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldHandleNoOpUpstreamBlockWhileConstructing() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}))
+        .thenReturn(TransferableBlockUtils.getNoOpTransferableBlock())
+        .thenReturn(block(schema, new Object[]{1}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    op.nextBlock(); // consume and do nothing
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 2);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{1});
+    Assert.assertEquals(block.getContainer().get(1), new Object[]{2});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  private static List<RexExpression> collation(int... indexes) {
+    return Arrays.stream(indexes).mapToObj(RexExpression.InputRef::new).collect(Collectors.toList());
+  }

Review Comment:
   i am pretty sure but can we test collation indexes that are not the beginning one?



##########
pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/operator/SortOperatorTest.java:
##########
@@ -0,0 +1,363 @@
+/**
+ * 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.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.calcite.rel.RelFieldCollation.Direction;
+import org.apache.pinot.common.datablock.DataBlock;
+import org.apache.pinot.common.utils.DataSchema;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.query.planner.logical.RexExpression;
+import org.apache.pinot.query.runtime.blocks.TransferableBlock;
+import org.apache.pinot.query.runtime.blocks.TransferableBlockUtils;
+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;
+
+import static org.apache.pinot.common.utils.DataSchema.ColumnDataType.INT;
+import static org.apache.pinot.common.utils.DataSchema.ColumnDataType.STRING;
+
+
+public class SortOperatorTest {
+
+  private AutoCloseable _mocks;
+
+  @Mock
+  private Operator<TransferableBlock> _input;
+
+  @BeforeMethod
+  public void setUp() {
+    _mocks = MockitoAnnotations.openMocks(this);
+  }
+
+  @AfterMethod
+  public void tearDown()
+      throws Exception {
+    _mocks.close();
+  }
+
+  @Test
+  public void shouldHandleUpstreamErrorBlock() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(TransferableBlockUtils.getErrorTransferableBlock(new Exception("foo!")));
+
+    // When:
+    TransferableBlock block = op.nextBlock();
+
+    // Then:
+    Assert.assertTrue(block.isErrorBlock(), "expected error block to propagate");
+  }
+
+  @Test
+  public void shouldHandleUpstreamNoOpBlock() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock()).thenReturn(TransferableBlockUtils.getNoOpTransferableBlock());
+
+    // When:
+    TransferableBlock block = op.nextBlock();
+
+    // Then:
+    Assert.assertTrue(block.isNoOpBlock(), "expected noop block to propagate");
+  }
+
+  @Test
+  public void shouldCreateEmptyBlockOnUpstreamEOS() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock()).thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    TransferableBlock block = op.nextBlock();
+
+    // Then:
+    Assert.assertTrue(block.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldConsumeAndSortInputOneBlockWithTwoRows() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}, new Object[]{1}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 2);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{1});
+    Assert.assertEquals(block.getContainer().get(1), new Object[]{2});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldConsumeAndSortInputOneBlockWithTwoRowsNonNumeric() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{STRING});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{"b"}, new Object[]{"a"}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 2);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{"a"});
+    Assert.assertEquals(block.getContainer().get(1), new Object[]{"b"});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldConsumeAndSortDescending() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.DESCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}, new Object[]{1}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 2);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{2});
+    Assert.assertEquals(block.getContainer().get(1), new Object[]{1});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldOffsetSortInputOneBlockWithThreeRows() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 1, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}, new Object[]{1}, new Object[]{3}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 2);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{2});
+    Assert.assertEquals(block.getContainer().get(1), new Object[]{3});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldOffsetLimitSortInputOneBlockWithThreeRows() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 1, 1, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}, new Object[]{1}, new Object[]{3}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 1);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{2});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldRespectMaxLimit() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 2, 0, schema, 1);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}, new Object[]{1}, new Object[]{3}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 1, "expected 1 element even though fetch is 2 because of max limit");
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{1});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldFetchAllWithNegativeFetch() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, -1, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}, new Object[]{1}, new Object[]{3}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 3);
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldConsumeAndSortTwoInputBlocksWithOneRowEach() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{2}))
+        .thenReturn(block(schema, new Object[]{1}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 2);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{1});
+    Assert.assertEquals(block.getContainer().get(1), new Object[]{2});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldBreakTiesUsingSecondCollationKey() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"first", "second"}, new DataSchema.ColumnDataType[]{INT, INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(block(schema, new Object[]{1, 2}, new Object[]{1, 1}))
+        .thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    op.nextBlock(); // consume, create NOOP
+    TransferableBlock block = op.nextBlock(); // construct
+    TransferableBlock block2 = op.nextBlock(); // eos
+
+    // Then:
+    Assert.assertEquals(block.getNumRows(), 2);
+    Assert.assertEquals(block.getContainer().get(0), new Object[]{1, 1});
+    Assert.assertEquals(block.getContainer().get(1), new Object[]{1, 2});
+    Assert.assertTrue(block2.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldHandleNoOpUpstreamBlockWhileConstructing() {
+    // Given:
+    List<RexExpression> collation = collation(0);

Review Comment:
   need a multiple collation test. 
   need a multiple collation and multiple ASCENDING/DESCENDING direction mix



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] codecov-commenter commented on pull request #9769: [multistage] add test coverage for SortOperator

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #9769:
URL: https://github.com/apache/pinot/pull/9769#issuecomment-1309242969

   # [Codecov](https://codecov.io/gh/apache/pinot/pull/9769?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#9769](https://codecov.io/gh/apache/pinot/pull/9769?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (ca45643) into [master](https://codecov.io/gh/apache/pinot/commit/8c9af20c3feaf9b54f129b7923728fc08fa205a5?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (8c9af20) will **decrease** coverage by `48.34%`.
   > The diff coverage is `100.00%`.
   
   ```diff
   @@              Coverage Diff              @@
   ##             master    #9769       +/-   ##
   =============================================
   - Coverage     64.02%   15.68%   -48.35%     
   + Complexity     4953      175     -4778     
   =============================================
     Files          1902     1902               
     Lines        102463   102466        +3     
     Branches      15587    15587               
   =============================================
   - Hits          65607    16072    -49535     
   - Misses        32088    85203    +53115     
   + Partials       4768     1191     -3577     
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | unittests1 | `?` | |
   | unittests2 | `15.68% <100.00%> (+<0.01%)` | :arrow_up: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://codecov.io/gh/apache/pinot/pull/9769?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...inot/query/runtime/operator/AggregateOperator.java](https://codecov.io/gh/apache/pinot/pull/9769/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtcXVlcnktcnVudGltZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcnVudGltZS9vcGVyYXRvci9BZ2dyZWdhdGVPcGVyYXRvci5qYXZh) | `97.22% <100.00%> (+1.85%)` | :arrow_up: |
   | [...che/pinot/query/runtime/operator/SortOperator.java](https://codecov.io/gh/apache/pinot/pull/9769/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtcXVlcnktcnVudGltZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcnVudGltZS9vcGVyYXRvci9Tb3J0T3BlcmF0b3IuamF2YQ==) | `93.33% <100.00%> (+7.22%)` | :arrow_up: |
   | [...src/main/java/org/apache/pinot/sql/FilterKind.java](https://codecov.io/gh/apache/pinot/pull/9769/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcWwvRmlsdGVyS2luZC5qYXZh) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...ain/java/org/apache/pinot/core/data/table/Key.java](https://codecov.io/gh/apache/pinot/pull/9769/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvY29yZS9kYXRhL3RhYmxlL0tleS5qYXZh) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...in/java/org/apache/pinot/spi/utils/BytesUtils.java](https://codecov.io/gh/apache/pinot/pull/9769/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvdXRpbHMvQnl0ZXNVdGlscy5qYXZh) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...n/java/org/apache/pinot/core/data/table/Table.java](https://codecov.io/gh/apache/pinot/pull/9769/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvY29yZS9kYXRhL3RhYmxlL1RhYmxlLmphdmE=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [.../java/org/apache/pinot/core/data/table/Record.java](https://codecov.io/gh/apache/pinot/pull/9769/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvY29yZS9kYXRhL3RhYmxlL1JlY29yZC5qYXZh) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [.../java/org/apache/pinot/core/util/GroupByUtils.java](https://codecov.io/gh/apache/pinot/pull/9769/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvY29yZS91dGlsL0dyb3VwQnlVdGlscy5qYXZh) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...java/org/apache/pinot/spi/trace/BaseRecording.java](https://codecov.io/gh/apache/pinot/pull/9769/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvdHJhY2UvQmFzZVJlY29yZGluZy5qYXZh) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...java/org/apache/pinot/spi/trace/NoOpRecording.java](https://codecov.io/gh/apache/pinot/pull/9769/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvdHJhY2UvTm9PcFJlY29yZGluZy5qYXZh) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | ... and [1207 more](https://codecov.io/gh/apache/pinot/pull/9769/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] agavra commented on a diff in pull request #9769: [multistage] add test coverage for SortOperator

Posted by GitBox <gi...@apache.org>.
agavra commented on code in PR #9769:
URL: https://github.com/apache/pinot/pull/9769#discussion_r1018514840


##########
pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/operator/SortOperatorTest.java:
##########
@@ -0,0 +1,363 @@
+/**
+ * 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.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.calcite.rel.RelFieldCollation.Direction;
+import org.apache.pinot.common.datablock.DataBlock;
+import org.apache.pinot.common.utils.DataSchema;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.query.planner.logical.RexExpression;
+import org.apache.pinot.query.runtime.blocks.TransferableBlock;
+import org.apache.pinot.query.runtime.blocks.TransferableBlockUtils;
+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;
+
+import static org.apache.pinot.common.utils.DataSchema.ColumnDataType.INT;
+import static org.apache.pinot.common.utils.DataSchema.ColumnDataType.STRING;
+
+
+public class SortOperatorTest {
+
+  private AutoCloseable _mocks;
+
+  @Mock
+  private Operator<TransferableBlock> _input;
+
+  @BeforeMethod
+  public void setUp() {
+    _mocks = MockitoAnnotations.openMocks(this);
+  }
+
+  @AfterMethod
+  public void tearDown()
+      throws Exception {
+    _mocks.close();
+  }
+
+  @Test
+  public void shouldHandleUpstreamErrorBlock() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock())
+        .thenReturn(TransferableBlockUtils.getErrorTransferableBlock(new Exception("foo!")));
+
+    // When:
+    TransferableBlock block = op.nextBlock();
+
+    // Then:
+    Assert.assertTrue(block.isErrorBlock(), "expected error block to propagate");
+  }
+
+  @Test
+  public void shouldHandleUpstreamNoOpBlock() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock()).thenReturn(TransferableBlockUtils.getNoOpTransferableBlock());
+
+    // When:
+    TransferableBlock block = op.nextBlock();
+
+    // Then:
+    Assert.assertTrue(block.isNoOpBlock(), "expected noop block to propagate");
+  }
+
+  @Test
+  public void shouldCreateEmptyBlockOnUpstreamEOS() {
+    // Given:
+    List<RexExpression> collation = collation(0);
+    List<Direction> directions = ImmutableList.of(Direction.ASCENDING);
+    DataSchema schema = new DataSchema(new String[]{"sort"}, new DataSchema.ColumnDataType[]{INT});
+    SortOperator op = new SortOperator(_input, collation, directions, 10, 0, schema);
+
+    Mockito.when(_input.nextBlock()).thenReturn(TransferableBlockUtils.getEndOfStreamTransferableBlock());
+
+    // When:
+    TransferableBlock block = op.nextBlock();
+
+    // Then:
+    Assert.assertTrue(block.isEndOfStreamBlock(), "expected EOS block to propagate");
+  }
+
+  @Test
+  public void shouldConsumeAndSortInputOneBlockWithTwoRows() {

Review Comment:
   yeah - it's essentially testing that it doesn't matter how the rows are distributed amongst the blocks (it's a combine/reduce operator). I could combine it into one test that has `two blocks with two rows each` to cover all that functionality, but this way if one of this or the next test fails we'd know exactly what broke.
   
   let me know if that clarifies



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] 61yao commented on a diff in pull request #9769: [multistage] add test coverage for SortOperator

Posted by GitBox <gi...@apache.org>.
61yao commented on code in PR #9769:
URL: https://github.com/apache/pinot/pull/9769#discussion_r1019440383


##########
pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/operator/AggregateOperatorTest.java:
##########
@@ -249,6 +250,31 @@ public void shouldThrowOnUnknownAggFunction() {
     AggregateOperator operator = new AggregateOperator(_input, outSchema, calls, group);
   }
 
+  @Test
+  public void shouldReturnErrorBlockOnUnexpectedInputType() {

Review Comment:
   Thanks for adding this!



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org