Search in sources :

Example 6 with VariableReferenceExpression

use of io.prestosql.spi.relation.VariableReferenceExpression in project hetu-core by openlookeng.

the class TestHivePageSourceProvider method testModifyDomainLessThanOrEqual.

@Test
public void testModifyDomainLessThanOrEqual() {
    Collection<Object> valueSet = new HashSet<>();
    valueSet.add(Long.valueOf(40));
    VariableReferenceExpression argument1 = new VariableReferenceExpression("arg_1", BIGINT);
    VariableReferenceExpression argument2 = new VariableReferenceExpression("arg_2", BIGINT);
    QualifiedObjectName objectName = new QualifiedObjectName("presto", "default", "$operator$less_than_or_equal");
    BuiltInFunctionHandle functionHandle = new BuiltInFunctionHandle(new Signature(objectName, FunctionKind.SCALAR, ImmutableList.of(), ImmutableList.of(), new TypeSignature("boolean"), ImmutableList.of(new TypeSignature("bigint"), new TypeSignature("bigint")), false));
    CallExpression filter = new CallExpression("LESS_THAN", functionHandle, BOOLEAN, ImmutableList.of(argument1, argument2));
    Domain domain = Domain.create(ValueSet.copyOf(BIGINT, valueSet), false);
    domain = modifyDomain(domain, Optional.of(filter));
    assertEquals(domain.getValues().getRanges().getSpan().getHigh().getValue(), Long.valueOf(40));
    assertEquals(domain.getValues().getRanges().getSpan().getLow().getValueBlock(), Optional.empty());
}
Also used : TypeSignature(io.prestosql.spi.type.TypeSignature) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) HivePageSourceProvider.modifyDomain(io.prestosql.plugin.hive.HivePageSourceProvider.modifyDomain) Domain(io.prestosql.spi.predicate.Domain) CallExpression(io.prestosql.spi.relation.CallExpression) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 7 with VariableReferenceExpression

use of io.prestosql.spi.relation.VariableReferenceExpression in project hetu-core by openlookeng.

the class TestHivePageSourceProvider method testModifyDomainGreaterThanOrEqual.

@Test
public void testModifyDomainGreaterThanOrEqual() {
    Collection<Object> valueSet = new HashSet<>();
    valueSet.add(Long.valueOf(40));
    VariableReferenceExpression argument1 = new VariableReferenceExpression("arg_1", BIGINT);
    VariableReferenceExpression argument2 = new VariableReferenceExpression("arg_2", BIGINT);
    QualifiedObjectName objectName = new QualifiedObjectName("presto", "default", "$operator$greater_than_or_equal");
    BuiltInFunctionHandle functionHandle = new BuiltInFunctionHandle(new Signature(objectName, FunctionKind.SCALAR, ImmutableList.of(), ImmutableList.of(), new TypeSignature("boolean"), ImmutableList.of(new TypeSignature("bigint"), new TypeSignature("bigint")), false));
    CallExpression filter = new CallExpression("GREATER_THAN_OR_EQUAL", functionHandle, BOOLEAN, ImmutableList.of(argument1, argument2));
    Domain domain = Domain.create(ValueSet.copyOf(BIGINT, valueSet), false);
    domain = modifyDomain(domain, Optional.of(filter));
    assertEquals(domain.getValues().getRanges().getSpan().getHigh().getValueBlock(), Optional.empty());
    assertEquals(domain.getValues().getRanges().getSpan().getLow().getValue(), Long.valueOf(40));
}
Also used : TypeSignature(io.prestosql.spi.type.TypeSignature) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) HivePageSourceProvider.modifyDomain(io.prestosql.plugin.hive.HivePageSourceProvider.modifyDomain) Domain(io.prestosql.spi.predicate.Domain) CallExpression(io.prestosql.spi.relation.CallExpression) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 8 with VariableReferenceExpression

use of io.prestosql.spi.relation.VariableReferenceExpression in project hetu-core by openlookeng.

the class SqlQueryExecution method findMappingFromPlan.

private void findMappingFromPlan(Map<String, Set<String>> mapping, PlanNode sourceNode) {
    if (sourceNode != null && sourceNode instanceof ProjectNode) {
        ProjectNode projectNode = (ProjectNode) sourceNode;
        Map<Symbol, RowExpression> assignments = projectNode.getAssignments().getMap();
        for (Symbol symbol : assignments.keySet()) {
            if (mapping.containsKey(symbol.getName())) {
                Set<String> sets = mapping.get(symbol.getName());
                RowExpression expression = assignments.get(symbol);
                if (expression instanceof VariableReferenceExpression) {
                    sets.add(((VariableReferenceExpression) expression).getName());
                } else {
                    sets.add(expression.toString());
                }
            } else {
                for (Map.Entry<String, Set<String>> entry : mapping.entrySet()) {
                    if (entry.getValue().contains(symbol.getName())) {
                        RowExpression expression = assignments.get(symbol);
                        if (expression instanceof VariableReferenceExpression) {
                            entry.getValue().add(((VariableReferenceExpression) expression).getName());
                        } else {
                            entry.getValue().add(expression.toString());
                        }
                    }
                }
            }
        }
    }
    for (PlanNode planNode : sourceNode.getSources()) {
        findMappingFromPlan(mapping, planNode);
    }
}
Also used : Set(java.util.Set) ImmutableSet(com.google.common.collect.ImmutableSet) HashSet(java.util.HashSet) PlanNode(io.prestosql.spi.plan.PlanNode) Symbol(io.prestosql.spi.plan.Symbol) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) RowExpression(io.prestosql.spi.relation.RowExpression) ProjectNode(io.prestosql.spi.plan.ProjectNode) Map(java.util.Map) StateMap(io.prestosql.spi.statestore.StateMap) HashMap(java.util.HashMap)

