use of com.facebook.presto.spi.type.TypeSignature in project presto by prestodb.
the class TestSignatureBinder method testBindLiteralForRepeatedVarchar.
@Test
public void testBindLiteralForRepeatedVarchar() throws Exception {
Set<String> literalParameters = ImmutableSet.of("x");
TypeSignature leftType = parseTypeSignature("varchar(x)", literalParameters);
TypeSignature rightType = parseTypeSignature("varchar(x)", literalParameters);
TypeSignature returnType = parseTypeSignature("varchar(x)", literalParameters);
Signature function = functionSignature().returnType(returnType).argumentTypes(leftType, rightType).build();
assertThat(function).withCoercion().boundTo(ImmutableList.of("varchar(3)", "varchar(5)"), "varchar(5)").produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("x", 5L)));
assertThat(function).withCoercion().boundTo(ImmutableList.of("varchar(3)", "varchar(5)"), "varchar(6)").produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("x", 6L)));
}
use of com.facebook.presto.spi.type.TypeSignature in project presto by prestodb.
the class TestSignatureBinder method testBindLiteralForRepeatedDecimal.
@Test
public void testBindLiteralForRepeatedDecimal() {
TypeSignature leftType = parseTypeSignature("decimal(p,s)", ImmutableSet.of("p", "s"));
TypeSignature rightType = parseTypeSignature("decimal(p,s)", ImmutableSet.of("p", "s"));
Signature function = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(leftType, rightType).build();
assertThat(function).boundTo("decimal(10,5)", "decimal(10,5)").produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("p", 10L, "s", 5L)));
assertThat(function).boundTo("decimal(10,8)", "decimal(9,8)").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("p", 10L, "s", 8L)));
assertThat(function).boundTo("decimal(10,2)", "decimal(10,8)").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("p", 16L, "s", 8L)));
assertThat(function).boundTo("unknown", "decimal(10,5)").withCoercion().produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("p", 10L, "s", 5L)));
}
use of com.facebook.presto.spi.type.TypeSignature in project presto by prestodb.
the class AbstractTestAggregationFunction method getFunction.
protected final InternalAggregationFunction getFunction() {
List<TypeSignatureProvider> parameterTypes = fromTypeSignatures(Lists.transform(getFunctionParameterTypes(), TypeSignature::parseTypeSignature));
Signature signature = functionRegistry.resolveFunction(QualifiedName.of(getFunctionName()), parameterTypes);
return functionRegistry.getAggregateFunctionImplementation(signature);
}
use of com.facebook.presto.spi.type.TypeSignature in project presto by prestodb.
the class TestClientTypeSignature method testJsonRoundTrip.
@Test
public void testJsonRoundTrip() {
TypeSignature bigint = BIGINT.getTypeSignature();
assertJsonRoundTrip(new ClientTypeSignature(bigint));
assertJsonRoundTrip(new ClientTypeSignature("array", ImmutableList.of(new ClientTypeSignatureParameter(TypeSignatureParameter.of(bigint)))));
assertJsonRoundTrip(new ClientTypeSignature("foo", ImmutableList.of(new ClientTypeSignatureParameter(TypeSignatureParameter.of(42)))));
assertJsonRoundTrip(new ClientTypeSignature("row", ImmutableList.of(new ClientTypeSignatureParameter(TypeSignatureParameter.of(new NamedTypeSignature("foo", bigint))), new ClientTypeSignatureParameter(TypeSignatureParameter.of(new NamedTypeSignature("bar", bigint))))));
}
use of com.facebook.presto.spi.type.TypeSignature in project presto by prestodb.
the class SignatureBinder method applyBoundVariables.
public static Signature applyBoundVariables(Signature signature, BoundVariables boundVariables, int arity) {
List<TypeSignature> argumentSignatures;
if (signature.isVariableArity()) {
argumentSignatures = expandVarargFormalTypeSignature(signature.getArgumentTypes(), arity);
} else {
checkArgument(signature.getArgumentTypes().size() == arity);
argumentSignatures = signature.getArgumentTypes();
}
List<TypeSignature> boundArgumentSignatures = applyBoundVariables(argumentSignatures, boundVariables);
TypeSignature boundReturnTypeSignature = applyBoundVariables(signature.getReturnType(), boundVariables);
return new Signature(signature.getName(), signature.getKind(), ImmutableList.of(), ImmutableList.of(), boundReturnTypeSignature, boundArgumentSignatures, false);
}
Aggregations