use of io.prestosql.sql.tree.Property in project hetu-core by openlookeng.
the class TestSqlParser method testAnalyze.
@Test
public void testAnalyze() {
QualifiedName table = QualifiedName.of("foo");
assertStatement("ANALYZE foo", new Analyze(table, ImmutableList.of()));
assertStatement("ANALYZE foo WITH ( \"string\" = 'bar', \"long\" = 42, computed = concat('ban', 'ana'), a = ARRAY[ 'v1', 'v2' ] )", new Analyze(table, ImmutableList.of(new Property(new Identifier("string"), new StringLiteral("bar")), new Property(new Identifier("long"), new LongLiteral("42")), new Property(new Identifier("computed"), new FunctionCall(QualifiedName.of("concat"), ImmutableList.of(new StringLiteral("ban"), new StringLiteral("ana")))), new Property(new Identifier("a"), new ArrayConstructor(ImmutableList.of(new StringLiteral("v1"), new StringLiteral("v2")))))));
assertStatement("EXPLAIN ANALYZE foo", new Explain(new Analyze(table, ImmutableList.of()), false, false, ImmutableList.of()));
assertStatement("EXPLAIN ANALYZE ANALYZE foo", new Explain(new Analyze(table, ImmutableList.of()), true, false, ImmutableList.of()));
}
use of io.prestosql.sql.tree.Property in project hetu-core by openlookeng.
the class AstBuilder method visitCreateCube.
@Override
public Node visitCreateCube(SqlBaseParser.CreateCubeContext context) {
if (context.cubeProperties() == null) {
throw new IllegalArgumentException("Missing properties: AGGREGATIONS, GROUP");
}
QualifiedName cubeName = getQualifiedName(context.cubeName);
QualifiedName sourceTableName = getQualifiedName(context.tableName);
List<Identifier> groupingSet = ImmutableList.of();
List<FunctionCall> aggregations = ImmutableList.of();
List<Property> properties = new ArrayList<>();
Optional<Expression> optionalExpression = visitIfPresent(context.expression(), Expression.class);
boolean cubeGroupProvided = false;
boolean aggregationsProvided = false;
boolean sourceFilterProvided = false;
Optional<Expression> sourceFilterPredicate = Optional.empty();
for (SqlBaseParser.CubePropertyContext propertyContext : context.cubeProperties().cubeProperty()) {
if (propertyContext.cubeGroup() != null) {
if (cubeGroupProvided) {
throw new IllegalArgumentException("Duplicate property: GROUP");
}
groupingSet = visit(propertyContext.cubeGroup().identifier(), Identifier.class);
cubeGroupProvided = true;
} else if (propertyContext.aggregations() != null) {
if (aggregationsProvided) {
throw new IllegalArgumentException("Duplicate property: AGGREGATIONS");
}
aggregations = visit(propertyContext.aggregations().expression(), FunctionCall.class);
aggregationsProvided = true;
} else if (propertyContext.sourceFilter() != null) {
if (sourceFilterProvided) {
throw new IllegalArgumentException("Duplicate Property: FILTER");
}
sourceFilterPredicate = visitIfPresent(propertyContext.sourceFilter().expression(), Expression.class);
sourceFilterProvided = true;
} else if (propertyContext.property() != null) {
properties.add((Property) visitProperty(propertyContext.property()));
}
}
if (!cubeGroupProvided) {
throw new IllegalArgumentException("Missing property: GROUP");
}
if (!aggregationsProvided) {
throw new IllegalArgumentException("Missing property: AGGREGATIONS");
}
List<Identifier> decomposedGroupingSet = new ArrayList<>();
groupingSet.forEach(groupItem -> {
decomposedGroupingSet.add(new Identifier(groupItem.getLocation().get(), groupItem.getValue().toLowerCase(Locale.ENGLISH), groupItem.isDelimited()));
});
Set<FunctionCall> decomposedAggregations = new LinkedHashSet<>();
aggregations.forEach(aggItem -> {
List<Expression> listArguments = aggItem.getArguments();
List<Expression> newArguments = new ArrayList<>();
for (Expression argument : listArguments) {
if (argument instanceof Identifier) {
newArguments.add(new Identifier(argument.getLocation().get(), ((Identifier) argument).getValue().toLowerCase(Locale.ENGLISH), ((Identifier) argument).isDelimited()));
} else {
newArguments.add(argument);
}
}
if (!"avg".equals(aggItem.getName().toString())) {
decomposedAggregations.add(new FunctionCall(aggItem.getLocation(), aggItem.getName(), aggItem.getWindow(), aggItem.getFilter(), aggItem.getOrderBy(), aggItem.isDistinct(), newArguments));
} else {
decomposedAggregations.add(aggItem);
decomposedAggregations.add(new FunctionCall(aggItem.getLocation(), QualifiedName.of("sum"), aggItem.getWindow(), aggItem.getFilter(), aggItem.getOrderBy(), aggItem.isDistinct(), newArguments));
decomposedAggregations.add(new FunctionCall(aggItem.getLocation(), QualifiedName.of("count"), aggItem.getWindow(), aggItem.getFilter(), aggItem.getOrderBy(), aggItem.isDistinct(), newArguments));
}
});
return new CreateCube(getLocation(context), cubeName, sourceTableName, decomposedGroupingSet, decomposedAggregations, context.EXISTS() != null, properties, optionalExpression, sourceFilterPredicate.orElse(null));
}
Aggregations