public static Expression combinePredicates(LogicalBinaryExpression.Operator operator, Collection<Expression> expressions) { if (operator == LogicalBinaryExpression.Operator.AND) { return combineConjuncts(expressions); } return combineDisjuncts(expressions); }
public List<SqlPathElement> getParsedPath() { if (parsedPath == null) { parsePath(); } return parsedPath; }
public static List<Expression> extractDisjuncts(Expression expression) { return extractPredicates(LogicalBinaryExpression.Operator.OR, expression); }
@Override protected Void visitAliasedRelation(AliasedRelation node, Integer indent) { process(node.getRelation(), indent); builder.append(' ') .append(formatExpression(node.getAlias(), parameters)); appendAliasColumns(builder, node.getColumnNames()); return null; }
private String formatColumnDefinition(ColumnDefinition column) { return formatExpression(column.getName(), parameters) + " " + column.getType() + column.getComment() .map(comment -> " COMMENT " + formatStringLiteral(comment)) .orElse("") + formatPropertiesSingleLine(column.getProperties()); }
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))); }
@Override protected Void visitRenameSchema(RenameSchema node, Integer context) { builder.append("ALTER SCHEMA ") .append(formatName(node.getSource())) .append(" RENAME TO ") .append(formatExpression(node.getTarget(), parameters)); return null; }
@Override protected Void visitDropColumn(DropColumn node, Integer context) { builder.append("ALTER TABLE ") .append(formatName(node.getTable())) .append(" DROP COLUMN ") .append(formatExpression(node.getColumn(), parameters)); return null; }
@Test(expectedExceptions = ParsingException.class, expectedExceptionsMessageRegExp = "\\Qline 1:9: mismatched input '.'. Expecting: ',', <EOF>\\E") public void testInvalidPath() { SqlEnvironmentConfig config = new SqlEnvironmentConfig().setPath("too.many.qualifiers"); new SqlPath(config.getPath()).getParsedPath(); } }
public static Expression and(Collection<Expression> expressions) { return binaryExpression(LogicalBinaryExpression.Operator.AND, expressions); }
@Override protected Void visitOrderBy(OrderBy node, Integer indent) { append(indent, formatOrderBy(node, parameters)) .append('\n'); return null; }
public static Expression combineDisjuncts(Collection<Expression> expressions) { return combineDisjunctsWithDefault(expressions, FALSE_LITERAL); }
private static void assertNormalize(Expression expression) { assertNormalize(expression, expression); }
private RowExpression translateAndOptimize(Expression expression) { return translateAndOptimize(expression, getExpressionTypes(expression)); }
public static Expression filterDeterministicConjuncts(Expression expression) { return filterConjuncts(expression, DeterminismEvaluator::isDeterministic); }
public static List<Expression> extractConjuncts(Expression expression) { return extractPredicates(LogicalBinaryExpression.Operator.AND, expression); }
public static Expression or(Collection<Expression> expressions) { return binaryExpression(LogicalBinaryExpression.Operator.OR, expressions); }
private String visitFilter(Expression node, Void context) { return "(WHERE " + process(node, context) + ')'; }