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

项目:hue    文件:TreePrinter.java   
public static void printStatement(String sql)
{
    println(sql.trim());
    println("");

    System.out.println("STATE Printing CommonTree toString...");
    CommonTree tree = VeroSqlParser.parseStatement(sql);
    println(TreePrinter.treeToString(tree));
    println("");

    System.out.println("STATE Printing AST toString...");
    Statement statement = VeroSqlParser.createStatement(tree);
    println(statement.toString());
    println("");

    System.out.println("STATE Printing Format sql toString...");
    // TODO: support formatting all statement types
    if (statement instanceof Query) {
        println(FormatterFactory.getSqlFormatter().formatSql(statement));
        println("");
    }

    println(repeat("=", 60));
    println("");
}
项目:presto    文件:CreateViewTask.java   
private String getFormattedSql(CreateView statement)
{
    Query query = statement.getQuery();
    String sql = formatSql(query);

    // verify round-trip
    Statement parsed;
    try {
        parsed = sqlParser.createStatement(sql);
    }
    catch (ParsingException e) {
        throw new PrestoException(INTERNAL_ERROR, "Formatted query does not parse: " + query);
    }
    if (!query.equals(parsed)) {
        throw new PrestoException(INTERNAL_ERROR, "Query does not round-trip: " + query);
    }

    return sql;
}
项目:presto    文件:DataDefinitionExecution.java   
@Inject
public DataDefinitionExecutionFactory(
        LocationFactory locationFactory,
        TransactionManager transactionManager,
        MetadataManager metadata,
        AccessControl accessControl,
        @ForQueryExecution ExecutorService executor,
        Map<Class<? extends Statement>, DataDefinitionTask<?>> tasks)
{
    this.locationFactory = requireNonNull(locationFactory, "locationFactory is null");
    this.transactionManager = requireNonNull(transactionManager, "transactionManager is null");
    this.metadata = requireNonNull(metadata, "metadata is null");
    this.accessControl = requireNonNull(accessControl, "accessControl is null");
    this.executor = requireNonNull(executor, "executor is null");
    this.tasks = requireNonNull(tasks, "tasks is null");
}
项目:presto    文件:DataDefinitionExecution.java   
@Override
public DataDefinitionExecution<?> createQueryExecution(
        QueryId queryId,
        String query,
        Session session,
        Statement statement)
{
    URI self = locationFactory.createQueryLocation(queryId);

    DataDefinitionTask<Statement> task = getTask(statement);
    checkArgument(task != null, "no task for statement: %s", statement.getClass().getSimpleName());

    QueryStateMachine stateMachine = QueryStateMachine.begin(queryId, query, session, self, task.isTransactionControl(), transactionManager, executor);
    stateMachine.setUpdateType(task.getName());
    return new DataDefinitionExecution<>(task, statement, transactionManager, metadata, accessControl, stateMachine);
}
项目:presto    文件:QueryExplainer.java   
@Inject
public QueryExplainer(
        List<PlanOptimizer> planOptimizers,
        Metadata metadata,
        AccessControl accessControl,
        SqlParser sqlParser,
        Map<Class<? extends Statement>, DataDefinitionTask<?>> dataDefinitionTask,
        FeaturesConfig featuresConfig)
{
    this(planOptimizers,
            metadata,
            accessControl,
            sqlParser,
            dataDefinitionTask,
            featuresConfig.isExperimentalSyntaxEnabled());
}
项目:presto    文件:QueryExplainer.java   
public String getPlan(Session session, Statement statement, Type planType)
{
    DataDefinitionTask<?> task = dataDefinitionTask.get(statement.getClass());
    if (task != null) {
        return explainTask(statement, task);
    }

    switch (planType) {
        case LOGICAL:
            Plan plan = getLogicalPlan(session, statement);
            return PlanPrinter.textLogicalPlan(plan.getRoot(), plan.getTypes(), metadata, session);
        case DISTRIBUTED:
            SubPlan subPlan = getDistributedPlan(session, statement);
            return PlanPrinter.textDistributedPlan(subPlan, metadata, session);
    }
    throw new IllegalArgumentException("Unhandled plan type: " + planType);
}
项目:presto    文件:QueryExplainer.java   
public String getGraphvizPlan(Session session, Statement statement, Type planType)
{
    DataDefinitionTask<?> task = dataDefinitionTask.get(statement.getClass());
    if (task != null) {
        // todo format as graphviz
        return explainTask(statement, task);
    }

    switch (planType) {
        case LOGICAL:
            Plan plan = getLogicalPlan(session, statement);
            return PlanPrinter.graphvizLogicalPlan(plan.getRoot(), plan.getTypes());
        case DISTRIBUTED:
            SubPlan subPlan = getDistributedPlan(session, statement);
            return PlanPrinter.graphvizDistributedPlan(subPlan);
    }
    throw new IllegalArgumentException("Unhandled plan type: " + planType);
}
项目:presto    文件:TestStatementBuilder.java   
private static void printStatement(String sql)
{
    println(sql.trim());
    println("");

    Statement statement = SQL_PARSER.createStatement(sql);
    println(statement.toString());
    println("");

    println(SqlFormatter.formatSql(statement));
    println("");
    assertFormattedSql(SQL_PARSER, statement);

    println(repeat("=", 60));
    println("");
}
项目:rakam    文件:TestQueryFormatter.java   
@Test
public void testSimpleQuery()
        throws Exception {
    Statement statement = new SqlParser().createStatement("select * from testcollection");

    assertEquals(formatQuery(statement, name -> "dummy", '"').trim(), "SELECT *\n" +
            "   FROM\n" +
            "     dummy");
}
项目:rakam    文件:TestFuturistic.java   
@Test(enabled = false)
    public void testName()
            throws Exception {
        String s = "select count(*) from test where ali = 5";
        Statement statement = new SqlParser().createStatement(s);
        Analysis analysis = new Analysis(statement, ImmutableList.of(), false);
        Session build = Session.builder(new SessionPropertyManager())
                .setQueryId(QueryId.valueOf("test"))
                .setCatalog("test")
                .setCatalog("test")
                .setCatalog("test")
                .build();
        QueryPlanner queryPlanner = new QueryPlanner(analysis, new SymbolAllocator(), new PlanNodeIdAllocator(), null, null, build);
        RelationPlan plan = queryPlanner.plan((Query) statement);
//        EffectivePredicateExtractor.extract(plan.getRoot(), ImmutableMap.of(new Symbol("ali"), BIGINT));
        EffectivePredicateExtractor.extract(plan.getRoot());
    }
