Java 类com.facebook.presto.sql.tree.Explain 实例源码

项目:sql4es    文件:ESStatement.java   
@Override
public ResultSet executeQuery(String sql) throws SQLException {
    //System.out.println("QUERY: ["+sql+"]");
    if(connection.getSchema() == null) throw new SQLException("No active index set for this driver. Pleas specify an active index or alias by executing 'USE <index/alias>' first");
    sql = sql.replaceAll("\r", " ").replaceAll("\n", " ");
    com.facebook.presto.sql.tree.Statement statement = parser.createStatement(sql);
    if(statement instanceof Query){
        if(this.result != null) this.result.close();
        queryState.buildRequest(sql, ((Query)statement).getQueryBody(), connection.getSchema());
        this.result = queryState.execute();
        return this.result;
    }else if(statement instanceof Explain){
        String ex = queryState.explain(sql, (Explain)statement, connection.getSchema());
        if(this.result != null) this.result.close();
        Heading heading = new Heading();
        heading.add(new Column("Explanation"));
        ESResultSet rs = new ESResultSet(heading, 1, 1);
        List<Object> row = rs.getNewRow();
        row.set(0, ex);
        rs.add(row);
        this.result = rs;
        return result;
    }else throw new SQLException("Provided query is not a SELECT or EXPLAIN query");
}
项目:presto    文件:TestSqlParser.java   
@Test
public void testExplain()
        throws Exception
{
    assertStatement("EXPLAIN SELECT * FROM t",
            new Explain(simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))), ImmutableList.of()));
    assertStatement("EXPLAIN (TYPE LOGICAL) SELECT * FROM t",
            new Explain(
                    simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("t"))),
                    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"))),
                    ImmutableList.of(
                            new ExplainType(ExplainType.Type.LOGICAL),
                            new ExplainFormat(ExplainFormat.Type.TEXT))));
}
项目:presto-query-formatter    文件:StatementFormatter.java   
@Override
protected Void visitExplain(Explain node, Integer indent)
{
    builder.append("EXPLAIN ");
    if (node.isAnalyze()) {
        builder.append("ANALYZE ");
    }

    List<String> options = new ArrayList<>();

    for (ExplainOption option : node.getOptions()) {
        if (option instanceof ExplainType) {
            options.add("TYPE " + ((ExplainType) option).getType());
        }
        else if (option instanceof ExplainFormat) {
            options.add("FORMAT " + ((ExplainFormat) option).getType());
        }
        else {
            throw new UnsupportedOperationException("unhandled explain option: " + option);
        }
    }

    if (!options.isEmpty()) {
        builder.append("(");
        Joiner.on(", ").appendTo(builder, options);
        builder.append(")");
    }

    builder.append("\n");

    process(node.getStatement(), indent);

    return null;
}
项目:presto    文件:StatementAnalyzer.java   
private String getQueryPlan(Explain node, ExplainType.Type planType, ExplainFormat.Type planFormat)
        throws IllegalArgumentException
{
    switch (planFormat) {
        case GRAPHVIZ:
            return queryExplainer.get().getGraphvizPlan(session, node.getStatement(), planType);
        case TEXT:
            return queryExplainer.get().getPlan(session, node.getStatement(), planType);
    }
    throw new IllegalArgumentException("Invalid Explain Format: " + planFormat.toString());
}
项目:presto    文件:SqlFormatter.java   
@Override
protected Void visitExplain(Explain node, Integer indent)
{
    builder.append("EXPLAIN ");

    List<String> options = new ArrayList<>();

    for (ExplainOption option : node.getOptions()) {
        if (option instanceof ExplainType) {
            options.add("TYPE " + ((ExplainType) option).getType());
        }
        else if (option instanceof ExplainFormat) {
            options.add("FORMAT " + ((ExplainFormat) option).getType());
        }
        else {
            throw new UnsupportedOperationException("unhandled explain option: " + option);
        }
    }

    if (!options.isEmpty()) {
        builder.append("(");
        Joiner.on(", ").appendTo(builder, options);
        builder.append(")");
    }

    builder.append("\n");

    process(node.getStatement(), indent);

    return null;
}
项目:EchoQuery    文件:SqlFormatter.java   
@Override
protected Void visitExplain(Explain node, Integer indent)
{
    builder.append("EXPLAIN ");

    List<String> options = new ArrayList<>();

    for (ExplainOption option : node.getOptions()) {
        if (option instanceof ExplainType) {
            options.add("TYPE " + ((ExplainType) option).getType());
        }
        else if (option instanceof ExplainFormat) {
            options.add("FORMAT " + ((ExplainFormat) option).getType());
        }
        else {
            throw new UnsupportedOperationException("unhandled explain option: " + option);
        }
    }

    if (!options.isEmpty()) {
        builder.append("(");
        Joiner.on(", ").appendTo(builder, options);
        builder.append(")");
    }

    builder.append("\n");

    process(node.getStatement(), indent);

    return null;
}
项目:presto    文件:AstBuilder.java   
@Override
public Node visitExplain(SqlBaseParser.ExplainContext context)
{
    return new Explain(getLocation(context), (Statement) visit(context.statement()), visit(context.explainOption(), ExplainOption.class));
}