Search in sources :

Example 1 with FunctionRegistry

use of com.facebook.presto.metadata.FunctionRegistry in project presto by prestodb.

the class ZipFunction method specialize.

@Override
public ScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) {
    List<Type> types = this.typeParameters.stream().map(boundVariables::getTypeVariable).collect(toImmutableList());
    List<Boolean> nullableArguments = types.stream().map(type -> false).collect(toImmutableList());
    List<Class<?>> javaArgumentTypes = types.stream().map(type -> Block.class).collect(toImmutableList());
    MethodHandle methodHandle = METHOD_HANDLE.bindTo(types).asVarargsCollector(Block[].class).asType(methodType(Block.class, javaArgumentTypes));
    return new ScalarFunctionImplementation(false, nullableArguments, methodHandle, isDeterministic());
}
Also used : TypeSignature(com.facebook.presto.spi.type.TypeSignature) IntStream(java.util.stream.IntStream) MethodType.methodType(java.lang.invoke.MethodType.methodType) MethodHandle(java.lang.invoke.MethodHandle) Block(com.facebook.presto.spi.block.Block) BoundVariables(com.facebook.presto.metadata.BoundVariables) TypeManager(com.facebook.presto.spi.type.TypeManager) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) FunctionRegistry(com.facebook.presto.metadata.FunctionRegistry) Signature(com.facebook.presto.metadata.Signature) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) RowType(com.facebook.presto.type.RowType) FunctionKind(com.facebook.presto.metadata.FunctionKind) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) String.join(java.lang.String.join) Reflection.methodHandle(com.facebook.presto.util.Reflection.methodHandle) Type(com.facebook.presto.spi.type.Type) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) Optional(java.util.Optional) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) UsedByGeneratedCode(com.facebook.presto.annotation.UsedByGeneratedCode) MethodType.methodType(java.lang.invoke.MethodType.methodType) RowType(com.facebook.presto.type.RowType) Type(com.facebook.presto.spi.type.Type) Block(com.facebook.presto.spi.block.Block) MethodHandle(java.lang.invoke.MethodHandle)

Example 2 with FunctionRegistry

use of com.facebook.presto.metadata.FunctionRegistry in project presto by prestodb.

the class TestTypeRegistry method testCastOperatorsExistForCoercions.

@Test
public void testCastOperatorsExistForCoercions() {
    FunctionRegistry functionRegistry = new FunctionRegistry(typeRegistry, new BlockEncodingManager(typeRegistry), new FeaturesConfig());
    Set<Type> types = getStandardPrimitiveTypes();
    for (Type sourceType : types) {
        for (Type resultType : types) {
            if (typeRegistry.canCoerce(sourceType, resultType) && sourceType != UNKNOWN && resultType != UNKNOWN) {
                assertTrue(functionRegistry.canResolveOperator(OperatorType.CAST, resultType, ImmutableList.of(sourceType)), format("'%s' -> '%s' coercion exists but there is no cast operator", sourceType, resultType));
            }
        }
    }
}
Also used : FunctionRegistry(com.facebook.presto.metadata.FunctionRegistry) CharType.createCharType(com.facebook.presto.spi.type.CharType.createCharType) Type(com.facebook.presto.spi.type.Type) VarcharType.createUnboundedVarcharType(com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType) VarcharType.createVarcharType(com.facebook.presto.spi.type.VarcharType.createVarcharType) OperatorType(com.facebook.presto.spi.function.OperatorType) DecimalType.createDecimalType(com.facebook.presto.spi.type.DecimalType.createDecimalType) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) Test(org.testng.annotations.Test)

Example 3 with FunctionRegistry

use of com.facebook.presto.metadata.FunctionRegistry in project presto by prestodb.

the class TestExpressionOptimizer method testPossibleExponentialOptimizationTime.

