Skip to content

Commit

Permalink
Fix null parameter declaration in listagg
Browse files Browse the repository at this point in the history
  • Loading branch information
dain committed May 27, 2022
1 parent a5cdc4d commit 5f90789
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ private ListaggAggregationFunction()
.argumentType(BOOLEAN)
.build())
.nullable()
.argumentNullability(true, false, false, false, false)
.description("concatenates the input values with the specified separator")
.build(),
AggregationFunctionMetadata.builder()
Expand Down Expand Up @@ -134,9 +133,7 @@ public static void input(Type type, ListaggAggregationState state, Block value,
state.setOverflowFiller(overflowFiller);
state.setShowOverflowEntryCount(showOverflowEntryCount);
}
if (!value.isNull(position)) {
state.add(value, position);
}
state.add(value, position);
}

public static void combine(Type type, ListaggAggregationState state, ListaggAggregationState otherState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,36 @@

import io.airlift.slice.Slice;
import io.trino.block.BlockAssertions;
import io.trino.metadata.TestingFunctionResolution;
import io.trino.spi.TrinoException;
import io.trino.spi.block.Block;
import io.trino.spi.block.BlockBuilder;
import io.trino.spi.block.VariableWidthBlockBuilder;
import io.trino.sql.analyzer.TypeSignatureProvider;
import io.trino.sql.tree.QualifiedName;
import org.testcontainers.shaded.org.apache.commons.lang.StringUtils;
import org.testng.annotations.Test;

import java.util.List;

import static io.airlift.slice.Slices.utf8Slice;
import static io.trino.block.BlockAssertions.createBooleansBlock;
import static io.trino.block.BlockAssertions.createStringsBlock;
import static io.trino.operator.aggregation.AggregationTestUtils.assertAggregation;
import static io.trino.spi.StandardErrorCode.EXCEEDED_FUNCTION_MEMORY_LIMIT;
import static io.trino.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT;
import static io.trino.spi.type.BooleanType.BOOLEAN;
import static io.trino.spi.type.VarcharType.VARCHAR;
import static io.trino.sql.analyzer.TypeSignatureProvider.fromTypes;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

public class TestListaggAggregationFunction
{
private static final TestingFunctionResolution FUNCTION_RESOLUTION = new TestingFunctionResolution();

@Test
public void testInputEmptyState()
{
Expand Down Expand Up @@ -206,6 +217,32 @@ public void testOutputTruncatedStateWithIndicationCountComplexSeparator()
assertEquals(getOutputStateOnlyValue(state, 21), "a###b###c###dd###e###...(7)");
}

@Test
public void testExecute()
{
List<TypeSignatureProvider> parameterTypes = fromTypes(VARCHAR, VARCHAR, BOOLEAN, VARCHAR, BOOLEAN);
assertAggregation(
FUNCTION_RESOLUTION,
QualifiedName.of("listagg"),
parameterTypes,
null,
createStringsBlock(null, null, null),
createStringsBlock(",", ",", ","),
createBooleansBlock(false, false, false),
createStringsBlock("", "", ""),
createBooleansBlock(false, false, false));
assertAggregation(
FUNCTION_RESOLUTION,
QualifiedName.of("listagg"),
parameterTypes,
"a,c",
createStringsBlock("a", null, "c"),
createStringsBlock(",", ",", ","),
createBooleansBlock(false, false, false),
createStringsBlock("", "", ""),
createBooleansBlock(false, false, false));
}

private static String getOutputStateOnlyValue(SingleListaggAggregationState state, int maxOutputLengthInBytes)
{
BlockBuilder out = new VariableWidthBlockBuilder(null, 32, 256);
Expand Down

0 comments on commit 5f90789

Please sign in to comment.