Search in sources :

Example 21 with FeaturesConfig

use of com.facebook.presto.sql.analyzer.FeaturesConfig 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 22 with FeaturesConfig

use of com.facebook.presto.sql.analyzer.FeaturesConfig 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 23 with FeaturesConfig

use of com.facebook.presto.sql.analyzer.FeaturesConfig 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)

Example 24 with FeaturesConfig

use of com.facebook.presto.sql.analyzer.FeaturesConfig in project presto by prestodb.

the class TestFunctionRegistry method testDuplicateFunctions.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "\\QFunction already registered: custom_add(bigint,bigint):bigint\\E")
public void testDuplicateFunctions() {
    List<SqlFunction> functions = new FunctionListBuilder().scalars(CustomFunctions.class).getFunctions().stream().filter(input -> input.getSignature().getName().equals("custom_add")).collect(toImmutableList());
    TypeRegistry typeManager = new TypeRegistry();
    FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig());
    registry.addFunctions(functions);
    registry.addFunctions(functions);
}
Also used : TypeSignature(com.facebook.presto.spi.type.TypeSignature) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) TypeManager(com.facebook.presto.spi.type.TypeManager) TIMESTAMP_WITH_TIME_ZONE(com.facebook.presto.spi.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE) TypeRegistry(com.facebook.presto.type.TypeRegistry) Assert.assertEquals(org.testng.Assert.assertEquals) ScalarFunctionImplementation(com.facebook.presto.operator.scalar.ScalarFunctionImplementation) Test(org.testng.annotations.Test) FunctionRegistry.mangleOperatorName(com.facebook.presto.metadata.FunctionRegistry.mangleOperatorName) Lists.transform(com.google.common.collect.Lists.transform) BlockEncodingSerde(com.facebook.presto.spi.block.BlockEncodingSerde) SCALAR(com.facebook.presto.metadata.FunctionKind.SCALAR) ImmutableList(com.google.common.collect.ImmutableList) FunctionRegistry.getMagicLiteralFunctionSignature(com.facebook.presto.metadata.FunctionRegistry.getMagicLiteralFunctionSignature) TypeSignatureProvider.fromTypeSignatures(com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypeSignatures) Signature.typeVariable(com.facebook.presto.metadata.Signature.typeVariable) StandardTypes(com.facebook.presto.spi.type.StandardTypes) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) Assert.assertFalse(org.testng.Assert.assertFalse) Functions(com.google.common.base.Functions) ImmutableSet(com.google.common.collect.ImmutableSet) FunctionRegistry.unmangleOperator(com.facebook.presto.metadata.FunctionRegistry.unmangleOperator) HYPER_LOG_LOG(com.facebook.presto.spi.type.HyperLogLogType.HYPER_LOG_LOG) MethodHandles(java.lang.invoke.MethodHandles) Assert.fail(org.testng.Assert.fail) String.format(java.lang.String.format) CustomFunctions(com.facebook.presto.operator.scalar.CustomFunctions) TypeUtils.resolveTypes(com.facebook.presto.type.TypeUtils.resolveTypes) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) OperatorType(com.facebook.presto.spi.function.OperatorType) Assert.assertTrue(org.testng.Assert.assertTrue) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Collections(java.util.Collections) SqlType(com.facebook.presto.spi.function.SqlType) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) TypeRegistry(com.facebook.presto.type.TypeRegistry) Test(org.testng.annotations.Test)

Example 25 with FeaturesConfig

use of com.facebook.presto.sql.analyzer.FeaturesConfig in project presto by prestodb.

the class TestFunctionRegistry method testListingHiddenFunctions.

@Test
public void testListingHiddenFunctions() throws Exception {
    TypeRegistry typeManager = new TypeRegistry();
    FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig());
    List<SqlFunction> functions = registry.list();
    List<String> names = transform(functions, input -> input.getSignature().getName());
    assertTrue(names.contains("length"), "Expected function names " + names + " to contain 'length'");
    assertTrue(names.contains("stddev"), "Expected function names " + names + " to contain 'stddev'");
    assertTrue(names.contains("rank"), "Expected function names " + names + " to contain 'rank'");
    assertFalse(names.contains("like"), "Expected function names " + names + " not to contain 'like'");
}
Also used : BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) TypeRegistry(com.facebook.presto.type.TypeRegistry) Test(org.testng.annotations.Test)

Aggregations

FeaturesConfig (com.facebook.presto.sql.analyzer.FeaturesConfig)39 Test (org.testng.annotations.Test)20 JoinCompiler (com.facebook.presto.sql.gen.JoinCompiler)14 BlockEncodingManager (com.facebook.presto.block.BlockEncodingManager)10 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)9 TypeRegistry (com.facebook.presto.type.TypeRegistry)9 Page (com.facebook.presto.common.Page)7 Type (com.facebook.presto.common.type.Type)7 SetBuilderOperatorFactory (com.facebook.presto.operator.SetBuilderOperator.SetBuilderOperatorFactory)6 RowPagesBuilder (com.facebook.presto.RowPagesBuilder)5 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)5 BlockEncodingManager (com.facebook.presto.common.block.BlockEncodingManager)4 CatalogManager (com.facebook.presto.metadata.CatalogManager)4 FunctionRegistry (com.facebook.presto.metadata.FunctionRegistry)4 FunctionRegistry.getMagicLiteralFunctionSignature (com.facebook.presto.metadata.FunctionRegistry.getMagicLiteralFunctionSignature)4 HashSemiJoinOperatorFactory (com.facebook.presto.operator.HashSemiJoinOperator.HashSemiJoinOperatorFactory)4 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 BeforeClass (org.testng.annotations.BeforeClass)4 CounterStat (com.facebook.airlift.stats.CounterStat)3