@Override public Node visitExplainType(SqlBaseParser.ExplainTypeContext context) { switch (context.value.getType()) { case SqlBaseLexer.LOGICAL: return new ExplainType(getLocation(context), ExplainType.Type.LOGICAL); case SqlBaseLexer.DISTRIBUTED: return new ExplainType(getLocation(context), ExplainType.Type.DISTRIBUTED); case SqlBaseLexer.VALIDATE: return new ExplainType(getLocation(context), ExplainType.Type.VALIDATE); case SqlBaseLexer.IO: return new ExplainType(getLocation(context), ExplainType.Type.IO); } throw new IllegalArgumentException("Unsupported EXPLAIN type: " + context.value.getText()); }
@Override protected Scope visitExplain(Explain node, Optional<Scope> scope) throws SemanticException { checkState(node.isAnalyze(), "Non analyze explain should be rewritten to Query"); if (node.getOptions().stream().anyMatch(option -> !option.equals(new ExplainType(DISTRIBUTED)))) { throw new SemanticException(NOT_SUPPORTED, node, "EXPLAIN ANALYZE only supports TYPE DISTRIBUTED option"); } process(node.getStatement(), scope); analysis.setUpdateType(null); return createAndAssignScope(node, scope, Field.newUnqualified("Query Plan", VARCHAR)); }
@Test public void testExplainVerboseTypeLogical() { assertStatement("EXPLAIN VERBOSE (type LOGICAL) SELECT * FROM t", new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false, true, ImmutableList.of(new ExplainType(ExplainType.Type.LOGICAL)))); }
@Test public void testExplainAnalyzeTypeDistributed() { assertStatement("EXPLAIN ANALYZE (type DISTRIBUTED) SELECT * FROM t", new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), true, false, ImmutableList.of(new ExplainType(ExplainType.Type.DISTRIBUTED)))); }
@Test public void testExplainAnalyzeVerboseTypeDistributed() { assertStatement("EXPLAIN ANALYZE VERBOSE (type DISTRIBUTED) SELECT * FROM t", new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), true, true, ImmutableList.of(new ExplainType(ExplainType.Type.DISTRIBUTED)))); }
@Test public void testExplain() { assertStatement("EXPLAIN SELECT * FROM t", new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false, false, ImmutableList.of())); assertStatement("EXPLAIN (TYPE LOGICAL) SELECT * FROM t", new Explain( simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false, false, ImmutableList.of(new ExplainType(ExplainType.Type.LOGICAL)))); assertStatement("EXPLAIN (TYPE LOGICAL, FORMAT TEXT) SELECT * FROM t", new Explain( simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false, false, ImmutableList.of( new ExplainType(ExplainType.Type.LOGICAL), new ExplainFormat(ExplainFormat.Type.TEXT)))); }
@Override public Node visitExplainType(SqlBaseParser.ExplainTypeContext context) { switch (context.value.getType()) { case SqlBaseLexer.LOGICAL: return new ExplainType(getLocation(context), ExplainType.Type.LOGICAL); case SqlBaseLexer.DISTRIBUTED: return new ExplainType(getLocation(context), ExplainType.Type.DISTRIBUTED); } throw new IllegalArgumentException("Unsupported EXPLAIN type: " + context.value.getText()); }
@Override public Node visitExplainType(SqlBaseParser.ExplainTypeContext context) { switch (context.value.getType()) { case SqlBaseLexer.LOGICAL: return new ExplainType(getLocation(context), ExplainType.Type.LOGICAL); case SqlBaseLexer.DISTRIBUTED: return new ExplainType(getLocation(context), ExplainType.Type.DISTRIBUTED); case SqlBaseLexer.VALIDATE: return new ExplainType(getLocation(context), ExplainType.Type.VALIDATE); case SqlBaseLexer.IO: return new ExplainType(getLocation(context), ExplainType.Type.IO); } throw new IllegalArgumentException("Unsupported EXPLAIN type: " + context.value.getText()); }
@Test public void testExplainAnalyzeVerboseTypeDistributed() { assertStatement("EXPLAIN ANALYZE VERBOSE (type DISTRIBUTED) SELECT * FROM t", new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), true, true, ImmutableList.of(new ExplainType(ExplainType.Type.DISTRIBUTED)))); }
@Test public void testExplainVerboseTypeLogical() { assertStatement("EXPLAIN VERBOSE (type LOGICAL) SELECT * FROM t", new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false, true, ImmutableList.of(new ExplainType(ExplainType.Type.LOGICAL)))); }
@Test public void testExplainAnalyzeTypeDistributed() { assertStatement("EXPLAIN ANALYZE (type DISTRIBUTED) SELECT * FROM t", new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), true, false, ImmutableList.of(new ExplainType(ExplainType.Type.DISTRIBUTED)))); }
if (node.getOptions().stream().anyMatch(option -> !option.equals(new ExplainType(DISTRIBUTED)))) { throw new SemanticException(NOT_SUPPORTED, node, "EXPLAIN ANALYZE only supports TYPE DISTRIBUTED option");
@Test public void testExplain() throws Exception { assertStatement("EXPLAIN SELECT * FROM t", new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false, ImmutableList.of())); assertStatement("EXPLAIN (TYPE LOGICAL) SELECT * FROM t", new Explain( simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false, ImmutableList.of(new ExplainType(ExplainType.Type.LOGICAL)))); assertStatement("EXPLAIN (TYPE LOGICAL, FORMAT TEXT) SELECT * FROM t", new Explain( simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false, ImmutableList.of( new ExplainType(ExplainType.Type.LOGICAL), new ExplainFormat(ExplainFormat.Type.TEXT)))); }
@Test public void testExplain() { assertStatement("EXPLAIN SELECT * FROM t", new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false, false, ImmutableList.of())); assertStatement("EXPLAIN (TYPE LOGICAL) SELECT * FROM t", new Explain( simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false, false, ImmutableList.of(new ExplainType(ExplainType.Type.LOGICAL)))); assertStatement("EXPLAIN (TYPE LOGICAL, FORMAT TEXT) SELECT * FROM t", new Explain( simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), false, false, ImmutableList.of( new ExplainType(ExplainType.Type.LOGICAL), new ExplainFormat(ExplainFormat.Type.TEXT)))); }