Search in sources :

Example 6 with Expression

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

the class PageProcessorBenchmark method rowExpression.

private RowExpression rowExpression(String value) {
    Expression expression = createExpression(value, METADATA, TypeProvider.copyOf(symbolTypes));
    Map<NodeRef<Expression>, Type> expressionTypes = TYPE_ANALYZER.getTypes(TEST_SESSION, TypeProvider.copyOf(symbolTypes), expression);
    return SqlToRowExpressionTranslator.translate(expression, SCALAR, expressionTypes, sourceLayout, METADATA.getFunctionAndTypeManager(), TEST_SESSION, true);
}
Also used : NodeRef(io.prestosql.sql.tree.NodeRef) Type(io.prestosql.spi.type.Type) FunctionAssertions.createExpression(io.prestosql.operator.scalar.FunctionAssertions.createExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Expression(io.prestosql.sql.tree.Expression)

Example 7 with Expression

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

the class TestSimplifyExpressions method assertSimplifies.

private static void assertSimplifies(String expression, String expected) {
    Expression actualExpression = rewriteIdentifiersToSymbolReferences(SQL_PARSER.createExpression(expression));
    Expression expectedExpression = rewriteIdentifiersToSymbolReferences(SQL_PARSER.createExpression(expected));
    Expression rewritten = rewrite(actualExpression, TEST_SESSION, new PlanSymbolAllocator(booleanSymbolTypeMapFor(actualExpression)), METADATA, LITERAL_ENCODER, new TypeAnalyzer(SQL_PARSER, METADATA));
    assertEquals(normalize(rewritten), normalize(expectedExpression));
}
Also used : LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) ExpressionUtils.binaryExpression(io.prestosql.sql.ExpressionUtils.binaryExpression) Expression(io.prestosql.sql.tree.Expression) PlanSymbolAllocator(io.prestosql.sql.planner.PlanSymbolAllocator) TypeAnalyzer(io.prestosql.sql.planner.TypeAnalyzer)

Example 8 with Expression

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

the class TestExpressionEquivalence method assertNotEquivalent.

private static void assertNotEquivalent(@Language("SQL") String left, @Language("SQL") String right) {
    ParsingOptions parsingOptions = new ParsingOptions(AS_DOUBLE);
    Expression leftExpression = rewriteIdentifiersToSymbolReferences(SQL_PARSER.createExpression(left, parsingOptions));
    Expression rightExpression = rewriteIdentifiersToSymbolReferences(SQL_PARSER.createExpression(right, parsingOptions));
    Set<Symbol> symbols = extractUnique(ImmutableList.of(leftExpression, rightExpression));
    TypeProvider types = TypeProvider.copyOf(symbols.stream().collect(toMap(identity(), TestExpressionEquivalence::generateType)));
    assertFalse(EQUIVALENCE.areExpressionsEquivalent(TEST_SESSION, leftExpression, rightExpression, types), format("Expected (%s) and (%s) to not be equivalent", left, right));
    assertFalse(EQUIVALENCE.areExpressionsEquivalent(TEST_SESSION, rightExpression, leftExpression, types), format("Expected (%s) and (%s) to not be equivalent", right, left));
}
Also used : ParsingOptions(io.prestosql.sql.parser.ParsingOptions) Expression(io.prestosql.sql.tree.Expression) Symbol(io.prestosql.spi.plan.Symbol) TypeProvider(io.prestosql.sql.planner.TypeProvider)

Example 9 with Expression

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

the class TestSqlParser method assertInvalidExpression.

private static void assertInvalidExpression(String expression, String expectedErrorMessageRegex) {
    try {
        Expression result = SQL_PARSER.createExpression(expression);
        fail("Expected to throw ParsingException for input:[" + expression + "], but got: " + result);
    } catch (ParsingException e) {
        if (!e.getErrorMessage().matches(expectedErrorMessageRegex)) {
            fail(format("Expected error message to match '%s', but was: '%s'", expectedErrorMessageRegex, e.getErrorMessage()));
        }
    }
}
Also used : LambdaExpression(io.prestosql.sql.tree.LambdaExpression) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression) IfExpression(io.prestosql.sql.tree.IfExpression) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression) ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) SubscriptExpression(io.prestosql.sql.tree.SubscriptExpression) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) QuantifiedComparisonExpression(io.prestosql.sql.tree.QuantifiedComparisonExpression) NullIfExpression(io.prestosql.sql.tree.NullIfExpression)

