use of io.mycat.calcite.physical.MycatSQLTableLookup in project Mycat2 by MyCATApache.
the class DrdsExecutorCompiler method getCodeExecuterContext.
@NotNull
@SneakyThrows
public static CodeExecuterContext getCodeExecuterContext(Map<RexNode, RexNode> constantMap, MycatRel relNode, boolean forUpdate) {
HashMap<String, Object> varContext = new HashMap<>(2);
StreamMycatEnumerableRelImplementor mycatEnumerableRelImplementor = new StreamMycatEnumerableRelImplementor(varContext);
HashMap<String, MycatRelDatasourceSourceInfo> stat = new HashMap<>();
relNode.accept(new RelShuttleImpl() {
@Override
public RelNode visit(RelNode other) {
CopyMycatRowMetaData rowMetaData = new CopyMycatRowMetaData(new CalciteRowMetaData(other.getRowType().getFieldList()));
if (other instanceof MycatView) {
MycatView view = (MycatView) other;
MycatRelDatasourceSourceInfo rel = stat.computeIfAbsent(other.getDigest(), s -> {
return new MycatRelDatasourceSourceInfo(rowMetaData, view.getSQLTemplate(forUpdate), view);
});
rel.refCount += 1;
}
if (other instanceof MycatTransientSQLTableScan) {
MycatTransientSQLTableScan tableScan = (MycatTransientSQLTableScan) other;
MycatRelDatasourceSourceInfo rel = stat.computeIfAbsent(other.getDigest(), s -> {
return new MycatRelDatasourceSourceInfo(rowMetaData, new TextSqlNode(tableScan.getSql()), tableScan);
});
rel.refCount += 1;
}
if (other instanceof MycatSQLTableLookup) {
MycatView right = ((MycatSQLTableLookup) other).getRight();
right.accept(this);
}
return super.visit(other);
}
});
ClassDeclaration classDeclaration = mycatEnumerableRelImplementor.implementHybridRoot(relNode, EnumerableRel.Prefer.ARRAY);
String code = Expressions.toString(classDeclaration.memberDeclarations, "\n", false);
if (log.isDebugEnabled()) {
log.debug("----------------------------------------code----------------------------------------");
log.debug(code);
}
CodeContext codeContext = new CodeContext(classDeclaration.name, code);
CodeExecuterContext executerContext = CodeExecuterContext.of(constantMap, stat, varContext, relNode, codeContext);
return executerContext;
}
Aggregations