Search in sources :

Example 1 with TabCriteria

use of com.qlangtech.tis.sql.parser.visitor.TableReferenceVisitor.TabCriteria 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

ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)1 JoinOn (com.facebook.presto.sql.tree.JoinOn)1 LogicalBinaryExpression (com.facebook.presto.sql.tree.LogicalBinaryExpression)1 Query (com.facebook.presto.sql.tree.Query)1 SqlTaskNode (com.qlangtech.tis.sql.parser.SqlTaskNode)1 EntityName (com.qlangtech.tis.sql.parser.tuple.creator.EntityName)1 TableDependencyVisitor (com.qlangtech.tis.sql.parser.visitor.TableDependencyVisitor)1 TabCriteria (com.qlangtech.tis.sql.parser.visitor.TableReferenceVisitor.TabCriteria)1