Search in sources :

Example 21 with TypeSignature

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)));
}
Also used : TypeSignature(com.facebook.presto.spi.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) TypeSignature(com.facebook.presto.spi.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) Test(org.testng.annotations.Test)

Example 22 with TypeSignature

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)));
}
Also used : TypeSignature(com.facebook.presto.spi.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) TypeSignature(com.facebook.presto.spi.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) Test(org.testng.annotations.Test)

Example 23 with TypeSignature

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);
}
Also used : TypeSignatureProvider(com.facebook.presto.sql.analyzer.TypeSignatureProvider) TypeSignature(com.facebook.presto.spi.type.TypeSignature) Signature(com.facebook.presto.metadata.Signature)

Example 24 with TypeSignature

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))))));
}
Also used : TypeSignature(com.facebook.presto.spi.type.TypeSignature) NamedTypeSignature(com.facebook.presto.spi.type.NamedTypeSignature) NamedTypeSignature(com.facebook.presto.spi.type.NamedTypeSignature) Test(org.testng.annotations.Test)

Example 25 with TypeSignature

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);
}
Also used : TypeSignature(com.facebook.presto.spi.type.TypeSignature) NamedTypeSignature(com.facebook.presto.spi.type.NamedTypeSignature) TypeSignature(com.facebook.presto.spi.type.TypeSignature) NamedTypeSignature(com.facebook.presto.spi.type.NamedTypeSignature)

Aggregations

TypeSignature (com.facebook.presto.spi.type.TypeSignature)34 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)19 ImmutableList (com.google.common.collect.ImmutableList)14 NamedTypeSignature (com.facebook.presto.spi.type.NamedTypeSignature)10 Test (org.testng.annotations.Test)10 Signature (com.facebook.presto.metadata.Signature)9 PrestoException (com.facebook.presto.spi.PrestoException)8 Type (com.facebook.presto.spi.type.Type)6 TypeSignatureParameter (com.facebook.presto.spi.type.TypeSignatureParameter)6 ImmutableSet (com.google.common.collect.ImmutableSet)6 Slice (io.airlift.slice.Slice)6 UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)5 SCALAR (com.facebook.presto.metadata.FunctionKind.SCALAR)5 SqlScalarFunction (com.facebook.presto.metadata.SqlScalarFunction)5 SqlScalarFunctionBuilder (com.facebook.presto.metadata.SqlScalarFunctionBuilder)5 SpecializeContext (com.facebook.presto.metadata.SqlScalarFunctionBuilder.SpecializeContext)5 SqlType (com.facebook.presto.spi.function.SqlType)5 DecimalType (com.facebook.presto.spi.type.DecimalType)5 Decimals (com.facebook.presto.spi.type.Decimals)5 Decimals.encodeUnscaledValue (com.facebook.presto.spi.type.Decimals.encodeUnscaledValue)5