@Override protected Void visitIntersect(Intersect node, Integer indent) { Iterator<Relation> relations = node.getRelations().iterator(); while (relations.hasNext()) { processRelation(relations.next(), indent); if (relations.hasNext()) { builder.append(indentString(indent)); builder.append("INTERSECT "); if (!node.isDistinct()) { builder.append("ALL "); } } } return null; }
@Override protected Void visitIntersect(Intersect node, Integer indent) { Iterator<Relation> relations = node.getRelations().iterator(); while (relations.hasNext()) { processRelation(relations.next(), indent); if (relations.hasNext()) { builder.append("INTERSECT "); if (!node.isDistinct()) { builder.append("ALL "); } } } return null; }
@Override public Node visitSetOperation(SqlBaseParser.SetOperationContext context) { QueryBody left = (QueryBody) visit(context.left); QueryBody right = (QueryBody) visit(context.right); boolean distinct = context.setQuantifier() == null || context.setQuantifier().DISTINCT() != null; switch (context.operator.getType()) { case SqlBaseLexer.UNION: return new Union(getLocation(context.UNION()), ImmutableList.of(left, right), distinct); case SqlBaseLexer.INTERSECT: return new Intersect(getLocation(context.INTERSECT()), ImmutableList.of(left, right), distinct); case SqlBaseLexer.EXCEPT: return new Except(getLocation(context.EXCEPT()), left, right, distinct); } throw new IllegalArgumentException("Unsupported set operation: " + context.operator.getText()); }
@Test public void testIntersect() { assertStatement("SELECT 123 INTERSECT DISTINCT SELECT 123 INTERSECT ALL SELECT 123", new Query( Optional.empty(), new Intersect(ImmutableList.of( new Intersect(ImmutableList.of(createSelect123(), createSelect123()), true), createSelect123() ), false), ImmutableList.of(), Optional.empty(), Optional.empty())); }
@Override protected RelationType visitIntersect(Intersect node, AnalysisContext context) { throw new SemanticException(NOT_SUPPORTED, node, "INTERSECT not yet implemented"); }