Search in sources :

Example 11 with ParsingOptions

use of com.facebook.presto.sql.parser.ParsingOptions in project presto by prestodb.

the class TestRowExpressionSerde method assertThrowsWhenSerialize.

private void assertThrowsWhenSerialize(@Language("SQL") String sql, boolean optimize) {
    RowExpression rowExpression = translate(expression(sql, new ParsingOptions(AS_DOUBLE)), optimize);
    assertThrows(IllegalArgumentException.class, () -> codec.toJson(rowExpression));
}
Also used : ParsingOptions(com.facebook.presto.sql.parser.ParsingOptions) RowExpression(com.facebook.presto.spi.relation.RowExpression)

Example 12 with ParsingOptions

use of com.facebook.presto.sql.parser.ParsingOptions in project presto by prestodb.

the class TestExpressionEquivalence method assertEquivalent.

private static void assertEquivalent(@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.viewOf(symbols.stream().collect(toImmutableMap(Symbol::getName, TestExpressionEquivalence::generateType)));
    assertTrue(EQUIVALENCE.areExpressionsEquivalent(TEST_SESSION, leftExpression, rightExpression, types), String.format("Expected (%s) and (%s) to be equivalent", left, right));
    assertTrue(EQUIVALENCE.areExpressionsEquivalent(TEST_SESSION, rightExpression, leftExpression, types), String.format("Expected (%s) and (%s) to be equivalent", right, left));
}
Also used : ParsingOptions(com.facebook.presto.sql.parser.ParsingOptions) Expression(com.facebook.presto.sql.tree.Expression) Symbol(com.facebook.presto.sql.planner.Symbol) TypeProvider(com.facebook.presto.sql.planner.TypeProvider)

Example 13 with ParsingOptions

use of com.facebook.presto.sql.parser.ParsingOptions in project presto by prestodb.

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.viewOf(symbols.stream().collect(toImmutableMap(Symbol::getName, TestExpressionEquivalence::generateType)));
    assertFalse(EQUIVALENCE.areExpressionsEquivalent(TEST_SESSION, leftExpression, rightExpression, types), String.format("Expected (%s) and (%s) to not be equivalent", left, right));
    assertFalse(EQUIVALENCE.areExpressionsEquivalent(TEST_SESSION, rightExpression, leftExpression, types), String.format("Expected (%s) and (%s) to not be equivalent", right, left));
}
Also used : ParsingOptions(com.facebook.presto.sql.parser.ParsingOptions) Expression(com.facebook.presto.sql.tree.Expression) Symbol(com.facebook.presto.sql.planner.Symbol) TypeProvider(com.facebook.presto.sql.planner.TypeProvider)

Aggregations

ParsingOptions (com.facebook.presto.sql.parser.ParsingOptions)13 RowExpression (com.facebook.presto.spi.relation.RowExpression)5 SqlParser (com.facebook.presto.sql.parser.SqlParser)5 Expression (com.facebook.presto.sql.tree.Expression)4 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)2 ParsingException (com.facebook.presto.sql.parser.ParsingException)2 Symbol (com.facebook.presto.sql.planner.Symbol)2 TypeProvider (com.facebook.presto.sql.planner.TypeProvider)2 Statement (com.facebook.presto.sql.tree.Statement)2 BenchmarkPrestoActionFactory (com.facebook.presto.benchmark.prestoaction.BenchmarkPrestoActionFactory)1 PrestoActionFactory (com.facebook.presto.benchmark.prestoaction.PrestoActionFactory)1 PrestoClusterConfig (com.facebook.presto.benchmark.prestoaction.PrestoClusterConfig)1 PrestoExceptionClassifier (com.facebook.presto.benchmark.prestoaction.PrestoExceptionClassifier)1 RetryConfig (com.facebook.presto.benchmark.retry.RetryConfig)1 PrestoException (com.facebook.presto.spi.PrestoException)1 ParsingUtil.createParsingOptions (com.facebook.presto.sql.ParsingUtil.createParsingOptions)1 SqlParserOptions (com.facebook.presto.sql.parser.SqlParserOptions)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 Test (org.testng.annotations.Test)1