Example 10 with Expression

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

the class ValuesMatcher method detailMatches.

@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
    ValuesNode valuesNode = (ValuesNode) node;
    if (!expectedRows.map(rows -> rows.equals(valuesNode.getRows().stream().map(rowExpressions -> rowExpressions.stream().map(rowExpression -> {
        if (isExpression(rowExpression)) {
            return castToExpression(rowExpression);
        }
        ConstantExpression expression = (ConstantExpression) rowExpression;
        if (expression.getType().getJavaType() == boolean.class) {
            return new BooleanLiteral(String.valueOf(expression.getValue()));
        }
        if (expression.getType().getJavaType() == long.class) {
            return new LongLiteral(String.valueOf(expression.getValue()));
        }
        if (expression.getType().getJavaType() == double.class) {
            return new DoubleLiteral(String.valueOf(expression.getValue()));
        }
        if (expression.getType().getJavaType() == Slice.class) {
            return new StringLiteral(String.valueOf(expression.getValue()));
        }
        return new GenericLiteral(expression.getType().toString(), String.valueOf(expression.getValue()));
    }).collect(toImmutableList())).collect(toImmutableList()))).orElse(true)) {
        return NO_MATCH;
    }
    return match(SymbolAliases.builder().putAll(Maps.transformValues(outputSymbolAliases, index -> toSymbolReference(valuesNode.getOutputSymbols().get(index)))).build());
}
Also used : Slice(io.airlift.slice.Slice) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) OriginalExpressionUtils.isExpression(io.prestosql.sql.relational.OriginalExpressionUtils.isExpression) BooleanLiteral(io.prestosql.sql.tree.BooleanLiteral) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) NO_MATCH(io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH) StatsProvider(io.prestosql.cost.StatsProvider) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) MatchResult.match(io.prestosql.sql.planner.assertions.MatchResult.match) PlanNode(io.prestosql.spi.plan.PlanNode) Maps(com.google.common.collect.Maps) Metadata(io.prestosql.metadata.Metadata) Preconditions.checkState(com.google.common.base.Preconditions.checkState) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) ValuesNode(io.prestosql.spi.plan.ValuesNode) List(java.util.List) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) GenericLiteral(io.prestosql.sql.tree.GenericLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) StringLiteral(io.prestosql.sql.tree.StringLiteral) Optional(java.util.Optional) Expression(io.prestosql.sql.tree.Expression) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) ValuesNode(io.prestosql.spi.plan.ValuesNode) StringLiteral(io.prestosql.sql.tree.StringLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) BooleanLiteral(io.prestosql.sql.tree.BooleanLiteral) Slice(io.airlift.slice.Slice) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) GenericLiteral(io.prestosql.sql.tree.GenericLiteral)

Aggregations

Expression (io.prestosql.sql.tree.Expression)206 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)114 RowExpression (io.prestosql.spi.relation.RowExpression)80 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)80 InListExpression (io.prestosql.sql.tree.InListExpression)73 Symbol (io.prestosql.spi.plan.Symbol)68 NotExpression (io.prestosql.sql.tree.NotExpression)58 PlanNode (io.prestosql.spi.plan.PlanNode)47 CallExpression (io.prestosql.spi.relation.CallExpression)47 ArithmeticBinaryExpression (io.prestosql.sql.tree.ArithmeticBinaryExpression)43 ArrayList (java.util.ArrayList)42 Test (org.testng.annotations.Test)42 Type (io.prestosql.spi.type.Type)41 DereferenceExpression (io.prestosql.sql.tree.DereferenceExpression)41 LambdaExpression (io.prestosql.sql.tree.LambdaExpression)41 ImmutableList (com.google.common.collect.ImmutableList)40 List (java.util.List)40 LogicalBinaryExpression (io.prestosql.sql.tree.LogicalBinaryExpression)38 SymbolReference (io.prestosql.sql.tree.SymbolReference)36 OriginalExpressionUtils.castToExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression)35