use of io.mycat.calcite.table.MycatTransientSQLTableScan in project Mycat2 by MyCATApache.
the class PlanImpl method specificSql.
@NotNull
public List<SpecificSql> specificSql(DrdsSqlWithParams drdsSql, int mergeUnionSize) {
List<SpecificSql> res = new ArrayList<>();
getMycatRel().accept(new RelShuttleImpl() {
@Override
protected RelNode visitChildren(RelNode relNode) {
List<Each> sqls = new ArrayList<>();
String parameterizedSql = "";
if (relNode instanceof MycatView) {
MycatView view = (MycatView) relNode;
SqlNode sqlTemplate = view.getSQLTemplate(false);
ImmutableMultimap<String, SqlString> apply = view.apply(mergeUnionSize, sqlTemplate, AsyncMycatDataContextImpl.getSqlMap(executerContext.getConstantMap(), view, drdsSql, drdsSql.getHintDataNodeFilter()), drdsSql.getParams());
ImmutableMultimap<String, SqlString> stringImmutableMultimap = apply;
for (Map.Entry<String, SqlString> entry : (stringImmutableMultimap.entries())) {
SqlString sqlString = new SqlString(entry.getValue().getDialect(), (Util.toLinux(entry.getValue().getSql())), entry.getValue().getDynamicParameters());
sqls.add(new Each(entry.getKey(), sqlString.getSql()));
}
if (relNode instanceof MycatView) {
parameterizedSql = ((MycatView) relNode).getSql();
}
if (relNode instanceof MycatTransientSQLTableScan) {
parameterizedSql = ((MycatTransientSQLTableScan) relNode).getSql();
}
res.add(new SpecificSql(relNode.getDigest(), parameterizedSql, sqls));
} else if (relNode instanceof MycatSQLTableLookup) {
MycatView right = ((MycatSQLTableLookup) relNode).getRight();
right.accept(this);
}
return super.visitChildren(relNode);
}
});
return res;
}
use of io.mycat.calcite.table.MycatTransientSQLTableScan 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