Search in sources :

Example 1 with SymbolReference

use of io.prestosql.sql.tree.SymbolReference in project hetu-core by openlookeng.

the class TestExpressionDomainTranslator method testCubeRangeVisitorRightSymbolReferenceComparisonExpression.

@Test
public void testCubeRangeVisitorRightSymbolReferenceComparisonExpression() {
    CubeRangeCanonicalizer.CubeRangeVisitor visitor = new CubeRangeCanonicalizer.CubeRangeVisitor(TYPES, metadata, TEST_SESSION.toConnectorSession());
    Expression cubePredicate = new ComparisonExpression(EQUAL, new LongLiteral("1"), new SymbolReference(C_TINYINT.getName()));
    List<Expression> predicates = ExpressionUtils.extractDisjuncts(cubePredicate);
    Expression transformed = ExpressionUtils.or(predicates.stream().map(visitor::process).collect(Collectors.toList()));
    assertNotNull(transformed);
}
Also used : ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) CubeRangeCanonicalizer(io.prestosql.operator.CubeRangeCanonicalizer) InListExpression(io.prestosql.sql.tree.InListExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) LongLiteral(io.prestosql.sql.tree.LongLiteral) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) SymbolReference(io.prestosql.sql.tree.SymbolReference) Test(org.testng.annotations.Test)

Example 2 with SymbolReference

use of io.prestosql.sql.tree.SymbolReference in project hetu-core by openlookeng.

the class TestExpressionDomainTranslator method testCubeRangeVisitorRightCastedSymbolReferenceComparisonExpression.

@Test
public void testCubeRangeVisitorRightCastedSymbolReferenceComparisonExpression() {
    CubeRangeCanonicalizer.CubeRangeVisitor visitor = new CubeRangeCanonicalizer.CubeRangeVisitor(TYPES, metadata, TEST_SESSION.toConnectorSession());
    Expression cubePredicate = new ComparisonExpression(EQUAL, new LongLiteral("1"), new Cast(new SymbolReference(C_TINYINT.getName()), "integer"));
    List<Expression> predicates = ExpressionUtils.extractDisjuncts(cubePredicate);
    Expression transformed = ExpressionUtils.or(predicates.stream().map(visitor::process).collect(Collectors.toList()));
    assertNotNull(transformed);
}
Also used : Cast(io.prestosql.sql.tree.Cast) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) CubeRangeCanonicalizer(io.prestosql.operator.CubeRangeCanonicalizer) InListExpression(io.prestosql.sql.tree.InListExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) LongLiteral(io.prestosql.sql.tree.LongLiteral) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) SymbolReference(io.prestosql.sql.tree.SymbolReference) Test(org.testng.annotations.Test)

Example 3 with SymbolReference

use of io.prestosql.sql.tree.SymbolReference in project hetu-core by openlookeng.

the class TestExpressionRewriteRuleSet method testAggregationExpressionRewrite.

@Test
public void testAggregationExpressionRewrite() {
    ExpressionRewriteRuleSet functionCallRewriter = new ExpressionRewriteRuleSet((expression, context) -> new FunctionCallBuilder(tester().getMetadata()).setName(QualifiedName.of("count")).addArgument(VARCHAR, new SymbolReference("y")).build());
    tester().assertThat(functionCallRewriter.aggregationExpressionRewrite()).on(p -> p.aggregation(a -> a.globalGrouping().addAggregation(p.symbol("count_1", BigintType.BIGINT), new FunctionCallBuilder(tester().getMetadata()).setName(QualifiedName.of("count")).addArgument(VARCHAR, new SymbolReference("x")).build(), ImmutableList.of(BigintType.BIGINT)).source(p.values(p.symbol("x"), p.symbol("y"))))).matches(PlanMatchPattern.aggregation(ImmutableMap.of("count_1", aliases -> new FunctionCallBuilder(tester().getMetadata()).setName(QualifiedName.of("count")).addArgument(VARCHAR, new SymbolReference("y")).build()), values("x", "y")));
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) BigintType(io.prestosql.spi.type.BigintType) PlanBuilder.assignment(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder.assignment) BaseRuleTest(io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest) PlanMatchPattern.project(io.prestosql.sql.planner.assertions.PlanMatchPattern.project) ImmutableMap(com.google.common.collect.ImmutableMap) PlanMatchPattern(io.prestosql.sql.planner.assertions.PlanMatchPattern) QualifiedName(io.prestosql.sql.tree.QualifiedName) FunctionCallBuilder(io.prestosql.sql.planner.FunctionCallBuilder) Test(org.testng.annotations.Test) PlanMatchPattern.values(io.prestosql.sql.planner.assertions.PlanMatchPattern.values) VARCHAR(io.prestosql.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) FunctionCall(io.prestosql.sql.tree.FunctionCall) LongLiteral(io.prestosql.sql.tree.LongLiteral) SymbolReference(io.prestosql.sql.tree.SymbolReference) DateType(io.prestosql.spi.type.DateType) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) PlanMatchPattern.filter(io.prestosql.sql.planner.assertions.PlanMatchPattern.filter) PlanMatchPattern.expression(io.prestosql.sql.planner.assertions.PlanMatchPattern.expression) OriginalExpressionUtils(io.prestosql.sql.relational.OriginalExpressionUtils) SymbolReference(io.prestosql.sql.tree.SymbolReference) FunctionCallBuilder(io.prestosql.sql.planner.FunctionCallBuilder) BaseRuleTest(io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest) Test(org.testng.annotations.Test)