Example 9 with VariableReferenceExpression

use of io.prestosql.spi.relation.VariableReferenceExpression in project hetu-core by openlookeng.

the class TestDynamicFilters method testExtractStaticFilters.

@Test
public void testExtractStaticFilters() {
    LogicalRowExpressions logicalRowExpressions = new LogicalRowExpressions(new RowExpressionDeterminismEvaluator(metadata), new FunctionResolution(metadata.getFunctionAndTypeManager()), metadata.getFunctionAndTypeManager());
    ConstantExpression staticExpression = new ConstantExpression(utf8Slice("age"), VarcharType.VARCHAR);
    VariableReferenceExpression variableExpression = new VariableReferenceExpression("col", VarcharType.VARCHAR);
    FunctionHandle functionHandle = metadata.getFunctionAndTypeManager().lookupFunction("rank", ImmutableList.of());
    RowExpression dynamicFilterExpression = call(DynamicFilters.Function.NAME, functionHandle, staticExpression.getType(), asList(staticExpression, variableExpression), Optional.empty());
    RowExpression combinedExpression = logicalRowExpressions.combineConjuncts(staticExpression, dynamicFilterExpression);
    Optional<RowExpression> extractedExpression = DynamicFilters.extractStaticFilters(Optional.of(combinedExpression), metadata);
    assertEquals(extractedExpression.get(), staticExpression);
    RowExpression combinedStaticExpression = logicalRowExpressions.combineConjuncts(staticExpression, variableExpression);
    combinedExpression = logicalRowExpressions.combineConjuncts(staticExpression, variableExpression, dynamicFilterExpression);
    extractedExpression = DynamicFilters.extractStaticFilters(Optional.of(combinedExpression), metadata);
    assertEquals(extractedExpression.get(), combinedStaticExpression);
}
Also used : RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) LogicalRowExpressions(io.prestosql.expressions.LogicalRowExpressions) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) RowExpression(io.prestosql.spi.relation.RowExpression) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) FunctionHandle(io.prestosql.spi.function.FunctionHandle) Test(org.testng.annotations.Test)

Example 10 with VariableReferenceExpression

use of io.prestosql.spi.relation.VariableReferenceExpression in project hetu-core by openlookeng.

the class TestDynamicFilters method testExtractDynamicFilterExpression.

@Test
public void testExtractDynamicFilterExpression() {
    LogicalRowExpressions logicalRowExpressions = new LogicalRowExpressions(new RowExpressionDeterminismEvaluator(metadata), new FunctionResolution(metadata.getFunctionAndTypeManager()), metadata.getFunctionAndTypeManager());
    ConstantExpression staticExpression1 = new ConstantExpression(utf8Slice("age"), VarcharType.VARCHAR);
    VariableReferenceExpression variableExpression1 = new VariableReferenceExpression("col", VarcharType.VARCHAR);
    ConstantExpression staticExpression2 = new ConstantExpression(utf8Slice("age"), VarcharType.VARCHAR);
    VariableReferenceExpression variableExpression2 = new VariableReferenceExpression("col", VarcharType.VARCHAR);
    FunctionHandle functionHandle = metadata.getFunctionAndTypeManager().lookupFunction("rank", ImmutableList.of());
    RowExpression dynamicFilterExpression1 = call(DynamicFilters.Function.NAME, functionHandle, staticExpression1.getType(), asList(staticExpression1, variableExpression1), Optional.empty());
    RowExpression dynamicFilterExpression2 = call(DynamicFilters.Function.NAME, functionHandle, staticExpression2.getType(), asList(staticExpression2, variableExpression2), Optional.empty());
    RowExpression combineDynamicFilterExpression = logicalRowExpressions.combineDisjuncts(asList(dynamicFilterExpression1, dynamicFilterExpression2));
    RowExpression combinedExpression = logicalRowExpressions.combineConjuncts(staticExpression1, combineDynamicFilterExpression);
    RowExpression extractedExpression = DynamicFilters.extractDynamicFilterExpression(combinedExpression, metadata);
    assertEquals(extractedExpression, combineDynamicFilterExpression);
}
Also used : RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) LogicalRowExpressions(io.prestosql.expressions.LogicalRowExpressions) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) RowExpression(io.prestosql.spi.relation.RowExpression) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) FunctionHandle(io.prestosql.spi.function.FunctionHandle) Test(org.testng.annotations.Test)

Aggregations

VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)59 RowExpression (io.prestosql.spi.relation.RowExpression)35 Symbol (io.prestosql.spi.plan.Symbol)32 CallExpression (io.prestosql.spi.relation.CallExpression)22 Test (org.testng.annotations.Test)22 ConstantExpression (io.prestosql.spi.relation.ConstantExpression)21 Map (java.util.Map)16 List (java.util.List)14 PlanNode (io.prestosql.spi.plan.PlanNode)13 ImmutableList (com.google.common.collect.ImmutableList)12 SpecialForm (io.prestosql.spi.relation.SpecialForm)12 HashMap (java.util.HashMap)11 HashSet (java.util.HashSet)11 BuiltInFunctionHandle (io.prestosql.spi.function.BuiltInFunctionHandle)10 Assignments (io.prestosql.spi.plan.Assignments)10 ProjectNode (io.prestosql.spi.plan.ProjectNode)10 SymbolReference (io.prestosql.sql.tree.SymbolReference)10 FunctionHandle (io.prestosql.spi.function.FunctionHandle)9 DynamicFilters (io.prestosql.sql.DynamicFilters)9 Optional (java.util.Optional)9