Search in sources :

Example 6 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 7 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)

Example 8 with FeaturesConfig

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

the class TestFunctionRegistry method testMagicLiteralFunction.

@Test
public void testMagicLiteralFunction() {
    Signature signature = getMagicLiteralFunctionSignature(TIMESTAMP_WITH_TIME_ZONE);
    assertEquals(signature.getName(), "$literal$timestamp with time zone");
    assertEquals(signature.getArgumentTypes(), ImmutableList.of(parseTypeSignature(StandardTypes.BIGINT)));
    assertEquals(signature.getReturnType().getBase(), StandardTypes.TIMESTAMP_WITH_TIME_ZONE);
    TypeRegistry typeManager = new TypeRegistry();
    FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig());
    Signature function = registry.resolveFunction(QualifiedName.of(signature.getName()), fromTypeSignatures(signature.getArgumentTypes()));
    assertEquals(function.getArgumentTypes(), ImmutableList.of(parseTypeSignature(StandardTypes.BIGINT)));
    assertEquals(signature.getReturnType().getBase(), StandardTypes.TIMESTAMP_WITH_TIME_ZONE);
}
Also used : BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) TypeSignature(com.facebook.presto.spi.type.TypeSignature) FunctionRegistry.getMagicLiteralFunctionSignature(com.facebook.presto.metadata.FunctionRegistry.getMagicLiteralFunctionSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) TypeRegistry(com.facebook.presto.type.TypeRegistry) Test(org.testng.annotations.Test)

Example 9 with FeaturesConfig

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

the class LocalQueryRunner method createPlan.

public Plan createPlan(Session session, @Language("SQL") String sql, LogicalPlanner.Stage stage) {
    Statement statement = unwrapExecuteStatement(sqlParser.createStatement(sql), sqlParser, session);
    assertFormattedSql(sqlParser, statement);
    FeaturesConfig featuresConfig = new FeaturesConfig().setDistributedIndexJoinsEnabled(false).setOptimizeHashGeneration(true);
    PlanOptimizers planOptimizers = new PlanOptimizers(metadata, sqlParser, featuresConfig, true, new MBeanExporter(new TestingMBeanServer()));
    return createPlan(session, sql, planOptimizers.get(), stage);
}
Also used : TestingMBeanServer(org.weakref.jmx.testing.TestingMBeanServer) SqlQueryManager.unwrapExecuteStatement(com.facebook.presto.execution.SqlQueryManager.unwrapExecuteStatement) Statement(com.facebook.presto.sql.tree.Statement) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) MBeanExporter(org.weakref.jmx.MBeanExporter) PlanOptimizers(com.facebook.presto.sql.planner.PlanOptimizers)

Example 10 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)

Aggregations

FeaturesConfig (com.facebook.presto.sql.analyzer.FeaturesConfig)13 BlockEncodingManager (com.facebook.presto.block.BlockEncodingManager)11 Test (org.testng.annotations.Test)10 TypeRegistry (com.facebook.presto.type.TypeRegistry)9 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)7 FunctionRegistry (com.facebook.presto.metadata.FunctionRegistry)4 FunctionRegistry.getMagicLiteralFunctionSignature (com.facebook.presto.metadata.FunctionRegistry.getMagicLiteralFunctionSignature)4 TypeSignature (com.facebook.presto.spi.type.TypeSignature)4 Signature (com.facebook.presto.metadata.Signature)3 OperatorType (com.facebook.presto.spi.function.OperatorType)3 CallExpression (com.facebook.presto.sql.relational.CallExpression)3 ConstantExpression (com.facebook.presto.sql.relational.ConstantExpression)3 RowExpression (com.facebook.presto.sql.relational.RowExpression)3 ExpressionOptimizer (com.facebook.presto.sql.relational.optimizer.ExpressionOptimizer)3 PlanOptimizers (com.facebook.presto.sql.planner.PlanOptimizers)2 MBeanExporter (org.weakref.jmx.MBeanExporter)2 TestingMBeanServer (org.weakref.jmx.testing.TestingMBeanServer)2 SqlQueryManager.unwrapExecuteStatement (com.facebook.presto.execution.SqlQueryManager.unwrapExecuteStatement)1 MockExchangeClientSupplier (com.facebook.presto.execution.TestSqlTaskManager.MockExchangeClientSupplier)1 LegacyNetworkTopology (com.facebook.presto.execution.scheduler.LegacyNetworkTopology)1