Example 4 with SymbolReference

use of io.prestosql.sql.tree.SymbolReference in project hetu-core by openlookeng.

the class RowExpressionVerifier method visitCast.

@Override
protected Boolean visitCast(Cast expected, RowExpression actual) {
    // TODO: clean up cast path
    if (actual instanceof ConstantExpression && expected.getExpression() instanceof Literal && expected.getType().equals(actual.getType().toString())) {
        Literal literal = (Literal) expected.getExpression();
        if (literal instanceof StringLiteral) {
            Object value = LiteralInterpreter.evaluate((ConstantExpression) actual);
            String actualString = value instanceof Slice ? ((Slice) value).toStringUtf8() : String.valueOf(value);
            return ((StringLiteral) literal).getValue().equals(actualString);
        }
        return getValueFromLiteral(literal).equals(String.valueOf(LiteralInterpreter.evaluate((ConstantExpression) actual)));
    }
    if (actual instanceof VariableReferenceExpression && expected.getExpression() instanceof SymbolReference && expected.getType().equals(actual.getType().toString())) {
        return visitSymbolReference((SymbolReference) expected.getExpression(), actual);
    }
    if (!(actual instanceof CallExpression) || !functionResolution.isCastFunction(((CallExpression) actual).getFunctionHandle())) {
        return false;
    }
    if (!expected.getType().equalsIgnoreCase(actual.getType().toString()) && !(expected.getType().toLowerCase(ENGLISH).equals(VARCHAR) && actual.getType().getTypeSignature().getBase().equals(VARCHAR))) {
        return false;
    }
    return process(expected.getExpression(), ((CallExpression) actual).getArguments().get(0));
}
Also used : StringLiteral(io.prestosql.sql.tree.StringLiteral) Slice(io.airlift.slice.Slice) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) SymbolReference(io.prestosql.sql.tree.SymbolReference) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) NullLiteral(io.prestosql.sql.tree.NullLiteral) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) GenericLiteral(io.prestosql.sql.tree.GenericLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) StringLiteral(io.prestosql.sql.tree.StringLiteral) Literal(io.prestosql.sql.tree.Literal) DecimalLiteral(io.prestosql.sql.tree.DecimalLiteral) BooleanLiteral(io.prestosql.sql.tree.BooleanLiteral) CallExpression(io.prestosql.spi.relation.CallExpression)

Example 5 with SymbolReference

use of io.prestosql.sql.tree.SymbolReference in project hetu-core by openlookeng.

the class SymbolAliases method getOptional.

public Optional<SymbolReference> getOptional(String inputAlias) {
    String alias = inputAlias;
    alias = toKey(alias);
    SymbolReference result = map.get(alias);
    return Optional.ofNullable(result);
}
Also used : SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) SymbolReference(io.prestosql.sql.tree.SymbolReference)

Aggregations

SymbolReference (io.prestosql.sql.tree.SymbolReference)57 Symbol (io.prestosql.spi.plan.Symbol)30 Expression (io.prestosql.sql.tree.Expression)29 Test (org.testng.annotations.Test)25 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)23 Cast (io.prestosql.sql.tree.Cast)19 RowExpression (io.prestosql.spi.relation.RowExpression)17 SymbolUtils.toSymbolReference (io.prestosql.sql.planner.SymbolUtils.toSymbolReference)17 LongLiteral (io.prestosql.sql.tree.LongLiteral)14 ImmutableList (com.google.common.collect.ImmutableList)13 ImmutableMap (com.google.common.collect.ImmutableMap)12 Type (io.prestosql.spi.type.Type)12 List (java.util.List)12 Map (java.util.Map)12 ProjectNode (io.prestosql.spi.plan.ProjectNode)11 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)10 ArrayList (java.util.ArrayList)10 Assignments (io.prestosql.spi.plan.Assignments)9 CallExpression (io.prestosql.spi.relation.CallExpression)9 OriginalExpressionUtils.castToExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression)9