Search in sources :

Example 6 with TableTupleCreator

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());
    });
}
Also used : TableTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.impl.TableTupleCreator) FunctionDataTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.impl.FunctionDataTupleCreator) TisGroup(com.qlangtech.tis.sql.parser.TisGroupBy.TisGroup) ColRef(com.qlangtech.tis.sql.parser.tuple.creator.impl.ColRef) IDataTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.IDataTupleCreator)

Example 7 with TableTupleCreator

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()));
            }
        }
    }
}
Also used : IEntityNameGetter(com.qlangtech.tis.sql.parser.tuple.creator.IEntityNameGetter) List(java.util.List) TestERRules(com.qlangtech.tis.sql.parser.er.TestERRules) IValChain(com.qlangtech.tis.sql.parser.tuple.creator.IValChain) TaskNodeTraversesCreatorVisitor(com.qlangtech.tis.sql.parser.tuple.creator.impl.TaskNodeTraversesCreatorVisitor) Map(java.util.Map) TableTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.impl.TableTupleCreator) Joiner(com.google.common.base.Joiner) TaskNodeTraversesCreatorVisitor(com.qlangtech.tis.sql.parser.tuple.creator.impl.TaskNodeTraversesCreatorVisitor) TableTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.impl.TableTupleCreator) IValChain(com.qlangtech.tis.sql.parser.tuple.creator.IValChain) List(java.util.List) IEntityNameGetter(com.qlangtech.tis.sql.parser.tuple.creator.IEntityNameGetter) Map(java.util.Map)

Example 8 with TableTupleCreator

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);
    }
}
Also used : ColRef(com.qlangtech.tis.sql.parser.tuple.creator.impl.ColRef) StreamTransformVisitor(com.qlangtech.tis.sql.parser.visitor.StreamTransformVisitor) IDataTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.IDataTupleCreator) TableTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.impl.TableTupleCreator) Query(com.facebook.presto.sql.tree.Query) Map(java.util.Map)

Example 9 with TableTupleCreator

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);
    }
}
Also used : TaskNodeTraversesCreatorVisitor(com.qlangtech.tis.sql.parser.tuple.creator.impl.TaskNodeTraversesCreatorVisitor) TableTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.impl.TableTupleCreator) SqlTaskNodeMeta(com.qlangtech.tis.sql.parser.SqlTaskNodeMeta) IEntityNameGetter(com.qlangtech.tis.sql.parser.tuple.creator.IEntityNameGetter)

Aggregations

TableTupleCreator (com.qlangtech.tis.sql.parser.tuple.creator.impl.TableTupleCreator)9 IDataTupleCreator (com.qlangtech.tis.sql.parser.tuple.creator.IDataTupleCreator)5 ColRef (com.qlangtech.tis.sql.parser.tuple.creator.impl.ColRef)5 FunctionDataTupleCreator (com.qlangtech.tis.sql.parser.tuple.creator.impl.FunctionDataTupleCreator)3 Map (java.util.Map)3 Joiner (com.google.common.base.Joiner)2 SqlTaskNodeMeta (com.qlangtech.tis.sql.parser.SqlTaskNodeMeta)2 IEntityNameGetter (com.qlangtech.tis.sql.parser.tuple.creator.IEntityNameGetter)2 TaskNodeTraversesCreatorVisitor (com.qlangtech.tis.sql.parser.tuple.creator.impl.TaskNodeTraversesCreatorVisitor)2 com.facebook.presto.sql.tree (com.facebook.presto.sql.tree)1 Type (com.facebook.presto.sql.tree.Join.Type)1 Query (com.facebook.presto.sql.tree.Query)1 StackableAstVisitorContext (com.facebook.presto.sql.tree.TISStackableAstVisitor.StackableAstVisitorContext)1 IDumpNodeMapContext (com.qlangtech.tis.sql.parser.IDumpNodeMapContext)1 NodeProcessResult (com.qlangtech.tis.sql.parser.NodeProcessResult)1 SqlTaskNode (com.qlangtech.tis.sql.parser.SqlTaskNode)1 TisGroupBy (com.qlangtech.tis.sql.parser.TisGroupBy)1 TisGroup (com.qlangtech.tis.sql.parser.TisGroupBy.TisGroup)1 TestERRules (com.qlangtech.tis.sql.parser.er.TestERRules)1 EntityName (com.qlangtech.tis.sql.parser.tuple.creator.EntityName)1