use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestSignatureBinder method testBindUnknown.
@Test
public void testBindUnknown() {
Signature function = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(parseTypeSignature("varchar(x)", ImmutableSet.of("x"))).build();
assertThat(function).boundTo("unknown").fails();
assertThat(function).boundTo("unknown").withCoercion().succeeds();
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestSignatureBinder method testNoVariableReuseAcrossTypes.
@Test(expectedExceptions = UnsupportedOperationException.class)
public void testNoVariableReuseAcrossTypes() {
Set<String> literalParameters = ImmutableSet.of("p1", "p2", "s");
TypeSignature leftType = parseTypeSignature("decimal(p1,s)", literalParameters);
TypeSignature rightType = parseTypeSignature("decimal(p2,s)", literalParameters);
Signature function = functionSignature().returnType(BOOLEAN.getTypeSignature()).argumentTypes(leftType, rightType).build();
assertThat(function).boundTo("decimal(2,1)", "decimal(3,1)").produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of()));
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestSignatureBinder method testVarArgs.
@Test
public void testVarArgs() {
Signature variableArityFunction = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(parseTypeSignature("T")).typeVariableConstraints(ImmutableList.of(typeVariable("T"))).setVariableArity(true).build();
assertThat(variableArityFunction).boundTo("bigint").produces(new BoundVariables(ImmutableMap.of("T", type("bigint")), ImmutableMap.of()));
assertThat(variableArityFunction).boundTo("varchar").produces(new BoundVariables(ImmutableMap.of("T", type("varchar")), ImmutableMap.of()));
assertThat(variableArityFunction).boundTo("bigint", "bigint").produces(new BoundVariables(ImmutableMap.of("T", type("bigint")), ImmutableMap.of()));
assertThat(variableArityFunction).boundTo("bigint", "varchar").withCoercion().fails();
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestSignatureBinder method testBindLiteralForRepeatedVarcharWithReturn.
@Test
public void testBindLiteralForRepeatedVarcharWithReturn() {
TypeSignature leftType = parseTypeSignature("varchar(x)", ImmutableSet.of("x"));
TypeSignature rightType = parseTypeSignature("varchar(x)", ImmutableSet.of("x"));
Signature function = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(leftType, rightType).build();
assertThat(function).boundTo("varchar(44)", "varchar(44)").produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("x", 44L)));
assertThat(function).boundTo("varchar(44)", "varchar(42)").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("x", 44L)));
assertThat(function).boundTo("varchar(42)", "varchar(44)").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("x", 44L)));
assertThat(function).boundTo("unknown", "varchar(44)").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("x", 44L)));
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestSignatureBinder method testUnknownCoercion.
@Test
public void testUnknownCoercion() {
Signature foo = functionSignature().returnType(parseTypeSignature("boolean")).argumentTypes(parseTypeSignature("T"), parseTypeSignature("T")).typeVariableConstraints(ImmutableList.of(typeVariable("T"))).build();
assertThat(foo).boundTo("unknown", "unknown").produces(new BoundVariables(ImmutableMap.of("T", type("unknown")), ImmutableMap.of()));
assertThat(foo).boundTo("unknown", "bigint").withCoercion().produces(new BoundVariables(ImmutableMap.of("T", type("bigint")), ImmutableMap.of()));
assertThat(foo).boundTo("varchar", "bigint").withCoercion().fails();
Signature bar = functionSignature().returnType(parseTypeSignature("boolean")).argumentTypes(parseTypeSignature("T"), parseTypeSignature("T")).typeVariableConstraints(ImmutableList.of(comparableTypeParameter("T"))).build();
assertThat(bar).boundTo("unknown", "bigint").withCoercion().produces(new BoundVariables(ImmutableMap.of("T", type("bigint")), ImmutableMap.of()));
assertThat(bar).boundTo("varchar", "bigint").withCoercion().fails();
assertThat(bar).boundTo("HyperLogLog", "HyperLogLog").withCoercion().fails();
}
Aggregations