use of io.trino.spi.type.ArrayType in project trino by trinodb.
the class TestArrayExceptFunction method testDuplicates.
@Test
public void testDuplicates() {
assertFunction("array_except(ARRAY[1, 5, 3, 5, 1], ARRAY[3])", new ArrayType(INTEGER), ImmutableList.of(1, 5));
assertFunction("array_except(ARRAY[CAST(1 as BIGINT), 5, 5, 3, 3, 3, 1], ARRAY[3, 5])", new ArrayType(BIGINT), ImmutableList.of(1L));
assertFunction("array_except(ARRAY[VARCHAR 'x', 'x', 'y', 'z'], ARRAY['x', 'y', 'x'])", new ArrayType(VARCHAR), ImmutableList.of("z"));
assertFunction("array_except(ARRAY[true, false, null, true, false, null], ARRAY[true, true, true])", new ArrayType(BOOLEAN), asList(false, null));
}
use of io.trino.spi.type.ArrayType in project trino by trinodb.
the class TestArrayFilterFunction method testEmpty.
@Test
public void testEmpty() {
assertFunction("filter(ARRAY [], x -> true)", new ArrayType(UNKNOWN), ImmutableList.of());
assertFunction("filter(ARRAY [], x -> false)", new ArrayType(UNKNOWN), ImmutableList.of());
assertFunction("filter(ARRAY [], x -> CAST (null AS BOOLEAN))", new ArrayType(UNKNOWN), ImmutableList.of());
assertFunction("filter(CAST (ARRAY [] AS ARRAY(INTEGER)), x -> true)", new ArrayType(INTEGER), ImmutableList.of());
}
use of io.trino.spi.type.ArrayType in project trino by trinodb.
the class TestArrayFunctions method testArrayConcat.
@Test
public void testArrayConcat() {
assertFunction("CONCAT(" + Joiner.on(", ").join(nCopies(127, "array[1]")) + ")", new ArrayType(INTEGER), nCopies(127, 1));
assertInvalidFunction("CONCAT(" + Joiner.on(", ").join(nCopies(128, "array[1]")) + ")", TOO_MANY_ARGUMENTS, "line 1:1: Too many arguments for function call concat()");
}
use of io.trino.spi.type.ArrayType in project trino by trinodb.
the class TestArrayFunctions method testArrayConstructor.
@Test
public void testArrayConstructor() {
tryEvaluateWithAll("array[" + Joiner.on(", ").join(nCopies(254, "rand()")) + "]", new ArrayType(DOUBLE));
assertInvalidFunction("array[" + Joiner.on(", ").join(nCopies(255, "rand()")) + "]", TOO_MANY_ARGUMENTS, "Too many arguments for array constructor");
}
use of io.trino.spi.type.ArrayType in project trino by trinodb.
the class TestLambdaExpression method testTypeCombinations.
@Test
public void testTypeCombinations() {
assertFunction("apply(25, x -> x + 1)", INTEGER, 26);
assertFunction("apply(25, x -> x + 1.0E0)", DOUBLE, 26.0);
assertFunction("apply(25, x -> x = 25)", BOOLEAN, true);
assertFunction("apply(25, x -> to_base(x, 16))", createVarcharType(64), "19");
assertFunction("apply(25, x -> ARRAY[x + 1])", new ArrayType(INTEGER), ImmutableList.of(26));
assertFunction("apply(25.6E0, x -> CAST(x AS BIGINT))", BIGINT, 26L);
assertFunction("apply(25.6E0, x -> x + 1.0E0)", DOUBLE, 26.6);
assertFunction("apply(25.6E0, x -> x = 25.6E0)", BOOLEAN, true);
assertFunction("apply(25.6E0, x -> CAST(x AS VARCHAR))", createUnboundedVarcharType(), "2.56E1");
assertFunction("apply(25.6E0, x -> MAP(ARRAY[x + 1], ARRAY[true]))", mapType(DOUBLE, BOOLEAN), ImmutableMap.of(26.6, true));
assertFunction("apply(true, x -> if(x, 25, 26))", INTEGER, 25);
assertFunction("apply(false, x -> if(x, 25.6E0, 28.9E0))", DOUBLE, 28.9);
assertFunction("apply(true, x -> not x)", BOOLEAN, false);
assertFunction("apply(false, x -> CAST(x AS VARCHAR))", createUnboundedVarcharType(), "false");
assertFunction("apply(true, x -> ARRAY[x])", new ArrayType(BOOLEAN), ImmutableList.of(true));
assertFunction("apply('41', x -> from_base(x, 16))", BIGINT, 65L);
assertFunction("apply('25.6E0', x -> CAST(x AS DOUBLE))", DOUBLE, 25.6);
assertFunction("apply('abc', x -> 'abc' = x)", BOOLEAN, true);
assertFunction("apply('abc', x -> x || x)", createUnboundedVarcharType(), "abcabc");
assertFunction("apply('123', x -> ROW(x, CAST(x AS INTEGER), x > '0'))", RowType.anonymous(ImmutableList.of(createVarcharType(3), INTEGER, BOOLEAN)), ImmutableList.of("123", 123, true));
assertFunction("apply(ARRAY['abc', NULL, '123'], x -> from_base(x[3], 10))", BIGINT, 123L);
assertFunction("apply(ARRAY['abc', NULL, '123'], x -> CAST(x[3] AS DOUBLE))", DOUBLE, 123.0);
assertFunction("apply(ARRAY['abc', NULL, '123'], x -> x[2] IS NULL)", BOOLEAN, true);
assertFunction("apply(ARRAY['abc', NULL, '123'], x -> x[2])", createVarcharType(3), null);
assertFunction("apply(MAP(ARRAY['abc', 'def'], ARRAY[123, 456]), x -> map_keys(x))", new ArrayType(createVarcharType(3)), ImmutableList.of("abc", "def"));
}
Aggregations