use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestSignatureBinder method testBindUnknownToVariadic.
@Test
public void testBindUnknownToVariadic() {
Signature rowFunction = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(parseTypeSignature("T"), parseTypeSignature("T")).typeVariableConstraints(ImmutableList.of(withVariadicBound("T", "row"))).build();
assertThat(rowFunction).boundTo("unknown", "row(a bigint)").withCoercion().produces(new BoundVariables(ImmutableMap.of("T", type("row(a bigint)")), ImmutableMap.of()));
Signature arrayFunction = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(parseTypeSignature("T"), parseTypeSignature("T")).typeVariableConstraints(ImmutableList.of(withVariadicBound("T", "array"))).build();
assertThat(arrayFunction).boundTo("unknown", "array(bigint)").withCoercion().produces(new BoundVariables(ImmutableMap.of("T", type("array(bigint)")), ImmutableMap.of()));
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestSignatureBinder method testBindTypeVariablesBasedOnTheSecondArgument.
@Test
public void testBindTypeVariablesBasedOnTheSecondArgument() {
Signature function = functionSignature().returnType(parseTypeSignature("T")).argumentTypes(parseTypeSignature("array(T)"), parseTypeSignature("T")).typeVariableConstraints(ImmutableList.of(typeVariable("T"))).build();
assertThat(function).boundTo("unknown", "decimal(2,1)").withCoercion().produces(new BoundVariables(ImmutableMap.of("T", type("decimal(2,1)")), ImmutableMap.of()));
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestSignatureBinder method testBindUnknownToDecimal.
@Test
public void testBindUnknownToDecimal() {
Signature function = functionSignature().returnType(parseTypeSignature("boolean")).argumentTypes(parseTypeSignature("decimal(p,s)", ImmutableSet.of("p", "s"))).build();
assertThat(function).boundTo("unknown").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("p", 1L, "s", 0L)));
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestSignatureBinder method testVariadic.
@Test
public void testVariadic() {
Signature mapVariadicBoundFunction = functionSignature().returnType(parseTypeSignature(StandardTypes.BIGINT)).argumentTypes(parseTypeSignature("T")).typeVariableConstraints(ImmutableList.of(withVariadicBound("T", "map"))).build();
assertThat(mapVariadicBoundFunction).boundTo("map(bigint,bigint)").produces(new BoundVariables(ImmutableMap.of("T", type("map(bigint,bigint)")), ImmutableMap.of()));
assertThat(mapVariadicBoundFunction).boundTo("array(bigint)").fails();
assertThat(mapVariadicBoundFunction).boundTo("array(bigint)").withCoercion().fails();
Signature decimalVariadicBoundFunction = functionSignature().returnType(parseTypeSignature("bigint")).argumentTypes(parseTypeSignature("T")).typeVariableConstraints(ImmutableList.of(withVariadicBound("T", "decimal"))).build();
assertThat(decimalVariadicBoundFunction).boundTo("decimal(2,1)").produces(new BoundVariables(ImmutableMap.of("T", type("decimal(2,1)")), ImmutableMap.of()));
assertThat(decimalVariadicBoundFunction).boundTo("bigint").fails();
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestSignatureBinder method testBindLiteralForVarchar.
@Test
public void testBindLiteralForVarchar() {
TypeSignature leftType = parseTypeSignature("varchar(x)", ImmutableSet.of("x"));
TypeSignature rightType = parseTypeSignature("varchar(y)", ImmutableSet.of("y"));
Signature function = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(leftType, rightType).build();
assertThat(function).boundTo("varchar(42)", "varchar(44)").produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("x", 42L, "y", 44L)));
assertThat(function).boundTo("unknown", "varchar(44)").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("x", 0L, "y", 44L)));
}
Aggregations