use of io.trino.spi.type.ArrayType in project trino by trinodb.
the class TestUnnestOperator method testUnnestNonNumericDoubles.
@Test
public void testUnnestNonNumericDoubles() {
Type arrayType = new ArrayType(DOUBLE);
Type mapType = TESTING_TYPE_MANAGER.getType(mapType(BIGINT.getTypeSignature(), BIGINT.getTypeSignature()));
List<Page> input = rowPagesBuilder(BIGINT, arrayType, mapType).row(1L, arrayBlockOf(DOUBLE, NEGATIVE_INFINITY, POSITIVE_INFINITY, NaN), mapBlockOf(BIGINT, DOUBLE, ImmutableMap.of(1, NEGATIVE_INFINITY, 2, POSITIVE_INFINITY, 3, NaN))).build();
OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2), ImmutableList.of(arrayType, mapType), false, false);
MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, DOUBLE, BIGINT, DOUBLE).row(1L, NEGATIVE_INFINITY, 1L, NEGATIVE_INFINITY).row(1L, POSITIVE_INFINITY, 2L, POSITIVE_INFINITY).row(1L, NaN, 3L, NaN).build();
assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
use of io.trino.spi.type.ArrayType in project trino by trinodb.
the class TestUnnestOperator method testOuterUnnest.
@Test
public void testOuterUnnest() {
Type mapType = TESTING_TYPE_MANAGER.getType(mapType(BIGINT.getTypeSignature(), BIGINT.getTypeSignature()));
Type arrayType = new ArrayType(BIGINT);
Type elementType = RowType.anonymous(ImmutableList.of(BIGINT, DOUBLE, VARCHAR));
Type arrayOfRowType = new ArrayType(elementType);
List<Page> input = rowPagesBuilder(BIGINT, mapType, arrayType, arrayOfRowType).row(1, mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(1, 2)), arrayBlockOf(BIGINT, 3), arrayBlockOf(elementType, ImmutableList.of(4, 5.5, "a"), ImmutableList.of(6, 7.7, "b"))).row(2, null, null, null).pageBreak().row(3, null, null, null).build();
OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2, 3), ImmutableList.of(mapType, arrayType, arrayOfRowType), false, true);
MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, BIGINT, BIGINT, BIGINT, BIGINT, DOUBLE, VARCHAR).row(1L, 1L, 2L, 3L, 4L, 5.5, "a").row(1L, null, null, null, 6L, 7.7, "b").row(2L, null, null, null, null, null, null).row(3L, null, null, null, null, null, null).build();
assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
use of io.trino.spi.type.ArrayType in project trino by trinodb.
the class TestingUnnesterUtil method createArrayBlock.
public static Block createArrayBlock(Slice[][] values) {
ArrayType arrayType = new ArrayType(VARCHAR);
BlockBuilder blockBuilder = arrayType.createBlockBuilder(null, 100, 100);
for (Slice[] expectedValue : values) {
if (expectedValue == null) {
blockBuilder.appendNull();
} else {
arrayType.writeObject(blockBuilder, createSimpleBlock(expectedValue));
}
}
return blockBuilder.build();
}
use of io.trino.spi.type.ArrayType in project trino by trinodb.
the class TestingUnnesterUtil method createArrayBlockOfRowBlocks.
public static Block createArrayBlockOfRowBlocks(Slice[][][] elements, RowType rowType) {
ArrayType arrayType = new ArrayType(rowType);
BlockBuilder arrayBlockBuilder = arrayType.createBlockBuilder(null, 100, 100);
for (int i = 0; i < elements.length; i++) {
if (elements[i] == null) {
arrayBlockBuilder.appendNull();
} else {
Slice[][] expectedValues = elements[i];
BlockBuilder elementBlockBuilder = rowType.createBlockBuilder(null, elements[i].length);
for (Slice[] expectedValue : expectedValues) {
if (expectedValue == null) {
elementBlockBuilder.appendNull();
} else {
BlockBuilder entryBuilder = elementBlockBuilder.beginBlockEntry();
for (Slice v : expectedValue) {
if (v == null) {
entryBuilder.appendNull();
} else {
VARCHAR.writeSlice(entryBuilder, v);
}
}
elementBlockBuilder.closeEntry();
}
}
arrayType.writeObject(arrayBlockBuilder, elementBlockBuilder.build());
}
}
return arrayBlockBuilder.build();
}
use of io.trino.spi.type.ArrayType in project trino by trinodb.
the class TestZipWithFunction method testSameLength.
@Test
public void testSameLength() {
assertFunction("zip_with(ARRAY[], ARRAY[], (x, y) -> (y, x))", new ArrayType(RowType.anonymous(ImmutableList.of(UNKNOWN, UNKNOWN))), ImmutableList.of());
assertFunction("zip_with(ARRAY[1, 2], ARRAY['a', 'b'], (x, y) -> (y, x))", new ArrayType(RowType.anonymous(ImmutableList.of(createVarcharType(1), INTEGER))), ImmutableList.of(ImmutableList.of("a", 1), ImmutableList.of("b", 2)));
assertFunction("zip_with(ARRAY[1, 2], ARRAY[VARCHAR 'a', VARCHAR 'b'], (x, y) -> (y, x))", new ArrayType(RowType.anonymous(ImmutableList.of(VARCHAR, INTEGER))), ImmutableList.of(ImmutableList.of("a", 1), ImmutableList.of("b", 2)));
assertFunction("zip_with(ARRAY[1, 1], ARRAY[1, 2], (x, y) -> x + y)", new ArrayType(INTEGER), ImmutableList.of(2, 3));
assertFunction("zip_with(CAST(ARRAY[3, 5] AS ARRAY(BIGINT)), CAST(ARRAY[1, 2] AS ARRAY(BIGINT)), (x, y) -> x * y)", new ArrayType(BIGINT), ImmutableList.of(3L, 10L));
assertFunction("zip_with(ARRAY[true, false], ARRAY[false, true], (x, y) -> x OR y)", new ArrayType(BOOLEAN), ImmutableList.of(true, true));
assertFunction("zip_with(ARRAY['a', 'b'], ARRAY['c', 'd'], (x, y) -> concat(x, y))", new ArrayType(VARCHAR), ImmutableList.of("ac", "bd"));
assertFunction("zip_with(ARRAY[MAP(ARRAY[CAST ('a' AS VARCHAR)], ARRAY[1]), MAP(ARRAY[VARCHAR 'b'], ARRAY[2])], ARRAY[MAP(ARRAY['c'], ARRAY[3]), MAP()], (x, y) -> map_concat(x, y))", new ArrayType(mapType(VARCHAR, INTEGER)), ImmutableList.of(ImmutableMap.of("a", 1, "c", 3), ImmutableMap.of("b", 2)));
}
Aggregations