private boolean areExpressionsEquivalent(Expression leftExpression, Expression rightExpression) { return expressionEquivalence.areExpressionsEquivalent(session, leftExpression, rightExpression, types); }
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 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) { Expression leftExpression = SQL_PARSER.createExpression(left); Expression rightExpression = SQL_PARSER.createExpression(right); Set<Symbol> symbols = extractUnique(ImmutableList.of(leftExpression, rightExpression)); Map<Symbol, Type> types = 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 assertNotEquivalent(@Language("SQL") String left, @Language("SQL") String right) { Expression leftExpression = SQL_PARSER.createExpression(left); Expression rightExpression = SQL_PARSER.createExpression(right); Set<Symbol> symbols = extractUnique(ImmutableList.of(leftExpression, rightExpression)); Map<Symbol, Type> types = 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)); }
if (leftSource != node.getLeft() || rightSource != node.getRight() || !expressionEquivalence.areExpressionsEquivalent(session, newJoinPredicate, joinPredicate, types)) { if (newJoinPredicate.equals(BooleanLiteral.TRUE_LITERAL)) { output = new JoinNode(node.getId(), INNER, leftSource, rightSource, ImmutableList.of(), Optional.<Symbol>empty(), Optional.<Symbol>empty());