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()));
// }
}
}
Aggregations