@Test(timeOut = 10_000)
public void testPossibleExponentialOptimizationTime() {
    TypeRegistry typeManager = new TypeRegistry();
    ExpressionOptimizer optimizer = new ExpressionOptimizer(new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()), typeManager, TEST_SESSION);
    RowExpression expression = new ConstantExpression(1L, BIGINT);
    for (int i = 0; i < 100; i++) {
        Signature signature = internalOperator(OperatorType.ADD.name(), parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT));
        expression = new CallExpression(signature, BIGINT, ImmutableList.of(expression, new ConstantExpression(1L, BIGINT)));
    }
    optimizer.optimize(expression);
}
Also used : FunctionRegistry(com.facebook.presto.metadata.FunctionRegistry) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) ExpressionOptimizer(com.facebook.presto.sql.relational.optimizer.ExpressionOptimizer) ConstantExpression(com.facebook.presto.sql.relational.ConstantExpression) Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) RowExpression(com.facebook.presto.sql.relational.RowExpression) TypeRegistry(com.facebook.presto.type.TypeRegistry) CallExpression(com.facebook.presto.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Example 4 with FunctionRegistry

use of com.facebook.presto.metadata.FunctionRegistry in project presto by prestodb.

the class TestExpressionOptimizer method testIfConstantOptimization.

@Test
public void testIfConstantOptimization() {
    TypeRegistry typeManager = new TypeRegistry();
    ExpressionOptimizer optimizer = new ExpressionOptimizer(new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()), typeManager, TEST_SESSION);
    assertEquals(optimizer.optimize(ifExpression(new ConstantExpression(true, BOOLEAN), 1L, 2L)), new ConstantExpression(1L, BIGINT));
    assertEquals(optimizer.optimize(ifExpression(new ConstantExpression(false, BOOLEAN), 1L, 2L)), new ConstantExpression(2L, BIGINT));
    assertEquals(optimizer.optimize(ifExpression(new ConstantExpression(null, BOOLEAN), 1L, 2L)), new ConstantExpression(2L, BIGINT));
    Signature bigintEquals = internalOperator(OperatorType.EQUAL.name(), BOOLEAN.getTypeSignature(), BIGINT.getTypeSignature(), BIGINT.getTypeSignature());
    RowExpression condition = new CallExpression(bigintEquals, BOOLEAN, ImmutableList.of(new ConstantExpression(3L, BIGINT), new ConstantExpression(3L, BIGINT)));
    assertEquals(optimizer.optimize(ifExpression(condition, 1L, 2L)), new ConstantExpression(1L, BIGINT));
}
Also used : FunctionRegistry(com.facebook.presto.metadata.FunctionRegistry) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) ExpressionOptimizer(com.facebook.presto.sql.relational.optimizer.ExpressionOptimizer) ConstantExpression(com.facebook.presto.sql.relational.ConstantExpression) Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) RowExpression(com.facebook.presto.sql.relational.RowExpression) TypeRegistry(com.facebook.presto.type.TypeRegistry) CallExpression(com.facebook.presto.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Example 5 with FunctionRegistry

use of com.facebook.presto.metadata.FunctionRegistry in project presto by prestodb.

the class TestExpressionOptimizer method testTryOptimization.

@Test
public void testTryOptimization() {
    TypeRegistry typeManager = new TypeRegistry();
    ExpressionOptimizer optimizer = new ExpressionOptimizer(new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()), typeManager, TEST_SESSION);
    Signature signature = new Signature("TRY", SCALAR, BIGINT.getTypeSignature());
    RowExpression tryExpression = new CallExpression(signature, BIGINT, ImmutableList.of(new ConstantExpression(1L, BIGINT)));
    assertEquals(optimizer.optimize(tryExpression), new ConstantExpression(1L, BIGINT));
    tryExpression = new CallExpression(signature, BIGINT, ImmutableList.of(new InputReferenceExpression(1, BIGINT)));
    assertEquals(optimizer.optimize(tryExpression), new InputReferenceExpression(1, BIGINT));
}
Also used : FunctionRegistry(com.facebook.presto.metadata.FunctionRegistry) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) InputReferenceExpression(com.facebook.presto.sql.relational.InputReferenceExpression) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) ExpressionOptimizer(com.facebook.presto.sql.relational.optimizer.ExpressionOptimizer) Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) ConstantExpression(com.facebook.presto.sql.relational.ConstantExpression) RowExpression(com.facebook.presto.sql.relational.RowExpression) TypeRegistry(com.facebook.presto.type.TypeRegistry) CallExpression(com.facebook.presto.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Aggregations

FunctionRegistry (com.facebook.presto.metadata.FunctionRegistry)8 Signature (com.facebook.presto.metadata.Signature)6 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)5 BlockEncodingManager (com.facebook.presto.block.BlockEncodingManager)4 Type (com.facebook.presto.spi.type.Type)4 FeaturesConfig (com.facebook.presto.sql.analyzer.FeaturesConfig)4 RowExpression (com.facebook.presto.sql.relational.RowExpression)4 Test (org.testng.annotations.Test)4 BoundVariables (com.facebook.presto.metadata.BoundVariables)3 TypeManager (com.facebook.presto.spi.type.TypeManager)3 CallExpression (com.facebook.presto.sql.relational.CallExpression)3 ConstantExpression (com.facebook.presto.sql.relational.ConstantExpression)3 ExpressionOptimizer (com.facebook.presto.sql.relational.optimizer.ExpressionOptimizer)3 TypeRegistry (com.facebook.presto.type.TypeRegistry)3 ImmutableCollectors.toImmutableList (com.facebook.presto.util.ImmutableCollectors.toImmutableList)3 ImmutableList (com.google.common.collect.ImmutableList)3 MethodHandle (java.lang.invoke.MethodHandle)3 List (java.util.List)3 UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)2 DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)2