Search in sources :

Example 1 with SqlTaskNode

use of com.qlangtech.tis.sql.parser.SqlTaskNode in project tis by qlangtech.

the class TestSupplyGoodsParse method testTopologyParse.

public void testTopologyParse() throws Exception {
    // this.parseSqlTaskNode()
    List<SqlTaskNode> processNodes = this.parseTopologySqlTaskNodes(topologyName);
    assertTrue(processNodes.size() > 0);
    assertEquals(4, processNodes.size());
    SqlTaskNodeMeta.SqlDataFlowTopology topology = SqlTaskNodeMeta.getSqlDataFlowTopology(topologyName);
    TableTupleCreator tableTupleCreator = topology.parseFinalSqlTaskNode();
    ColRef.ListMap cols = tableTupleCreator.getColsRefs().getColRefMap();
    assertTrue(cols.size() > 0);
    assertEquals("parse from suppyGoods cols size", 58, cols.size());
    assertNotNull("tableTupleCreator", tableTupleCreator);
}
Also used : SqlTaskNode(com.qlangtech.tis.sql.parser.SqlTaskNode) ColRef(com.qlangtech.tis.sql.parser.tuple.creator.impl.ColRef) TableTupleCreator(com.qlangtech.tis.sql.parser.tuple.creator.impl.TableTupleCreator) SqlTaskNodeMeta(com.qlangtech.tis.sql.parser.SqlTaskNodeMeta)

Example 2 with SqlTaskNode

use of com.qlangtech.tis.sql.parser.SqlTaskNode in project tis by qlangtech.

the class TestTableDependencyVisitor method testDependencies.

public void testDependencies() throws Exception {
    List<SqlTaskNode> taskNodes = SqlTaskNodeMeta.getSqlDataFlowTopology("totalpay").parseTaskNodes();
    String order_customers = "order_customers";
    Optional<SqlTaskNode> taskNode = taskNodes.stream().filter((r) -> order_customers.equals(r.getExportName())).findFirst();
    Assert.assertTrue(order_customers + " shall be exist", taskNode.isPresent());
    TableDependencyVisitor dependenciesVisitor = TableDependencyVisitor.create();
    Query query = SqlTaskNode.parseQuery(taskNode.get().getContent());
    dependenciesVisitor.process(query, null);
    // for (String dependency : dependenciesVisitor.getTabDependencies()) {
    // System.out.println(dependency);
    // }
    // Assert.assertTrue(dependenciesVisitor.getTabDependencies().size() > 0);
    Assert.assertEquals(1, dependenciesVisitor.getTabDependencies().size());
    Assert.assertTrue(dependenciesVisitor.getTabDependencies().contains("instance"));
}
Also used : SqlTaskNode(com.qlangtech.tis.sql.parser.SqlTaskNode) List(java.util.List) SqlTaskNode(com.qlangtech.tis.sql.parser.SqlTaskNode) Query(com.facebook.presto.sql.tree.Query) Optional(java.util.Optional) SqlTaskNodeMeta(com.qlangtech.tis.sql.parser.SqlTaskNodeMeta) Assert(com.qlangtech.tis.common.utils.Assert) TestCase(junit.framework.TestCase) Query(com.facebook.presto.sql.tree.Query)

Example 3 with SqlTaskNode

use of com.qlangtech.tis.sql.parser.SqlTaskNode in project tis by qlangtech.

the class TabCriteriaEntityRecognizeVisitor method visit.

