use of io.trino.spi.type.ArrayType in project trino by trinodb.
the class TestScalarParser method testGenericWithIncompleteSpecialization.
@Test
public void testGenericWithIncompleteSpecialization() {
assertFunction("generic_incomplete_specialization_nullable(9876543210)", BIGINT, 9876543210L);
assertFunction("generic_incomplete_specialization_nullable(1.234E0)", DOUBLE, 1.234);
assertFunction("generic_incomplete_specialization_nullable('abcd')", createVarcharType(4), "abcd");
assertFunction("generic_incomplete_specialization_nullable(true)", BOOLEAN, true);
assertFunction("generic_incomplete_specialization_nullable(array[1, 2])", new ArrayType(INTEGER), ImmutableList.of(1, 2));
assertFunction("generic_incomplete_specialization_not_nullable(9876543210)", BIGINT, 9876543210L);
assertFunction("generic_incomplete_specialization_not_nullable(1.234E0)", DOUBLE, 1.234);
assertFunction("generic_incomplete_specialization_not_nullable('abcd')", createVarcharType(4), "abcd");
assertFunction("generic_incomplete_specialization_not_nullable(true)", BOOLEAN, true);
assertFunction("generic_incomplete_specialization_not_nullable(array[1, 2])", new ArrayType(INTEGER), ImmutableList.of(1, 2));
}
use of io.trino.spi.type.ArrayType in project trino by trinodb.
the class TestStringFunctions method testSplit.
@Test
public void testSplit() {
assertFunction("SPLIT('a.b.c', '.')", new ArrayType(createVarcharType(5)), ImmutableList.of("a", "b", "c"));
assertFunction("SPLIT('ab', '.', 1)", new ArrayType(createVarcharType(2)), ImmutableList.of("ab"));
assertFunction("SPLIT('a.b', '.', 1)", new ArrayType(createVarcharType(3)), ImmutableList.of("a.b"));
assertFunction("SPLIT('a.b.c', '.')", new ArrayType(createVarcharType(5)), ImmutableList.of("a", "b", "c"));
assertFunction("SPLIT('a..b..c', '..')", new ArrayType(createVarcharType(7)), ImmutableList.of("a", "b", "c"));
assertFunction("SPLIT('a.b.c', '.', 2)", new ArrayType(createVarcharType(5)), ImmutableList.of("a", "b.c"));
assertFunction("SPLIT('a.b.c', '.', 3)", new ArrayType(createVarcharType(5)), ImmutableList.of("a", "b", "c"));
assertFunction("SPLIT('a.b.c', '.', 4)", new ArrayType(createVarcharType(5)), ImmutableList.of("a", "b", "c"));
assertFunction("SPLIT('a.b.c.', '.', 4)", new ArrayType(createVarcharType(6)), ImmutableList.of("a", "b", "c", ""));
assertFunction("SPLIT('a.b.c.', '.', 3)", new ArrayType(createVarcharType(6)), ImmutableList.of("a", "b", "c."));
assertFunction("SPLIT('...', '.')", new ArrayType(createVarcharType(3)), ImmutableList.of("", "", "", ""));
assertFunction("SPLIT('..a...a..', '.')", new ArrayType(createVarcharType(9)), ImmutableList.of("", "", "a", "", "", "a", "", ""));
// Test SPLIT for non-ASCII
assertFunction("SPLIT('\u4FE1\u5FF5,\u7231,\u5E0C\u671B', ',', 3)", new ArrayType(createVarcharType(7)), ImmutableList.of("\u4FE1\u5FF5", "\u7231", "\u5E0C\u671B"));
assertFunction("SPLIT('\u8B49\u8BC1\u8A3C', '\u8BC1', 2)", new ArrayType(createVarcharType(3)), ImmutableList.of("\u8B49", "\u8A3C"));
assertFunction("SPLIT('.a.b.c', '.', 4)", new ArrayType(createVarcharType(6)), ImmutableList.of("", "a", "b", "c"));
assertFunction("SPLIT('.a.b.c', '.', 3)", new ArrayType(createVarcharType(6)), ImmutableList.of("", "a", "b.c"));
assertFunction("SPLIT('.a.b.c', '.', 2)", new ArrayType(createVarcharType(6)), ImmutableList.of("", "a.b.c"));
assertFunction("SPLIT('a..b..c', '.', 3)", new ArrayType(createVarcharType(7)), ImmutableList.of("a", "", "b..c"));
assertFunction("SPLIT('a.b..', '.', 3)", new ArrayType(createVarcharType(5)), ImmutableList.of("a", "b", "."));
assertInvalidFunction("SPLIT('a.b.c', '', 1)", "The delimiter may not be the empty string");
assertInvalidFunction("SPLIT('a.b.c', '.', 0)", "Limit must be positive");
assertInvalidFunction("SPLIT('a.b.c', '.', -1)", "Limit must be positive");
assertInvalidFunction("SPLIT('a.b.c', '.', 2147483648)", "Limit is too large");
}
use of io.trino.spi.type.ArrayType in project trino by trinodb.
the class TestUnnestOperator method testUnnest.
@Test
public void testUnnest() {
Type arrayType = new ArrayType(BIGINT);
Type mapType = TESTING_TYPE_MANAGER.getType(mapType(BIGINT.getTypeSignature(), BIGINT.getTypeSignature()));
List<Page> input = rowPagesBuilder(BIGINT, arrayType, mapType).row(1L, arrayBlockOf(BIGINT, 2, 3), mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(4, 5))).row(2L, arrayBlockOf(BIGINT, 99), null).row(3L, null, null).pageBreak().row(6L, arrayBlockOf(BIGINT, 7, 8), mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(9, 10, 11, 12))).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, BIGINT, BIGINT, BIGINT).row(1L, 2L, 4L, 5L).row(1L, 3L, null, null).row(2L, 99L, null, null).row(6L, 7L, 9L, 10L).row(6L, 8L, 11L, 12L).build();
assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
use of io.trino.spi.type.ArrayType in project trino by trinodb.
the class TestUnnestOperator method testOuterUnnestWithOrdinality.
@Test
public void testOuterUnnestWithOrdinality() {
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, 6, 7)), arrayBlockOf(BIGINT, 3), arrayBlockOf(elementType, ImmutableList.of(4, 5.5, "a"))).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), true, true);
MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, BIGINT, BIGINT, BIGINT, BIGINT, DOUBLE, VARCHAR, BIGINT).row(1L, 1L, 2L, 3L, 4L, 5.5, "a", 1L).row(1L, 6L, 7L, null, null, null, null, 2L).row(2L, null, null, null, null, null, null, null).row(3L, null, 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 TestUnnestOperator method testUnnestWithOrdinality.
@Test
public void testUnnestWithOrdinality() {
Type arrayType = new ArrayType(BIGINT);
Type mapType = TESTING_TYPE_MANAGER.getType(mapType(BIGINT.getTypeSignature(), BIGINT.getTypeSignature()));
List<Page> input = rowPagesBuilder(BIGINT, arrayType, mapType).row(1L, arrayBlockOf(BIGINT, 2, 3), mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(4, 5))).row(2L, arrayBlockOf(BIGINT, 99), null).row(3L, null, null).pageBreak().row(6L, arrayBlockOf(BIGINT, 7, 8), mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(9, 10, 11, 12))).build();
OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2), ImmutableList.of(arrayType, mapType), true, false);
MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, BIGINT, BIGINT, BIGINT, BIGINT).row(1L, 2L, 4L, 5L, 1L).row(1L, 3L, null, null, 2L).row(2L, 99L, null, null, 1L).row(6L, 7L, 9L, 10L, 1L).row(6L, 8L, 11L, 12L, 2L).build();
assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Aggregations