@Override public Expression deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { return rewriteIdentifiersToSymbolReferences(sqlParser.createExpression(jsonParser.readValueAs(String.class))); } }
@Override public FunctionCall deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { return (FunctionCall) rewriteIdentifiersToSymbolReferences(sqlParser.createExpression(jsonParser.readValueAs(String.class))); } }
private Expression expression(String sqlExpression) { return rewriteIdentifiersToSymbolReferences(sqlParser.createExpression(sqlExpression)); } }
private Expression expression(String sql) { return rewriteIdentifiersToSymbolReferences(parser.createExpression(sql)); }
private Expression expression(String sql) { SqlParser parser = new SqlParser(); return rewriteIdentifiersToSymbolReferences(parser.createExpression(sql)); }
public static Expression expression(String sql) { return ExpressionUtils.rewriteIdentifiersToSymbolReferences(new SqlParser().createExpression(sql)); }
private Expression expression(String sql) { return rewriteIdentifiersToSymbolReferences(new SqlParser().createExpression(sql)); }
private static void assertNotEquivalent(@Language("SQL") String left, @Language("SQL") String right) { ParsingOptions parsingOptions = new ParsingOptions(AS_DOUBLE /* anything */); 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), 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)); }
private static void assertEquivalent(@Language("SQL") String left, @Language("SQL") String right) { ParsingOptions parsingOptions = new ParsingOptions(AS_DOUBLE /* anything */); 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))); 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)); }
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 SymbolAllocator(booleanSymbolTypeMapFor(actualExpression)), METADATA, LITERAL_ENCODER, SQL_PARSER); assertEquals( normalize(rewritten), normalize(expectedExpression)); }
public static PlanMatchPattern filter(String expectedPredicate, PlanMatchPattern source) { return filter(rewriteIdentifiersToSymbolReferences(new SqlParser().createExpression(expectedPredicate)), source); }
private static void assertOptimizedMatches(@Language("SQL") String actual, @Language("SQL") String expected) { // replaces FunctionCalls to FailureFunction by fail() Object actualOptimized = optimize(actual); if (actualOptimized instanceof Expression) { actualOptimized = ExpressionTreeRewriter.rewriteWith(new FailedFunctionRewriter(), (Expression) actualOptimized); } assertEquals( actualOptimized, rewriteIdentifiersToSymbolReferences(SQL_PARSER.createExpression(expected))); }
public static PlanMatchPattern join(JoinNode.Type joinType, List<ExpectedValueProvider<JoinNode.EquiJoinClause>> expectedEquiCriteria, Optional<String> expectedFilter, Optional<JoinNode.DistributionType> expectedDistributionType, PlanMatchPattern left, PlanMatchPattern right) { return node(JoinNode.class, left, right).with( new JoinMatcher( joinType, expectedEquiCriteria, expectedFilter.map(predicate -> rewriteIdentifiersToSymbolReferences(new SqlParser().createExpression(predicate))), expectedDistributionType)); }
public static PlanMatchPattern spatialLeftJoin(String expectedFilter, PlanMatchPattern left, PlanMatchPattern right) { return node(SpatialJoinNode.class, left, right).with( new SpatialJoinMatcher(SpatialJoinNode.Type.LEFT, rewriteIdentifiersToSymbolReferences(new SqlParser().createExpression(expectedFilter, new ParsingOptions())), Optional.empty())); }
parsedExpression = rewriteIdentifiersToSymbolReferences(parsedExpression);
public static PlanMatchPattern spatialJoin(String expectedFilter, Optional<String> kdbTree, PlanMatchPattern left, PlanMatchPattern right) { return node(SpatialJoinNode.class, left, right).with( new SpatialJoinMatcher(SpatialJoinNode.Type.INNER, rewriteIdentifiersToSymbolReferences(new SqlParser().createExpression(expectedFilter, new ParsingOptions())), kdbTree)); }