Search in sources :

Example 1 with TypeProvider

use of com.facebook.presto.sql.planner.TypeProvider in project presto by prestodb.

the class TestValidateStreamingAggregations method validatePlan.

private void validatePlan(Function<PlanBuilder, PlanNode> planProvider) {
    PlanBuilder builder = new PlanBuilder(TEST_SESSION, idAllocator, metadata);
    PlanNode planNode = planProvider.apply(builder);
    TypeProvider types = builder.getTypes();
    getQueryRunner().inTransaction(session -> {
        // metadata.getCatalogHandle() registers the catalog for the transaction
        session.getCatalog().ifPresent(catalog -> metadata.getCatalogHandle(session, catalog));
        new ValidateStreamingAggregations().validate(planNode, session, metadata, sqlParser, types, WarningCollector.NOOP);
        return null;
    });
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) TypeProvider(com.facebook.presto.sql.planner.TypeProvider) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)

Example 2 with TypeProvider

use of com.facebook.presto.sql.planner.TypeProvider in project presto by prestodb.

the class TestValidateStreamingJoins method validatePlan.

private void validatePlan(Function<PlanBuilder, PlanNode> planProvider) {
    PlanBuilder builder = new PlanBuilder(TEST_SESSION, idAllocator, metadata);
    PlanNode planNode = planProvider.apply(builder);
    TypeProvider types = builder.getTypes();
    getQueryRunner().inTransaction(testSession, session -> {
        session.getCatalog().ifPresent(catalog -> metadata.getCatalogHandle(session, catalog));
        new ValidateStreamingJoins().validate(planNode, session, metadata, sqlParser, types, WarningCollector.NOOP);
        return null;
    });
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) TypeProvider(com.facebook.presto.sql.planner.TypeProvider) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)

Example 3 with TypeProvider

use of com.facebook.presto.sql.planner.TypeProvider in project presto by prestodb.

the class TestRowExpressionTranslator method testMissingFunctionTranslator.

@Test
public void testMissingFunctionTranslator() {
    String untranslated = "ABS(col1)";
    TypeProvider typeProvider = TypeProvider.copyOf(ImmutableMap.of("col1", DOUBLE));
    RowExpression specialForm = sqlToRowExpressionTranslator.translate(expression(untranslated), typeProvider);
    TranslatedExpression translatedExpression = translateWith(specialForm, new TestFunctionTranslator(functionAndTypeManager, buildFunctionTranslator(ImmutableSet.of(TestFunctions.class))), emptyMap());
    assertFalse(translatedExpression.getTranslated().isPresent());
}
Also used : TypeProvider(com.facebook.presto.sql.planner.TypeProvider) RowExpression(com.facebook.presto.spi.relation.RowExpression) TranslatedExpression(com.facebook.presto.expressions.translator.TranslatedExpression) Test(org.testng.annotations.Test)

Example 4 with TypeProvider

use of com.facebook.presto.sql.planner.TypeProvider in project presto by prestodb.

the class ActualProperties method translateRowExpression.

