use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestSignatureBinder method testBindPartialDecimal.
@Test
public void testBindPartialDecimal() {
Signature function = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(parseTypeSignature("decimal(4,s)", ImmutableSet.of("s"))).build();
assertThat(function).boundTo("decimal(2,1)").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("s", 1L)));
function = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(parseTypeSignature("decimal(p,1)", ImmutableSet.of("p"))).build();
assertThat(function).boundTo("decimal(2,0)").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("p", 3L)));
assertThat(function).boundTo("decimal(2,1)").produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("p", 2L)));
assertThat(function).boundTo("bigint").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("p", 20L)));
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestSignatureBinder method testBindUnknownToConcreteArray.
@Test
public void testBindUnknownToConcreteArray() {
Signature function = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(parseTypeSignature("array(boolean)")).build();
assertThat(function).boundTo("unknown").withCoercion().succeeds();
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestSignatureBinder method testBindVarchar.
@Test
public void testBindVarchar() {
Signature function = functionSignature().returnType(parseTypeSignature("varchar(42)")).argumentTypes(parseTypeSignature("varchar(42)")).build();
assertThat(function).boundTo(ImmutableList.of("varchar(1)"), "varchar(1)").fails();
assertThat(function).boundTo(ImmutableList.of("varchar(1)"), "varchar(1)").withCoercion().fails();
assertThat(function).boundTo(ImmutableList.of("varchar(1)"), "varchar(42)").withCoercion().succeeds();
assertThat(function).boundTo(ImmutableList.of("varchar(44)"), "varchar(44)").withCoercion().fails();
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestSignatureBinder method testRow.
@Test
public void testRow() {
Signature function = functionSignature().returnType(BOOLEAN.getTypeSignature()).argumentTypes(parseTypeSignature("row(integer)")).build();
assertThat(function).boundTo("row(tinyint)").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of()));
assertThat(function).boundTo("row(integer)").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of()));
assertThat(function).boundTo("row(bigint)").withCoercion().fails();
Signature biFunction = functionSignature().returnType(BOOLEAN.getTypeSignature()).argumentTypes(parseTypeSignature("row(T)"), parseTypeSignature("row(T)")).typeVariableConstraints(ImmutableList.of(typeVariable("T"))).build();
assertThat(biFunction).boundTo("row(bigint)", "row(bigint)").withCoercion().produces(new BoundVariables(ImmutableMap.of("T", type("bigint")), ImmutableMap.of()));
assertThat(biFunction).boundTo("row(integer)", "row(bigint)").withCoercion().produces(new BoundVariables(ImmutableMap.of("T", type("bigint")), ImmutableMap.of()));
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestSignatureBinder method testBasic.
@Test
public void testBasic() {
Signature function = functionSignature().typeVariableConstraints(ImmutableList.of(typeVariable("T"))).returnType(parseTypeSignature("T")).argumentTypes(parseTypeSignature("T")).build();
assertThat(function).boundTo("bigint").produces(new BoundVariables(ImmutableMap.of("T", type("bigint")), ImmutableMap.of()));
assertThat(function).boundTo("varchar").produces(new BoundVariables(ImmutableMap.of("T", type("varchar")), ImmutableMap.of()));
assertThat(function).boundTo("varchar", "bigint").fails();
assertThat(function).boundTo("array(bigint)").produces(new BoundVariables(ImmutableMap.of("T", type("array(bigint)")), ImmutableMap.of()));
}
Aggregations