當前位置: 首頁>>代碼示例>>Java>>正文


Java With類代碼示例

本文整理匯總了Java中com.facebook.presto.sql.tree.With的典型用法代碼示例。如果您正苦於以下問題:Java With類的具體用法?Java With怎麽用?Java With使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


With類屬於com.facebook.presto.sql.tree包,在下文中一共展示了With類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testWith

import com.facebook.presto.sql.tree.With; //導入依賴的package包/類
@Test
public void testWith()
        throws Exception
{
    assertStatement("WITH a (t, u) AS (SELECT * FROM x), b AS (SELECT * FROM y) TABLE z",
            new Query(Optional.of(new With(false, ImmutableList.of(
                    new WithQuery("a", simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("x"))), ImmutableList.of("t", "u")),
                    new WithQuery("b", simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("y"))), null)))),
                    new Table(QualifiedName.of("z")),
                    ImmutableList.of(),
                    Optional.<String>empty(),
                    Optional.<Approximate>empty()));

    assertStatement("WITH RECURSIVE a AS (SELECT * FROM x) TABLE y",
            new Query(Optional.of(new With(true, ImmutableList.of(
                    new WithQuery("a", simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("x"))), null)))),
                    new Table(QualifiedName.of("y")),
                    ImmutableList.of(),
                    Optional.<String>empty(),
                    Optional.<Approximate>empty()));
}
 
開發者ID:y-lan,項目名稱:presto,代碼行數:22,代碼來源:TestSqlParser.java

示例2: visitQuery

import com.facebook.presto.sql.tree.With; //導入依賴的package包/類
@Override
protected Void visitQuery(Query node, Integer indent)
{
    if (node.getWith().isPresent()) {
        With with = node.getWith().get();
        append(indent, "WITH");
        if (with.isRecursive()) {
            builder.append(" RECURSIVE");
        }
        builder.append("\n  ");
        Iterator<WithQuery> queries = with.getQueries().iterator();
        while (queries.hasNext()) {
            WithQuery query = queries.next();
            append(indent, query.getName());
            query.getColumnNames().ifPresent(columnNames -> appendAliasColumns(builder, columnNames));
            builder.append(" AS ");
            process(new TableSubquery(query.getQuery()), indent);
            builder.append('\n');
            if (queries.hasNext()) {
                builder.append(", ");
            }
        }
    }

    processRelation(node.getQueryBody(), indent);

    if (node.getOrderBy().isPresent()) {
        append(indent, "ORDER BY " + formatSortItems(node.getOrderBy().get().getSortItems(), parameters, indent))
                .append('\n');
    }

    if (node.getLimit().isPresent()) {
        append(indent, "LIMIT " + node.getLimit().get())
                .append('\n');
    }

    return null;
}
 
開發者ID:prestodb-rocks,項目名稱:presto-query-formatter,代碼行數:39,代碼來源:StatementFormatter.java

示例3: analyzeWith

import com.facebook.presto.sql.tree.With; //導入依賴的package包/類
private void analyzeWith(Query node, AnalysisContext context)
{
    // analyze WITH clause
    if (!node.getWith().isPresent()) {
        return;
    }

    With with = node.getWith().get();
    if (with.isRecursive()) {
        throw new SemanticException(NOT_SUPPORTED, with, "Recursive WITH queries are not supported");
    }

    for (WithQuery withQuery : with.getQueries()) {
        if (withQuery.getColumnNames() != null && !withQuery.getColumnNames().isEmpty()) {
            throw new SemanticException(NOT_SUPPORTED, withQuery, "Column alias not supported in WITH queries");
        }

        Query query = withQuery.getQuery();
        process(query, context);

        String name = withQuery.getName();
        if (context.isNamedQueryDeclared(name)) {
            throw new SemanticException(DUPLICATE_RELATION, withQuery, "WITH query name '%s' specified more than once", name);
        }

        context.addNamedQuery(name, query);
    }
}
 
開發者ID:y-lan,項目名稱:presto,代碼行數:29,代碼來源:StatementAnalyzer.java

示例4: visitQuery