public ActualProperties translateRowExpression(Map<VariableReferenceExpression, RowExpression> assignments, TypeProvider types) {
    Map<VariableReferenceExpression, VariableReferenceExpression> inputToOutputVariables = new HashMap<>();
    for (Map.Entry<VariableReferenceExpression, RowExpression> assignment : assignments.entrySet()) {
        RowExpression expression = assignment.getValue();
        if (isExpression(expression)) {
            if (castToExpression(expression) instanceof SymbolReference) {
                inputToOutputVariables.put(toVariableReference(castToExpression(expression), types), assignment.getKey());
            }
        } else {
            if (expression instanceof VariableReferenceExpression) {
                inputToOutputVariables.put((VariableReferenceExpression) expression, assignment.getKey());
            }
        }
    }
    Map<VariableReferenceExpression, ConstantExpression> translatedConstants = new HashMap<>();
    for (Map.Entry<VariableReferenceExpression, ConstantExpression> entry : constants.entrySet()) {
        if (inputToOutputVariables.containsKey(entry.getKey())) {
            translatedConstants.put(inputToOutputVariables.get(entry.getKey()), entry.getValue());
        }
    }
    ImmutableMap.Builder<VariableReferenceExpression, RowExpression> inputToOutputMappings = ImmutableMap.builder();
    inputToOutputMappings.putAll(inputToOutputVariables);
    constants.entrySet().stream().filter(entry -> !inputToOutputVariables.containsKey(entry.getKey())).forEach(inputToOutputMappings::put);
    return builder().global(global.translateRowExpression(inputToOutputMappings.build(), assignments, types)).local(LocalProperties.translate(localProperties, variable -> Optional.ofNullable(inputToOutputVariables.get(variable)))).constants(translatedConstants).build();
}
Also used : SINGLE_DISTRIBUTION(com.facebook.presto.sql.planner.SystemPartitioningHandle.SINGLE_DISTRIBUTION) Iterables.transform(com.google.common.collect.Iterables.transform) OriginalExpressionUtils.isExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.isExpression) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) HashMap(java.util.HashMap) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) Function(java.util.function.Function) OriginalExpressionUtils.castToExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToExpression) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) TypeProvider(com.facebook.presto.sql.planner.TypeProvider) MoreLists.filteredCopy(com.facebook.presto.util.MoreLists.filteredCopy) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) LocalProperty(com.facebook.presto.spi.LocalProperty) Partitioning(com.facebook.presto.sql.planner.Partitioning) RowExpression(com.facebook.presto.spi.relation.RowExpression) SymbolReference(com.facebook.presto.sql.tree.SymbolReference) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Session(com.facebook.presto.Session) Collection(java.util.Collection) Set(java.util.Set) ConstantProperty(com.facebook.presto.spi.ConstantProperty) SOURCE_DISTRIBUTION(com.facebook.presto.sql.planner.SystemPartitioningHandle.SOURCE_DISTRIBUTION) Objects(java.util.Objects) PlannerUtils.toVariableReference(com.facebook.presto.sql.planner.PlannerUtils.toVariableReference) List(java.util.List) PartitioningHandle(com.facebook.presto.sql.planner.PartitioningHandle) Optional(java.util.Optional) Immutable(javax.annotation.concurrent.Immutable) Metadata(com.facebook.presto.metadata.Metadata) COORDINATOR_DISTRIBUTION(com.facebook.presto.sql.planner.SystemPartitioningHandle.COORDINATOR_DISTRIBUTION) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) HashMap(java.util.HashMap) SymbolReference(com.facebook.presto.sql.tree.SymbolReference) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) ImmutableMap(com.google.common.collect.ImmutableMap) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 5 with TypeProvider

use of com.facebook.presto.sql.planner.TypeProvider in project presto by prestodb.

the class RuleAssert method get.

public PlanNode get() {
    RuleApplication ruleApplication = applyRule();
    TypeProvider types = ruleApplication.types;
    if (!ruleApplication.wasRuleApplied()) {
        fail(String.format("%s did not fire for:\n%s", rule.getClass().getName(), formatPlan(plan, types)));
    }
    return ruleApplication.getTransformedPlan();
}
Also used : TypeProvider(com.facebook.presto.sql.planner.TypeProvider)

Aggregations

TypeProvider (com.facebook.presto.sql.planner.TypeProvider)28 RowExpression (com.facebook.presto.spi.relation.RowExpression)17 PlanNode (com.facebook.presto.spi.plan.PlanNode)12 Test (org.testng.annotations.Test)12 ColumnHandle (com.facebook.presto.spi.ColumnHandle)7 Session (com.facebook.presto.Session)6 TranslatedExpression (com.facebook.presto.expressions.translator.TranslatedExpression)6 ConnectorSession (com.facebook.presto.spi.ConnectorSession)6 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)6 List (java.util.List)6 JdbcColumnHandle (com.facebook.presto.plugin.jdbc.JdbcColumnHandle)5 JdbcTableHandle (com.facebook.presto.plugin.jdbc.JdbcTableHandle)5 JdbcTableLayoutHandle (com.facebook.presto.plugin.jdbc.JdbcTableLayoutHandle)5 SchemaTableName (com.facebook.presto.spi.SchemaTableName)5 Expression (com.facebook.presto.sql.tree.Expression)5 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)5 Map (java.util.Map)5 CallExpression (com.facebook.presto.spi.relation.CallExpression)4 ProjectNode (com.facebook.presto.spi.plan.ProjectNode)3 ConstantExpression (com.facebook.presto.spi.relation.ConstantExpression)3