项目:airpal    文件:QueryExecutionAuthorizer.java   
public static Set<Table> tablesUsedByQuery(String query, String defaultConnector, String defaultSchema)
{
    List<String> statements = STATEMENT_SPLITTER.splitToList(query);
    ImmutableSet.Builder<Table> tables = ImmutableSet.builder();
    CatalogSchemaContext context = new CatalogSchemaContext(defaultConnector, defaultSchema);

    for (String strStatement : statements) {
        InputReferenceExtractor extractor = new InputReferenceExtractor();
        Statement statement = SQL_PARSER.createStatement(strStatement);
        context = statement.accept(extractor, context);

        tables.addAll(extractor.getReferences());
    }

    return tables.build();
}
项目:hue    文件:VeroOracleSqlFormatter.java   
public String formatSql(Node root) {
    StringBuilder builder = new StringBuilder();

    if (root instanceof Statement) {
        setOutputPassFunc(false);
        setOutputDivideByZeroGuard(true);
    } else {
        // Expression
        setOutputPassFunc(true);
        setOutputDivideByZeroGuard(true);
    }

    new Formatter(builder).process(root, 0);
    return builder.toString();
}
项目:hue    文件:VeroPrestoSqlFormatter.java   
public String formatSql(Node root) {
    StringBuilder builder = new StringBuilder();

    if (root instanceof Statement) {
        setOutputPassFunc(false);
        setOutputDivideByZeroGuard(true);
    } else {
        // Expression
        setOutputPassFunc(true);
        setOutputDivideByZeroGuard(true);
    }

    new Formatter(builder).process(root, 0);
    return builder.toString();
}
项目:hue    文件:VeroTeradataSqlFormatter.java   
public String formatSql(Node root) {
    StringBuilder builder = new StringBuilder();

    if (root instanceof Statement) {
        setOutputPassFunc(false);
        setOutputDivideByZeroGuard(true);
    } else {
        // Expression
        setOutputPassFunc(true);
        setOutputDivideByZeroGuard(true);
    }

    new Formatter(builder).process(root, 0);
    return builder.toString();
}
项目:hue    文件:VeroSalesforceSqlFormatter.java   
public String formatSql(Node root) {
    StringBuilder builder = new StringBuilder();

    if (root instanceof Statement) {
        setOutputPassFunc(false);
        setOutputDivideByZeroGuard(true);
    } else {
        // Expression
        setOutputPassFunc(true);
        setOutputDivideByZeroGuard(true);
    }

    new Formatter(builder).process(root, 0);
    return builder.toString();
}
项目:hue    文件:VeroDerbySqlFormatter.java   
public String formatSql(Node root) {
    StringBuilder builder = new StringBuilder();

    if (root instanceof Statement) {
        setOutputPassFunc(false);
        setOutputDivideByZeroGuard(true);
    } else {
        // Expression
        setOutputPassFunc(true);
        setOutputDivideByZeroGuard(true);
    }

    new Formatter(builder).process(root, 0);
    return builder.toString();
}
项目:hue    文件:VeroDrillSqlFormatter.java   
public String formatSql(Node root) {
    StringBuilder builder = new StringBuilder();

    if (root instanceof Statement) {
        setOutputPassFunc(false);
        setOutputDivideByZeroGuard(false);
    } else {
        // Expression
        setOutputPassFunc(true);
        setOutputDivideByZeroGuard(false);
    }

    new Formatter(builder).process(root, 0);
    return builder.toString();
}
项目:hue    文件:VeroMssqlSqlFormatter.java   
public String formatSql(Node root) {
    StringBuilder builder = new StringBuilder();

    if (root instanceof Statement) {
        setOutputPassFunc(false);
        setOutputDivideByZeroGuard(true);
    } else {
        // Expression
        setOutputPassFunc(true);
        setOutputDivideByZeroGuard(true);
    }

    new Formatter(builder).process(root, 0);
    return builder.toString();
}
项目:hue    文件:VeroMysqlSqlFormatter.java   
public String formatSql(Node root) {
    StringBuilder builder = new StringBuilder();

    if (root instanceof Statement) {
        setOutputPassFunc(false);
        setOutputDivideByZeroGuard(true);
    } else {
        // Expression
        setOutputPassFunc(true);
        setOutputDivideByZeroGuard(true);
    }

    new Formatter(builder).process(root, 0);
    return builder.toString();
}
项目:hue    文件:VeroPostgresqlSqlFormatter.java   
public String formatSql(Node root) {
    StringBuilder builder = new StringBuilder();

    if (root instanceof Statement) {
        setOutputPassFunc(false);
        setOutputDivideByZeroGuard(true);
    } else {
        // Expression
        setOutputPassFunc(true);
        setOutputDivideByZeroGuard(true);
    }

    new Formatter(builder).process(root, 0);
    return builder.toString();
}
项目:hue    文件:VeroRedshiftSqlFormatter.java   
public String formatSql(Node root) {
    StringBuilder builder = new StringBuilder();

    if (root instanceof Statement) {
        setOutputPassFunc(false);
        setOutputDivideByZeroGuard(true);
    } else {
        // Expression
        setOutputPassFunc(true);
        setOutputDivideByZeroGuard(true);
    }

    new Formatter(builder).process(root, 0);
    return builder.toString();
}
项目:hue    文件:VeroHiveSqlFormatter.java   
public String formatSql(Node root) {
    StringBuilder builder = new StringBuilder();

    if (root instanceof Statement) {
        setOutputPassFunc(false);
        setOutputDivideByZeroGuard(true);
    } else {
        // Expression
        setOutputPassFunc(true);
        setOutputDivideByZeroGuard(true);
    }

    new Formatter(builder).process(root, 0);
    return builder.toString();
}
项目:hue    文件:VeroAccessSqlFormatter.java   
public String formatSql(Node root) {
    StringBuilder builder = new StringBuilder();

    if (root instanceof Statement) {
        setOutputPassFunc(false);
        setOutputDivideByZeroGuard(false);
    } else {
        // Expression
        setOutputPassFunc(true);
        setOutputDivideByZeroGuard(false);
    }

    new Formatter(builder).process(root, 0);
    return builder.toString();
}
项目:hue    文件:VeroGoogleAnalyticsSqlFormatter.java   
public String formatSql(Node root) {
    StringBuilder builder = new StringBuilder();

    if (root instanceof Statement) {
        setOutputPassFunc(false);
        setOutputDivideByZeroGuard(true);
    } else {
        // Expression
        setOutputPassFunc(true);
        setOutputDivideByZeroGuard(true);
    }

    new Formatter(builder).process(root, 0);
    return builder.toString();
}
项目:hue    文件:VeroNetezzaSqlFormatter.java   
public String formatSql(Node root) {
    StringBuilder builder = new StringBuilder();

    if (root instanceof Statement) {
        setOutputPassFunc(false);
        setOutputDivideByZeroGuard(true);
    } else {
        // Expression
        setOutputPassFunc(true);
        setOutputDivideByZeroGuard(true);
    }

    new Formatter(builder).process(root, 0);
    return builder.toString();
}
项目:hue    文件:VeroVerticaSqlFormatter.java   
public String formatSql(Node root) {
    StringBuilder builder = new StringBuilder();

    if (root instanceof Statement) {
        setOutputPassFunc(false);
        setOutputDivideByZeroGuard(true);
    } else {
        // Expression
        setOutputPassFunc(true);
        setOutputDivideByZeroGuard(true);
    }

    new Formatter(builder).process(root, 0);
    return builder.toString();
}
项目:presto-query-formatter    文件:Main.java   
private static void format(String sql)
{
    Statement statement = SQL_PARSER.createStatement(sql);
    String formattedSql = formatSql(statement);
    checkState(statement.equals(SQL_PARSER.createStatement(formattedSql)), "Formatted SQL is different than original");
    System.out.println(formattedSql + ";");
}
项目:presto-query-formatter    文件:TestStatementFormatter.java   
private void testQuery(String query) {
    System.out.println(">>>> Testing: " + query);
    Statement statement = SQL_PARSER.createStatement(query);
    String formmatted = formatSql(statement);
    System.out.println(formmatted);
    assertEquals(formmatted, formatSql(SQL_PARSER.createStatement(formmatted)));
}
项目:presto    文件:SqlQueryExecution.java   
@Override
public SqlQueryExecution createQueryExecution(QueryId queryId, String query, Session session, Statement statement)
{
    String executionPolicyName = SystemSessionProperties.getExecutionPolicy(session);
    ExecutionPolicy executionPolicy = executionPolicies.get(executionPolicyName);
    checkArgument(executionPolicy != null, "No execution policy %s", executionPolicy);

    return new SqlQueryExecution(
            queryId,
            query,
            session,
            locationFactory.createQueryLocation(queryId),
            statement,
            transactionManager,
            metadata,
            accessControl,
            sqlParser,
            splitManager,
            nodeScheduler,
            planOptimizers,
            remoteTaskFactory,
            locationFactory,
            scheduleSplitBatchSize,
            experimentalSyntaxEnabled,
            executor,
            nodeTaskMap,
            queryExplainer,
            executionPolicy);
}
项目:presto    文件:CoordinatorModule.java   
private static <T extends Statement> void bindDataDefinitionTask(
        Binder binder,
        MapBinder<Class<? extends Statement>, QueryExecutionFactory<?>> executionBinder,
        Class<T> statement,
        Class<? extends DataDefinitionTask<T>> task)
{
    MapBinder<Class<? extends Statement>, DataDefinitionTask<?>> taskBinder = newMapBinder(binder,
            new TypeLiteral<Class<? extends Statement>>() {}, new TypeLiteral<DataDefinitionTask<?>>() {});

    taskBinder.addBinding(statement).to(task).in(Scopes.SINGLETON);
    executionBinder.addBinding(statement).to(DataDefinitionExecutionFactory.class).in(Scopes.SINGLETON);
}
项目:presto    文件:Analyzer.java   
public Analysis analyze(Statement statement)
{
    Analysis analysis = new Analysis();
    StatementAnalyzer analyzer = new StatementAnalyzer(analysis, metadata, sqlParser, accessControl, session, experimentalSyntaxEnabled, queryExplainer);
    RelationType outputDescriptor = analyzer.process(statement, new AnalysisContext());
    analysis.setOutputDescriptor(outputDescriptor);
    return analysis;
}
项目:presto    文件:StatementAnalyzer.java   
private static void validateColumnNames(Statement node, RelationType descriptor)
{
    // verify that all column names are specified and unique
    // TODO: collect errors and return them all at once
    Set<String> names = new HashSet<>();
    for (Field field : descriptor.getVisibleFields()) {
        Optional<String> fieldName = field.getName();
        if (!fieldName.isPresent()) {
            throw new SemanticException(COLUMN_NAME_NOT_SPECIFIED, node, "Column name not specified at position %s", descriptor.indexOf(field) + 1);
        }
        if (!names.add(fieldName.get())) {
            throw new SemanticException(DUPLICATE_COLUMN_NAME, node, "Column name '%s' specified more than once", fieldName.get());
        }
    }
}
项目:presto    文件:StatementAnalyzer.java   
private Query parseView(String view, QualifiedObjectName name, Table node)
{
    try {
        Statement statement = sqlParser.createStatement(view);
        return checkType(statement, Query.class, "parsed view");
    }
    catch (ParsingException e) {
        throw new SemanticException(VIEW_PARSE_ERROR, node, "Failed parsing stored view '%s': %s", name, e.getMessage());
    }
}
项目:presto    文件:QueryExplainer.java   
public QueryExplainer(
        List<PlanOptimizer> planOptimizers,
        Metadata metadata,
        AccessControl accessControl,
        SqlParser sqlParser,
        Map<Class<? extends Statement>, DataDefinitionTask<?>> dataDefinitionTask,
        boolean experimentalSyntaxEnabled)
{
    this.planOptimizers = requireNonNull(planOptimizers, "planOptimizers is null");
    this.metadata = requireNonNull(metadata, "metadata is null");
    this.accessControl = requireNonNull(accessControl, "accessControl is null");
    this.sqlParser = requireNonNull(sqlParser, "sqlParser is null");
    this.experimentalSyntaxEnabled = experimentalSyntaxEnabled;
    this.dataDefinitionTask = ImmutableMap.copyOf(requireNonNull(dataDefinitionTask, "dataDefinitionTask is null"));
}
项目:presto    文件:QueryExplainer.java   
private Plan getLogicalPlan(Session session, Statement statement)
{
    // analyze statement
    Analyzer analyzer = new Analyzer(session, metadata, sqlParser, accessControl, Optional.of(this), experimentalSyntaxEnabled);

    Analysis analysis = analyzer.analyze(statement);
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();

    // plan statement
    LogicalPlanner logicalPlanner = new LogicalPlanner(session, planOptimizers, idAllocator, metadata);
    return logicalPlanner.plan(analysis);
}
项目:presto    文件:QueryExplainer.java   
private SubPlan getDistributedPlan(Session session, Statement statement)
{
    // analyze statement
    Analyzer analyzer = new Analyzer(session, metadata, sqlParser, accessControl, Optional.of(this), experimentalSyntaxEnabled);

    Analysis analysis = analyzer.analyze(statement);
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();

    // plan statement
    LogicalPlanner logicalPlanner = new LogicalPlanner(session, planOptimizers, idAllocator, metadata);
    Plan plan = logicalPlanner.plan(analysis);

    return new PlanFragmenter().createSubPlans(plan);
}
项目:presto    文件:TestAnalyzer.java   
private void analyze(Session clientSession, @Language("SQL") String query)
{
    transaction(transactionManager)
            .singleStatement()
            .readUncommitted()
            .readOnly()
            .execute(clientSession, session -> {
                Analyzer analyzer = createAnalyzer(session, metadata, true);
                Statement statement = SQL_PARSER.createStatement(query);
                analyzer.analyze(statement);
            });
}
项目:presto    文件:TestAnalyzer.java   
private void analyzeWithoutExperimentalSyntax(@Language("SQL") String query)
{
    transaction(transactionManager)
            .singleStatement()
            .readUncommitted()
            .readOnly()
            .execute(CLIENT_SESSION, session -> {
                Analyzer analyzer = createAnalyzer(session, metadata, false);
                Statement statement = SQL_PARSER.createStatement(query);
                analyzer.analyze(statement);
            });
}
项目:presto    文件:TreeAssertions.java   
public static void assertFormattedSql(SqlParser sqlParser, Node expected)
{
    String formatted = formatSql(expected);

    // verify round-trip of formatting already-formatted SQL
    Statement actual = parseFormatted(sqlParser, formatted, expected);
    assertEquals(formatSql(actual), formatted);

    // compare parsed tree with parsed tree of formatted SQL
    if (!actual.equals(expected)) {
        // simplify finding the non-equal part of the tree
        assertListEquals(linearizeTree(actual), linearizeTree(expected));
    }
    assertEquals(actual, expected);
}
项目:presto    文件:TreeAssertions.java   
private static Statement parseFormatted(SqlParser sqlParser, String sql, Node tree)
{
    try {
        return sqlParser.createStatement(sql);
    }
    catch (ParsingException e) {
        throw new AssertionError(format(
                "failed to parse formatted SQL: %s\nerror: %s\ntree: %s",
                sql, e.getMessage(), tree));
    }
}