use of com.qlangtech.tis.sql.parser.tuple.creator.impl.FunctionDataTupleCreator in project tis by qlangtech.
the class TestOrderCustomersSqlParse method testParse.
public void testParse() throws Exception {
final String order_customers = "order_customers";
TableTupleCreator task = parseSqlTaskNode(order_customers);
ColRef colRef = task.getColsRefs();
Assert.assertNotNull(colRef);
ColRef.ListMap /* colName */
colRefMap = colRef.getColRefMap();
// {name:has_fetch=FunctionDataTuple,
// name:customer_ids=ref:a1,entity:innertab_a1,
// name:order_id=ref:a1,entity:innertab_a1}
IDataTupleCreator tupleCreator = null;
Assert.assertEquals(3, colRefMap.size());
ColName hasFetch = new ColName("has_fetch");
tupleCreator = colRefMap.get(hasFetch);
Assert.assertTrue(tupleCreator instanceof FunctionDataTupleCreator);
FunctionDataTupleCreator funcDataTuple = (FunctionDataTupleCreator) tupleCreator;
Assert.assertEquals(1, funcDataTuple.getParams().size());
Optional<ColName> funcParam = funcDataTuple.getParams().keySet().stream().findFirst();
Assert.assertTrue(funcParam.isPresent());
ColName hasFetchParam = funcParam.get();
Assert.assertEquals("has_fetch", hasFetchParam.getAliasName());
Assert.assertEquals("has_fetch", hasFetchParam.getName());
Optional<IDataTupleCreator> hasFetchRef = funcDataTuple.getParams().values().stream().findFirst();
Assert.assertTrue(hasFetchRef.isPresent());
IDataTupleCreator asTableTuple = hasFetchRef.get();
Assert.assertTrue(asTableTuple instanceof TableTupleCreator);
TableTupleCreator a2Tuple = (TableTupleCreator) asTableTuple;
// EntitiyRef entityRef = a2Tuple.getEntityRef();
// Assert.assertNotNull(entityRef);
Assert.assertEquals("tis.innertab_a2", a2Tuple.getEntityName().toString());
// task = entityRef.getTaskNode();
// Assert.assertNotNull(task);
ColName hasFetchOfinnertab_a2 = new ColName("has_fetch");
tupleCreator = task.getColsRefs().getColRefMap().get(hasFetchOfinnertab_a2);
Assert.assertTrue(tupleCreator instanceof FunctionDataTupleCreator);
funcDataTuple = (FunctionDataTupleCreator) tupleCreator;
Assert.assertEquals(1, funcDataTuple.getParams().size());
ColName customerIds = new ColName("customer_ids");
tupleCreator = colRefMap.get(customerIds);
assertA1Tuple(tupleCreator);
ColName orderid = new ColName("order_id");
tupleCreator = colRefMap.get(orderid);
assertA1Tuple(tupleCreator);
Assert.assertEquals(2, colRef.getBaseRefKeys().size());
Assert.assertTrue(colRef.getTupleCreator("a1") != null);
Assert.assertTrue(colRef.getTupleCreator("a2") != null);
Assert.assertTrue(colRef.getTupleCreator("a1") instanceof TableTupleCreator);
Assert.assertTrue(colRef.getTupleCreator("a2") instanceof TableTupleCreator);
}
use of com.qlangtech.tis.sql.parser.tuple.creator.impl.FunctionDataTupleCreator 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.tuple.creator.impl.FunctionDataTupleCreator 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);
}
});
}
});
}
use of com.qlangtech.tis.sql.parser.tuple.creator.impl.FunctionDataTupleCreator in project tis by qlangtech.
the class StreamComponentCodeGeneratorFlink method generateCreateGroupResultScript.
private void generateCreateGroupResultScript(FuncFormat rr, final PropGetter propGetter, TisGroupBy groups) {
if (propGetter.isLastFunctInChain()) {
rr.startLine("var result:Any = null");
}
final AtomicBoolean hasBreak = new AtomicBoolean();
rr.startLine(new IBlockToString() {
public String toString() {
return hasBreak.get() ? "breakable {" : StringUtils.EMPTY;
}
});
rr.methodBody("for ((k:GroupKey, v:GroupValues) <- " + groups.getGroupAggrgationName() + ")", (r) -> {
final PropGetter pgetter = propGetter;
if (propGetter.isLastFunctInChain()) {
rr.startLine("result = ");
hasBreak.set(true);
propGetter.getGroovyScript(rr, true);
rr.startLine("break");
rr.returnLine();
} else {
PropGetter prev = propGetter.getPrev();
while (prev != null) {
if (prev.getTupleCreator() instanceof FunctionDataTupleCreator) {
break;
}
prev = prev.getPrev();
}
boolean shallCallableProcess = (prev != null && prev.shallCallableProcess());
if (shallCallableProcess) {
rr.startLine("putMediaResult(\"" + pgetter.getOutputColName().getAliasName() + "\", //");
} else {
rr.startLine("v.putMediaData( // \n");
rr.startLine("\"").append(propGetter.getOutputColName().getAliasName()).append("\" // \n");
rr.startLine(", //\n");
}
// );
propGetter.getGroovyScript(rr, true);
if (shallCallableProcess) {
rr.startLine(") // end putMediaResult");
hasBreak.set(true);
rr.startLine("break");
} else {
rr.startLine(") // end putMediaData\n");
}
}
});
rr.startLine(new IBlockToString() {
public String toString() {
return hasBreak.get() ? "} //end breakable" : StringUtils.EMPTY;
}
});
if (propGetter.isLastFunctInChain()) {
rr.startLine(" result //return");
}
rr.returnLine();
}
use of com.qlangtech.tis.sql.parser.tuple.creator.impl.FunctionDataTupleCreator in project tis by qlangtech.
the class StreamComponentCodeGenerator method generateCreateGroupResultScript.
private void generateCreateGroupResultScript(FuncFormat rr, final PropGetter propGetter, TisGroupBy groups) {
if (propGetter.isLastFunctInChain()) {
rr.startLine("var result:Any = null");
}
final AtomicBoolean hasBreak = new AtomicBoolean();
rr.startLine(new IBlockToString() {
public String toString() {
return hasBreak.get() ? "breakable {" : StringUtils.EMPTY;
}
});
rr.methodBody("for ((k:GroupKey, v:GroupValues) <- " + groups.getGroupAggrgationName() + ")", (r) -> {
final PropGetter pgetter = propGetter;
if (propGetter.isLastFunctInChain()) {
rr.startLine("result = ");
hasBreak.set(true);
propGetter.getGroovyScript(rr, true);
rr.startLine("break");
rr.returnLine();
} else {
PropGetter prev = propGetter.getPrev();
while (prev != null) {
if (prev.getTupleCreator() instanceof FunctionDataTupleCreator) {
break;
}
prev = prev.getPrev();
}
boolean shallCallableProcess = (prev != null && prev.shallCallableProcess());
if (shallCallableProcess) {
rr.startLine("putMediaResult(\"" + pgetter.getOutputColName().getAliasName() + "\", //");
} else {
rr.startLine("v.putMediaData( // \n");
rr.startLine("\"").append(propGetter.getOutputColName().getAliasName()).append("\" // \n");
rr.startLine(", //\n");
}
// );
propGetter.getGroovyScript(rr, true);
if (shallCallableProcess) {
rr.startLine(") // end putMediaResult");
hasBreak.set(true);
rr.startLine("break");
} else {
rr.startLine(") // end putMediaData\n");
}
}
});
rr.startLine(new IBlockToString() {
public String toString() {
return hasBreak.get() ? "} //end breakable" : StringUtils.EMPTY;
}
});
if (propGetter.isLastFunctInChain()) {
rr.startLine(" result //return");
}
rr.returnLine();
}
Aggregations