use of com.qlangtech.tis.sql.parser.TisGroupBy in project tis by qlangtech.
the class StreamTransformVisitor method visitGroupBy.
@Override
protected NodeProcessResult<?> visitGroupBy(GroupBy node, StackableAstVisitorContext<Integer> context) {
// System.out.println(
// "GROUP BY " + (node.isDistinct() ? " DISTINCT " : "") +
// formatGroupBy(node.getGroupingElements()));
TisGroupBy groupBy = new TisGroupBy();
for (GroupingElement groupingElement : node.getGroupingElements()) {
if (groupingElement instanceof SimpleGroupBy) {
Set<Expression> columns = ImmutableSet.copyOf(((SimpleGroupBy) groupingElement).getColumnExpressions());
for (Expression g : columns) {
if (g instanceof DereferenceExpression) {
DereferenceExpression group = (DereferenceExpression) g;
if (!(group.getBase() instanceof Identifier)) {
faild(group.getBase());
}
groupBy.add(new TisGroup(((Identifier) group.getBase()).getValue(), group.getField().getValue()));
} else {
faild("groupby cols shall col must has tab reference", g);
}
}
// this.groupBy = Optional.of(groupBy);
} else {
faild(node);
}
// 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);
}
if (groupBy.getGroups().size() > 0) {
this.colsRef.getColRefMap().entrySet().forEach((r) -> {
if (r.getValue() instanceof FunctionDataTupleCreator) {
((FunctionDataTupleCreator) r.getValue()).setGroupBy(groupBy);
}
// System.out.println(r.getKey() + ":" + r.getValue().hashCode());
});
}
return null;
}
use of com.qlangtech.tis.sql.parser.TisGroupBy in project tis by qlangtech.
the class TableReferenceVisitor method setFuncGroupByTuple.
private void setFuncGroupByTuple(IDataTupleCreator tupleCreator, final String tabRefName) {
Stream<FunctionDataTupleCreator> funcs = this.colRef.getColRefMap().values().stream().filter((r) -> r instanceof FunctionDataTupleCreator).map((r) -> (FunctionDataTupleCreator) r);
funcs.forEach((f) -> {
Optional<TisGroupBy> g = f.getGroupBy();
if (g.isPresent()) {
g.get().getGroups().forEach((group) -> {
TableTupleCreator tabTuple = null;
if (!group.isTupleSetted() && StringUtils.equals(group.getTabRef(), tabRefName)) {
if (!(tupleCreator instanceof TableTupleCreator)) {
throw new IllegalStateException("tupleCreator type shall be TableTupleCterator");
}
tabTuple = (TableTupleCreator) tupleCreator;
if (!tabRefName.equals(tabTuple.getMediaTabRef())) {
throw new IllegalStateException("tabRefName:" + tabRefName + ",tabTuple.getMediaTabRef:" + tabTuple.getMediaTabRef() + " shall be equal");
}
group.setTabTuple(tabTuple);
}
});
}
});
}
Aggregations