@Override
public void visit(TableTupleCreator tableTuple) {
    TabCriteria tableCriteria = tabCriteria;
    // join 部分逻辑处理
    if (!tableCriteria.isPrimary()) {
        JoinOn joinOn = tableCriteria.getJoinOn();
        ComparisonExpression compare = null;
        LogicalBinaryExpression logic = null;
        if (joinOn.getExpression() instanceof ComparisonExpression) {
            // (tp.totalpay_id = o.totalpay_id)
            compare = (ComparisonExpression) joinOn.getExpression();
        } else if (joinOn.getExpression() instanceof LogicalBinaryExpression) {
            // ((tp.card_id = cc.id) AND (tp.entity_id = cc.entity_id))
            logic = (LogicalBinaryExpression) joinOn.getExpression();
        }
    }
    if (this.subQuery != null) {
        // 是像 totalpay/order_customers.txt 文件中那样有内嵌子查询的
        SqlTaskNode subqueryTaskNode = new SqlTaskNode(EntityName.parse(tableCriteria.getName()), NodeType.JOINER_SQL, this.dumpNodsContext);
        // Map<ColName, ValueOperator> columnTracer = Maps.newHashMap();
        // Rewriter rewriter = Rewriter.create(columnTracer);
        subqueryTaskNode.setContent(SqlFormatter.formatSql(this.subQuery.getQuery().getQueryBody(), Optional.empty()));
        TableDependencyVisitor dependenciesVisitor = TableDependencyVisitor.create();
        Query query = SqlTaskNode.parseQuery(subqueryTaskNode.getContent());
        dependenciesVisitor.process(query, null);
        dependenciesVisitor.getTabDependencies().stream().forEach((table) -> {
            // ;
            // 
            // List<TableTupleCreator> tables = SqlTaskNode.dumpNodes.get(table);
            // if (tables.size() != 1) {
            // throw new IllegalStateException("table:" + table + " relevant tab has more than 1 match");
            // }
            // tables.get(0).getEntityName();
            EntityName firstMatch = dumpNodsContext.accurateMatch(table);
            subqueryTaskNode.addRequired(firstMatch, new SqlTaskNode(firstMatch, NodeType.DUMP, this.dumpNodsContext));
        });
        final TableTupleCreator tupleCreator = subqueryTaskNode.parse(true);
        tableTuple.setColsRefs(tupleCreator.getColsRefs());
        tableTuple.setRealEntityName(tupleCreator.getEntityName());
    // tableTuple.setEntityRef(new EntitiyRef(tableCriteria.getName(),
    // subqueryTaskNode));
    } else {
        // tableTuple.setEntityRef(new EntitiyRef(tableCriteria.getName()));
        // List<TableTupleCreator> tabs = null;
        EntityName ename = this.dumpNodsContext.nullableMatch(tableCriteria.getName());
        if (ename != null) {
            tableTuple.setNodetype(NodeType.DUMP);
            tableTuple.setRealEntityName(ename);
        } else {
            tableTuple.setRealEntityName(EntityName.parse(tableCriteria.getName()));
        }
    // if ((tabs = SqlTaskNode.dumpNodes.get(tableCriteria.getName())) != null) {
    // tableTuple.setNodetype(NodeType.DUMP);
    // 
    // if (tabs.size() != 1) {
    // throw new IllegalStateException(
    // "tabname:" + tableCriteria.getName() + " relevant tab size shall be 1 but " + tabs.size());
    // } else {
    // tableTuple.setRealEntityName(tabs.get(0).getEntityName());
    // }
    // } else {
    // tableTuple.setRealEntityName(EntityName.parse(tableCriteria.getName()));
    // }
    }
}
Also used : LogicalBinaryExpression(com.facebook.presto.sql.tree.LogicalBinaryExpression) SqlTaskNode(com.qlangtech.tis.sql.parser.SqlTaskNode) TabCriteria(com.qlangtech.tis.sql.parser.visitor.TableReferenceVisitor.TabCriteria) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Query(com.facebook.presto.sql.tree.Query) EntityName(com.qlangtech.tis.sql.parser.tuple.creator.EntityName) TableDependencyVisitor(com.qlangtech.tis.sql.parser.visitor.TableDependencyVisitor) JoinOn(com.facebook.presto.sql.tree.JoinOn)

Aggregations

SqlTaskNode (com.qlangtech.tis.sql.parser.SqlTaskNode)3 Query (com.facebook.presto.sql.tree.Query)2 SqlTaskNodeMeta (com.qlangtech.tis.sql.parser.SqlTaskNodeMeta)2 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)1 JoinOn (com.facebook.presto.sql.tree.JoinOn)1 LogicalBinaryExpression (com.facebook.presto.sql.tree.LogicalBinaryExpression)1 Assert (com.qlangtech.tis.common.utils.Assert)1 EntityName (com.qlangtech.tis.sql.parser.tuple.creator.EntityName)1 ColRef (com.qlangtech.tis.sql.parser.tuple.creator.impl.ColRef)1 TableTupleCreator (com.qlangtech.tis.sql.parser.tuple.creator.impl.TableTupleCreator)1 TableDependencyVisitor (com.qlangtech.tis.sql.parser.visitor.TableDependencyVisitor)1 TabCriteria (com.qlangtech.tis.sql.parser.visitor.TableReferenceVisitor.TabCriteria)1 List (java.util.List)1 Optional (java.util.Optional)1 TestCase (junit.framework.TestCase)1