diff --git a/pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/operator/LiteralValueOperatorTest.java b/pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/operator/LiteralValueOperatorTest.java new file mode 100644 index 000000000000..663caf2272de --- /dev/null +++ b/pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/operator/LiteralValueOperatorTest.java @@ -0,0 +1,71 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.query.runtime.operator; + +import com.google.common.collect.ImmutableList; +import java.util.List; +import org.apache.pinot.common.utils.DataSchema; +import org.apache.pinot.common.utils.DataSchema.ColumnDataType; +import org.apache.pinot.query.planner.logical.RexExpression; +import org.apache.pinot.query.runtime.blocks.TransferableBlock; +import org.apache.pinot.spi.data.FieldSpec.DataType; +import org.testng.Assert; +import org.testng.annotations.Test; + + +public class LiteralValueOperatorTest { + + @Test + public void shouldReturnLiteralBlock() { + // Given: + DataSchema schema = new DataSchema(new String[]{"sLiteral", "iLiteral"}, + new ColumnDataType[]{ColumnDataType.STRING, ColumnDataType.INT}); + List> literals = ImmutableList.of( + ImmutableList.of( + new RexExpression.Literal(DataType.STRING, "foo"), + new RexExpression.Literal(DataType.INT, 1)), + ImmutableList.of( + new RexExpression.Literal(DataType.STRING, ""), + new RexExpression.Literal(DataType.INT, 2)) + ); + LiteralValueOperator operator = new LiteralValueOperator(schema, literals); + + // When: + TransferableBlock transferableBlock = operator.nextBlock(); + + // Then: + Assert.assertEquals(transferableBlock.getContainer().get(0), new Object[]{"foo", 1}); + Assert.assertEquals(transferableBlock.getContainer().get(1), new Object[]{"", 2}); + Assert.assertTrue(operator.nextBlock().isEndOfStreamBlock(), "Expected EOS after reading two rows"); + } + + @Test + public void shouldHandleEmptyLiteralRows() { + // Given: + DataSchema schema = new DataSchema(new String[]{}, new ColumnDataType[]{}); + List> literals = ImmutableList.of(ImmutableList.of()); + LiteralValueOperator operator = new LiteralValueOperator(schema, literals); + + // When: + TransferableBlock transferableBlock = operator.nextBlock(); + + // Then: + Assert.assertEquals(transferableBlock.getContainer().get(0), new Object[]{}); + } +}