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

项目:presto-query-formatter    文件:StatementFormatter.java   
@Override
protected Void visitShowPartitions(ShowPartitions node, Integer indent)
{
    builder.append("SHOW PARTITIONS FROM ")
            .append(node.getTable());

    if (node.getWhere().isPresent()) {
        builder.append(" WHERE ")
                .append(formatExpression(node.getWhere().get(), parameters, indent));
    }

    if (!node.getOrderBy().isEmpty()) {
        builder.append(" ORDER BY ")
                .append(formatSortItems(node.getOrderBy(), parameters, indent));
    }

    if (node.getLimit().isPresent()) {
        builder.append(" LIMIT ")
                .append(node.getLimit().get());
    }

    return null;
}
项目:presto    文件:SqlFormatter.java   
@Override
protected Void visitShowPartitions(ShowPartitions node, Integer context)
{
    builder.append("SHOW PARTITIONS FROM ")
            .append(node.getTable());

    if (node.getWhere().isPresent()) {
        builder.append(" WHERE ")
                .append(formatExpression(node.getWhere().get()));
    }

    if (!node.getOrderBy().isEmpty()) {
        builder.append(" ORDER BY ")
                .append(formatSortItems(node.getOrderBy()));
    }

    if (node.getLimit().isPresent()) {
        builder.append(" LIMIT ")
                .append(node.getLimit().get());
    }

    return null;
}
项目:EchoQuery    文件:SqlFormatter.java   
@Override
protected Void visitShowPartitions(ShowPartitions node, Integer context)
{
    builder.append("SHOW PARTITIONS FROM ")
            .append(node.getTable());

    if (node.getWhere().isPresent()) {
        builder.append(" WHERE ")
                .append(formatExpression(node.getWhere().get()));
    }

    if (!node.getOrderBy().isEmpty()) {
        builder.append(" ORDER BY ")
                .append(formatSortItems(node.getOrderBy()));
    }

    if (node.getLimit().isPresent()) {
        builder.append(" LIMIT ")
                .append(node.getLimit().get());
    }

    return null;
}
项目:presto    文件:AstBuilder.java   
@Override
public Node visitShowPartitions(SqlBaseParser.ShowPartitionsContext context)
{
    return new ShowPartitions(
            getLocation(context),
            getQualifiedName(context.qualifiedName()),
            visitIfPresent(context.booleanExpression(), Expression.class),
            visit(context.sortItem(), SortItem.class),
            getTextIfPresent(context.limit));
}
项目:presto    文件:TestSqlParser.java   
@Test
public void testShowPartitions()
{
    assertStatement("SHOW PARTITIONS FROM t", new ShowPartitions(QualifiedName.of("t"), Optional.empty(), ImmutableList.of(), Optional.empty()));

    assertStatement("SHOW PARTITIONS FROM t WHERE x = 1",
            new ShowPartitions(
                    QualifiedName.of("t"),
                    Optional.of(new ComparisonExpression(ComparisonExpression.Type.EQUAL, new QualifiedNameReference(QualifiedName.of("x")), new LongLiteral("1"))),
                    ImmutableList.of(),
                    Optional.empty()));

    assertStatement("SHOW PARTITIONS FROM t WHERE x = 1 ORDER BY y",
            new ShowPartitions(
                    QualifiedName.of("t"),
                    Optional.of(new ComparisonExpression(ComparisonExpression.Type.EQUAL, new QualifiedNameReference(QualifiedName.of("x")), new LongLiteral("1"))),
                    ImmutableList.of(new SortItem(new QualifiedNameReference(QualifiedName.of("y")), SortItem.Ordering.ASCENDING, SortItem.NullOrdering.UNDEFINED)),
                    Optional.empty()));

    assertStatement("SHOW PARTITIONS FROM t WHERE x = 1 ORDER BY y LIMIT 10",
            new ShowPartitions(
                    QualifiedName.of("t"),
                    Optional.of(new ComparisonExpression(ComparisonExpression.Type.EQUAL, new QualifiedNameReference(QualifiedName.of("x")), new LongLiteral("1"))),
                    ImmutableList.of(new SortItem(new QualifiedNameReference(QualifiedName.of("y")), SortItem.Ordering.ASCENDING, SortItem.NullOrdering.UNDEFINED)),
                    Optional.of("10")));

    assertStatement("SHOW PARTITIONS FROM t WHERE x = 1 ORDER BY y LIMIT ALL",
            new ShowPartitions(
                    QualifiedName.of("t"),
                    Optional.of(new ComparisonExpression(ComparisonExpression.Type.EQUAL, new QualifiedNameReference(QualifiedName.of("x")), new LongLiteral("1"))),
                    ImmutableList.of(new SortItem(new QualifiedNameReference(QualifiedName.of("y")), SortItem.Ordering.ASCENDING, SortItem.NullOrdering.UNDEFINED)),
                    Optional.of("ALL")));
}