import com.facebook.presto.sql.tree.With; //導入依賴的package包/類
@Override
public Node visitQuery(SqlBaseParser.QueryContext context)
{
    Query body = (Query) visit(context.queryNoWith());

    return new Query(
            getLocation(context),
            visitIfPresent(context.with(), With.class),
            body.getQueryBody(),
            body.getOrderBy(),
            body.getLimit(),
            body.getApproximate());
}
 
開發者ID:y-lan,項目名稱:presto,代碼行數:14,代碼來源:AstBuilder.java

示例5: visitQueryNoWith

import com.facebook.presto.sql.tree.With; //導入依賴的package包/類
@Override
public Node visitQueryNoWith(SqlBaseParser.QueryNoWithContext context)
{
    QueryBody term = (QueryBody) visit(context.queryTerm());

    if (term instanceof QuerySpecification) {
        // When we have a simple query specification
        // followed by order by limit, fold the order by and limit
        // clauses into the query specification (analyzer/planner
        // expects this structure to resolve references with respect
        // to columns defined in the query specification)
        QuerySpecification query = (QuerySpecification) term;

        return new Query(
                getLocation(context),
                Optional.<With>empty(),
                new QuerySpecification(
                        getLocation(context),
                        query.getSelect(),
                        query.getFrom(),
                        query.getWhere(),
                        query.getGroupBy(),
                        query.getHaving(),
                        visit(context.sortItem(), SortItem.class),
                        getTextIfPresent(context.limit)),
                ImmutableList.of(),
                Optional.<String>empty(),
                getTextIfPresent(context.confidence)
                        .map(confidence -> new Approximate(getLocation(context), confidence)));
    }

    return new Query(
            getLocation(context),
            Optional.<With>empty(),
            term,
            visit(context.sortItem(), SortItem.class),
            getTextIfPresent(context.limit),
            getTextIfPresent(context.confidence)
                    .map(confidence -> new Approximate(getLocation(context), confidence)));
}
 
開發者ID:y-lan,項目名稱:presto,代碼行數:41,代碼來源:AstBuilder.java

示例6: visitQuery

import com.facebook.presto.sql.tree.With; //導入依賴的package包/類
@Override
protected Void visitQuery(Query node, Integer indent)
{
    if (node.getWith().isPresent()) {
        With with = node.getWith().get();
        append(indent, "WITH");
        if (with.isRecursive()) {
            builder.append(" RECURSIVE");
        }
        builder.append("\n  ");
        Iterator<WithQuery> queries = with.getQueries().iterator();
        while (queries.hasNext()) {
            WithQuery query = queries.next();
            append(indent, query.getName());
            appendAliasColumns(builder, query.getColumnNames());
            builder.append(" AS ");
            process(new TableSubquery(query.getQuery()), indent);
            builder.append('\n');
            if (queries.hasNext()) {
                builder.append(", ");
            }
        }
    }

    processRelation(node.getQueryBody(), indent);

    if (!node.getOrderBy().isEmpty()) {
        append(indent, "ORDER BY " + formatSortItems(node.getOrderBy()))
                .append('\n');
    }

    if (node.getLimit().isPresent()) {
        append(indent, "LIMIT " + node.getLimit().get())
                .append('\n');
    }

    if (node.getApproximate().isPresent()) {
        String confidence = node.getApproximate().get().getConfidence();
        append(indent, "APPROXIMATE AT " + confidence + " CONFIDENCE")
                .append('\n');
    }

    return null;
}
 
開發者ID:y-lan,項目名稱:presto,代碼行數:45,代碼來源:SqlFormatter.java

示例7: visitWith

import com.facebook.presto.sql.tree.With; //導入依賴的package包/類
@Override
public Node visitWith(SqlBaseParser.WithContext context)
{
    return new With(getLocation(context), context.RECURSIVE() != null, visit(context.namedQuery(), WithQuery.class));
}
 
開發者ID:y-lan,項目名稱:presto,代碼行數:6,代碼來源:AstBuilder.java


注:本文中的com.facebook.presto.sql.tree.With類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。