use of com.qlangtech.tis.sql.parser.tuple.creator.impl.TableTupleCreator in project tis by qlangtech.
the class TestTmpPaySqlParse method testParse.
public void testParse() throws Exception {
String tmpPay = "tmp_pay";
final TableTupleCreator tmpPayTask = this.parseSqlTaskNode(tmpPay);
final ColRef colRef = tmpPayTask.getColsRefs();
Assert.assertNotNull(colRef);
final ColRef.ListMap /* colName */
colRefMap = colRef.getColRefMap();
Assert.assertEquals(5, colRefMap.size());
// Map<String, IDataTupleCreator> /* ref */
// baseRefMap = colRef.baseRefMap;
Assert.assertEquals(1, colRef.getBaseRefSize());
// baseRefMap.get("aa");
IDataTupleCreator aaTupleCreator = colRef.getTupleCreator("aa");
Assert.assertNotNull(aaTupleCreator);
Assert.assertTrue(aaTupleCreator instanceof TableTupleCreator);
TableTupleCreator aaTabTupleCreator = (TableTupleCreator) aaTupleCreator;
// EntitiyRef entityRef = aaTabTupleCreator.getEntityRef();
// Assert.assertNotNull(entityRef);
Assert.assertEquals("innertab_aa", aaTabTupleCreator.getEntityName());
// Assert.assertNotNull(entityRef.getTaskNode());
// SqlTaskNode taskNode = entityRef.getTaskNode();
Assert.assertEquals(NodeType.JOINER_SQL, aaTabTupleCreator.getNodetype());
// Assert.assertEquals("innertab_aa", taskNode.getExportName());
Assert.assertEquals("aa", aaTabTupleCreator.getMediaTabRef());
final ColRef aaTabTupleColRef = aaTabTupleCreator.getColsRefs();
// Set<Map.Entry<String, SqlTaskNode>> required = taskNode.getRequired();
// .baseRefMap.size());
Assert.assertEquals(1, aaTabTupleColRef.getBaseRefSize());
// ===============================================================
ColName pay_customer_ids = new ColName("pay_customer_ids");
IDataTupleCreator pay_customer_idsTuple = aaTabTupleColRef.getColRefMap().get(pay_customer_ids);
Assert.assertTrue(pay_customer_idsTuple instanceof FunctionDataTupleCreator);
FunctionDataTupleCreator pay_customer_idsTupleFunc = (FunctionDataTupleCreator) pay_customer_idsTuple;
Optional<TisGroupBy> pay_customer_idsTupleFuncGroup = pay_customer_idsTupleFunc.getGroupBy();
Assert.assertTrue(pay_customer_idsTupleFuncGroup.isPresent());
Assert.assertEquals(2, pay_customer_idsTupleFuncGroup.get().getGroups().size());
TisGroup group = pay_customer_idsTupleFuncGroup.get().getGroups().get(0);
Assert.assertEquals("totalpay_id", group.getColname());
Assert.assertNotNull(group.getTabTuple());
group = pay_customer_idsTupleFuncGroup.get().getGroups().get(1);
Assert.assertEquals("kindpay_id", group.getColname());
Assert.assertNotNull(group.getTabTuple());
// ===============================================================
Optional<Map.Entry<String, IDataTupleCreator>> dependency = aaTabTupleColRef.getBaseRefEntities().stream().findFirst();
Assert.assertTrue(dependency.isPresent());
Assert.assertEquals("p", dependency.get().getKey());
Assert.assertTrue(dependency.get().getValue() instanceof TableTupleCreator);
TableTupleCreator payTabTuple = (TableTupleCreator) dependency.get().getValue();
Assert.assertEquals(NodeType.DUMP, payTabTuple.getNodetype());
// ==================================================================================
ColName kindpay = new ColName("kindpay");
IDataTupleCreator kindPayCreator = colRefMap.get(kindpay);
Assert.assertNotNull(kindPayCreator);
Assert.assertTrue(kindPayCreator instanceof FunctionDataTupleCreator);
FunctionDataTupleCreator kindPayFuncCreator = (FunctionDataTupleCreator) kindPayCreator;
Map<ColName, IDataTupleCreator> kindpayFuncParams = kindPayFuncCreator.getParams();
Assert.assertEquals(1, kindpayFuncParams.size());
ColName innerAkindpay = new ColName("aakindpay");
IDataTupleCreator innerATuple = kindpayFuncParams.get(innerAkindpay);
Assert.assertNotNull(innerATuple);
Assert.assertTrue(innerATuple instanceof TableTupleCreator);
TableTupleCreator innerATableTuple = (TableTupleCreator) innerATuple;
Assert.assertEquals("aa", innerATableTuple.getMediaTabRef());
innerATuple = innerATableTuple.getColsRefs().getColRefMap().get(innerAkindpay);
Assert.assertNotNull(innerATuple);
Assert.assertTrue(innerATuple instanceof FunctionDataTupleCreator);
Assert.assertEquals(6, ((FunctionDataTupleCreator) innerATuple).getParams().size());
// ===================================================================================
ColName payCustomerIds = new ColName("pay_customer_ids");
IDataTupleCreator payCustomerIdsTuple = colRef.getColRefMap().get(payCustomerIds);
Assert.assertTrue(payCustomerIdsTuple instanceof FunctionDataTupleCreator);
FunctionDataTupleCreator pay_customer_idsFuncTuple = (FunctionDataTupleCreator) payCustomerIdsTuple;
Optional<TisGroupBy> pay_customer_idsFuncTupleGroupBy = pay_customer_idsFuncTuple.getGroupBy();
Assert.assertTrue(pay_customer_idsFuncTupleGroupBy.isPresent());
Assert.assertEquals(1, pay_customer_idsFuncTupleGroupBy.get().getGroups().size());
pay_customer_idsFuncTupleGroupBy.get().getGroups().forEach((r) -> {
Assert.assertNotNull("TabRef:" + r.getTabRef(), r.getTabTuple());
});
}
use of com.qlangtech.tis.sql.parser.tuple.creator.impl.TableTupleCreator in project tis by qlangtech.
the class TestValChainListTupleMap method generateCode.
public void generateCode() throws Exception {
TableTupleCreator totalpaySummaryTuple = this.parseSqlTaskNode(totalpay_summary);
TaskNodeTraversesCreatorVisitor visitor = new TaskNodeTraversesCreatorVisitor(TestERRules.getTotalpayErRules());
totalpaySummaryTuple.accept(visitor);
Map<IEntityNameGetter, List<IValChain>> tabTriggers = visitor.getTabTriggerLinker();
for (Map.Entry<IEntityNameGetter, List<IValChain>> e : tabTriggers.entrySet()) {
System.out.println(e.getKey().getEntityName());
if ("payinfo".equals(e.getKey().getEntityName().getTabName()) || "card".equals(e.getKey().getEntityName().getTabName())) {
System.out.println("====================================================");
System.out.println(e.getKey().getEntityName().getTabName());
for (IValChain chain : e.getValue()) {
System.out.println(Joiner.on("->").join(chain.mapChainValve((r) -> {
return r.getIdentityName();
}).iterator()));
}
}
}
}
use of com.qlangtech.tis.sql.parser.tuple.creator.impl.TableTupleCreator in project tis by qlangtech.
the class SqlTaskNode method parse.
public TableTupleCreator parse(boolean parseAllRefTab) {
if (tupleCterator != null) {
return this.tupleCterator;
}
this.tupleCterator = new TableTupleCreator(this.exportName.getTabName(), nodetype);
tupleCterator.setRealEntityName(this.exportName);
try {
Query query = parseQuery(this.getContent());
StreamTransformVisitor v = new StreamTransformVisitor(this.dumpNodesContext);
query.accept(v, new StackableAstVisitorContext<>(1));
ColRef colsRefs = v.getColsRef();
tupleCterator.setColsRefs(colsRefs);
// TaskNode 識別
if (parseAllRefTab) {
for (Map.Entry<String, IDataTupleCreator> /**
* ref
*/
entry : colsRefs.getBaseRefEntities()) {
entry.getValue().accept(taskNodeRecognizedVisitor);
}
}
return tupleCterator;
} catch (Exception e) {
throw new RuntimeException("exportName:" + this.exportName, e);
}
}
use of com.qlangtech.tis.sql.parser.tuple.creator.impl.TableTupleCreator in project tis by qlangtech.
the class DataFlowAppSource method getTabTriggerLinker.
// @Override
public Map<IEntityNameGetter, List<IValChain>> getTabTriggerLinker() {
try {
SqlTaskNodeMeta.SqlDataFlowTopology topology = SqlTaskNodeMeta.getSqlDataFlowTopology(dataflowName);
TableTupleCreator finalTableNode = topology.parseFinalSqlTaskNode();
ERRules erR = getErRules();
TaskNodeTraversesCreatorVisitor visitor = new TaskNodeTraversesCreatorVisitor(erR);
finalTableNode.accept(visitor);
Map<IEntityNameGetter, List<IValChain>> tabTriggers = visitor.getTabTriggerLinker();
return tabTriggers;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations