Java 类com.facebook.presto.sql.tree.Cube 实例源码
项目:presto-query-formatter
文件:ExpressionFormatter.java
static String formatGroupBy(List<GroupingElement> groupingElements, Optional<List<Expression>> parameters, int indent)
{
ImmutableList.Builder<String> resultStrings = ImmutableList.builder();
for (GroupingElement groupingElement : groupingElements) {
String result = "";
if (groupingElement instanceof SimpleGroupBy) {
Set<Expression> columns = ImmutableSet.copyOf(((SimpleGroupBy) groupingElement).getColumnExpressions());
if (columns.size() == 1) {
result = formatExpression(getOnlyElement(columns), parameters, indent);
}
else {
result = formatGroupingSet(columns, parameters, indent);
}
}
else if (groupingElement instanceof GroupingSets) {
result = format("GROUPING SETS (%s)", Joiner.on(", ").join(
((GroupingSets) groupingElement).getSets().stream()
.map(ExpressionFormatter::formatGroupingSet)
.iterator()));
}
else if (groupingElement instanceof Cube) {
result = format("CUBE %s", formatGroupingSet(((Cube) groupingElement).getColumns()));
}
else if (groupingElement instanceof Rollup) {
result = format("ROLLUP %s", formatGroupingSet(((Rollup) groupingElement).getColumns()));
}
resultStrings.add(result);
}
return Joiner.on(", ").join(resultStrings.build());
}
项目:presto
文件:AstBuilder.java
@Override
public Node visitCube(SqlBaseParser.CubeContext context)
{
return new Cube(getLocation(context), context.qualifiedName().stream()
.map(AstBuilder::getQualifiedName)
.collect(toList()));
}
项目:presto
文件:ExpressionFormatter.java
static String formatGroupBy(List<GroupingElement> groupingElements)
{
ImmutableList.Builder<String> resultStrings = ImmutableList.builder();
for (GroupingElement groupingElement : groupingElements) {
String result = "";
if (groupingElement instanceof SimpleGroupBy) {
Set<Expression> columns = ImmutableSet.copyOf(((SimpleGroupBy) groupingElement).getColumnExpressions());
if (columns.size() == 1) {
result = formatExpression(getOnlyElement(columns));
}
else {
result = formatGroupingSet(columns);
}
}
else if (groupingElement instanceof GroupingSets) {
result = format("GROUPING SETS (%s)", Joiner.on(", ").join(
groupingElement.enumerateGroupingSets().stream()
.map(ExpressionFormatter::formatGroupingSet)
.iterator()));
}
else if (groupingElement instanceof Cube) {
result = format("CUBE %s", formatGroupingSet(((Cube) groupingElement).getColumns()));
}
else if (groupingElement instanceof Rollup) {
result = format("ROLLUP %s", formatGroupingSet(((Rollup) groupingElement).getColumns()));
}
resultStrings.add(result);
}
return Joiner.on(", ").join(resultStrings.build());
}
项目:EchoQuery
文件:ExpressionFormatter.java
static String formatGroupBy(List<GroupingElement> groupingElements)
{
ImmutableList.Builder<String> resultStrings = ImmutableList.builder();
for (GroupingElement groupingElement : groupingElements) {
String result = "";
if (groupingElement instanceof SimpleGroupBy) {
Set<Expression> columns = ImmutableSet.copyOf(((SimpleGroupBy) groupingElement).getColumnExpressions());
if (columns.size() == 1) {
result = formatExpression(getOnlyElement(columns));
}
else {
result = formatGroupingSet(columns);
}
}
else if (groupingElement instanceof GroupingSets) {
result = format("GROUPING SETS (%s)", Joiner.on(", ").join(
groupingElement.enumerateGroupingSets().stream()
.map(ExpressionFormatter::formatGroupingSet)
.iterator()));
}
else if (groupingElement instanceof Cube) {
result = format("CUBE %s", formatGroupingSet(((Cube) groupingElement).getColumns()));
}
else if (groupingElement instanceof Rollup) {
result = format("ROLLUP %s", formatGroupingSet(((Rollup) groupingElement).getColumns()));
}
resultStrings.add(result);
}
return Joiner.on(", ").join(resultStrings.build());
}