use of com.qlangtech.tis.sql.parser.meta.DependencyNode in project tis by qlangtech.
the class TableRelation method createChildPKLiteria.
/**
* 当子表为主表的时候
*
* @param context
* @return
*/
public String createChildPKLiteria(MergeData context) {
try {
DependencyNode child = this.getChild();
EntityName parentEntity = this.getParent().parseEntityName();
EntityName childEntity = child.parseEntityName();
PrimaryTableMeta primary = getPrimaryTableMeta(context, childEntity);
// 主索引连接键
// JoinerKey joinerKey = getPrimaryJoinerKey(primary, false);
// primary.getPrimaryKeyName();
// joinerKey.getParentKey();
// 先查数据库,将子表的记录都查出来
// child.getName();
FuncFormat r = new FuncFormat();
r.startLine("// create by TableRelation.createChildPKLiteria()");
r.startLine("val primaryColMeta = tabColumnMetaMap.get(\"" + primary.getTabName() + "\")");
r.startLine("if (primaryColMeta == null) {");
r.startLine(" throw new IllegalStateException(\"tableName: " + primary.getTabName() + " is not exist in tabColumnMetaMap\")");
r.startLine("}");
r.startLine("val pcol = primaryColMeta.getColMeta(\"" + primary.getDBPrimayKeyName().getName() + "\")");
FlatTableRelation currentTableRelation = this.getCurrentTableRelation(false);
final String methodToken = currentTableRelation.getJoinerKeysQueryMethodToken();
context.addGlobalScript(methodToken, currentTableRelation.buildQueryHeaderByTailerInfo(Collections.emptySet()));
// // 定义结果集对象
// r.startLine(childEntity.buildDefineRowMapListLiteria());
// // 创建查询对象
// r.startLine(childEntity.buildDefineCriteriaEqualLiteria());
//
// //<< 设置查询条件
Stack<FlatTableRelation> unprocessedTableRelationStack = context.getUnprocessedTableRelations();
String paramsList = null;
if (!unprocessedTableRelationStack.empty()) {
FlatTableRelation unprocessedTableRelation = unprocessedTableRelationStack.pop();
// paramsList = unprocessedTableRelation.getTailerKeys().stream().map((m) -> {
// TisGroupBy.TisColumn col = new TisGroupBy.TisColumn(m.getHeadLinkKey());
// r.appendLine(col.buildDefineParam());
// return col.getJavaVarName();
// }).collect(Collectors.joining(","));
paramsList = unprocessedTableRelation.getRel().getJoinerKeys().stream().map((m) -> {
TisGroupBy.TisColumn col = new TisGroupBy.TisColumn(m.getParentKey());
r.appendLine(col.buildDefineParam());
return col.getJavaVarName();
}).collect(Collectors.joining(","));
} else {
paramsList = this.getJoinerKeys().stream().map((m) -> {
TisGroupBy.TisColumn col = new TisGroupBy.TisColumn(m.getParentKey());
r.appendLine(col.buildDefineParam());
return col.getJavaVarName();
}).collect(Collectors.joining(","));
}
boolean isMulti = (this.cardinality == TabCardinality.ONE_N);
// 执行调用方法
r.startLine("val " + (isMulti ? childEntity.entities() + ": List[RowMap] " : childEntity.getJavaEntityName() + ": RowMap ") + " = this.query" + childEntity.javaPropTableName() + "By" + parentEntity.javaPropTableName() + "(" + paramsList + ") ");
if (isMulti) {
// 遍历结果集
r.buildRowMapTraverseLiteria(childEntity, (mm) -> {
mm.startLine("pushPojo2Queue(" + primary.createCompositePK("primaryColMeta", "r") + ", row)");
});
} else {
r.methodBody("if(" + childEntity.getJavaEntityName() + " != null)", (mm) -> {
// mm.startLine("return new CompositePK(" + childEntity.getJavaEntityName() + ", pcol /**子表列*/, sharedId)");
mm.startLine("return " + primary.createCompositePK("primaryColMeta", childEntity.getJavaEntityName()));
});
}
r.startLine(" null /*gencode20200730*/");
return r.toString();
} finally {
context.getUnprocessedTableRelations().clear();
}
}
use of com.qlangtech.tis.sql.parser.meta.DependencyNode in project tis by qlangtech.
the class TestSqlDataFlowTopology method testDeserialize.
public void testDeserialize() throws Exception {
// 通过yaml的反序列化方式
SqlDataFlowTopology topology = SqlTaskNodeMeta.getSqlDataFlowTopology("totalpay");
// topology.getFinalNode()
String jsonContent = com.alibaba.fastjson.JSON.toJSONString(topology, SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.PrettyFormat);
// Assert.assertTrue(topology.getTimestamp() > 0);
Assert.assertTrue(topology.getDumpNodes().size() > 0);
Assert.assertTrue(topology.getNodeMetas().size() > 0);
Assert.assertTrue(StringUtils.isNotBlank(topology.getName()));
Assert.assertNotNull(jsonContent);
// System.out.println(jsonContent);
SqlDataFlowTopology topology2 = SqlDataFlowTopology.deserialize(jsonContent);
Assert.assertNotNull(topology2);
Collection<DependencyNode> dumpNodes = topology2.getDumpNodes();
Assert.assertEquals(topology.getDumpNodes().size(), dumpNodes.size());
Assert.assertEquals(topology.getName(), topology2.getName());
List<SqlTaskNodeMeta> sqlNode = topology2.getNodeMetas();
for (SqlTaskNodeMeta n : sqlNode) {
Assert.assertTrue(n.getDependencies().size() > 0);
Assert.assertNotNull(n.getSql());
}
Assert.assertEquals(topology.getNodeMetas().size(), sqlNode.size());
Assert.assertEquals(topology.getTimestamp(), topology2.getTimestamp());
}
use of com.qlangtech.tis.sql.parser.meta.DependencyNode in project tis by qlangtech.
the class ERRules method getFirstParent.
/**
* 取得第一个父表关系, 一个表有多个父表,优先取为主索引表的父表
*
* @param tabName
* @return
*/
public Optional<TableRelation> getFirstParent(String tabName) {
// List<PrimaryTableMeta> primaryTableNames = this.getPrimaryTabs();
DependencyNode child;
TableRelation resultRel = null;
Optional<PrimaryTableMeta> hasPrimaryParent = null;
for (TableRelation relation : this.getRelationList()) {
child = relation.getChild();
if (StringUtils.equals(child.getName(), tabName)) {
resultRel = relation;
// 优先选取主索引表
if (isPrimaryTable(relation.getParent().getName()).isPresent()) {
return Optional.of(relation);
}
}
}
if (resultRel != null) {
return Optional.of(resultRel);
}
return Optional.empty();
}
use of com.qlangtech.tis.sql.parser.meta.DependencyNode in project tis by qlangtech.
the class ERRules method getTimestampVerColumn.
/**
* 取得表的时间戳生成列
*
* @param tableName
* @return
*/
@Override
public String getTimestampVerColumn(EntityName tableName) {
if (this.isTriggerIgnore(tableName)) {
throw new IllegalStateException("tab:" + tableName + " is not monitor in incr process");
}
DependencyNode dumpNode = getDumpNode(tableName);
TabExtraMeta extraMeta = dumpNode.getExtraMeta();
if (extraMeta == null || StringUtils.isEmpty(extraMeta.getTimeVerColName())) {
throw new IllegalStateException("table:" + tableName + " can not find 'timeVerColName' prop");
}
return extraMeta.getTimeVerColName();
}
use of com.qlangtech.tis.sql.parser.meta.DependencyNode in project tis by qlangtech.
the class DataFlowAppSource method getProcessDataResults.
// @Override
// public List<PrimaryTableMeta> getPrimaryTabs() {
// return getErRules().getPrimaryTabs();
// }
@Override
public ExecuteResult getProcessDataResults(IExecChainContext execChainContext, ISingleTableDumpFactory singleTableDumpFactory, IDataProcessFeedback dataProcessFeedback, ITaskPhaseInfo taskPhaseInfo) throws Exception {
// 执行工作流数据结构
SqlTaskNodeMeta.SqlDataFlowTopology topology = SqlTaskNodeMeta.getSqlDataFlowTopology(dataflowName);
Map<String, TISReactor.TaskAndMilestone> /**
* taskid
*/
taskMap = Maps.newHashMap();
// 取得workflowdump需要依赖的表
Collection<DependencyNode> tables = topology.getDumpNodes();
StringBuffer dumps = new StringBuffer("dependency table:\n");
dumps.append("\t\t=======================\n");
for (DependencyNode t : tables) {
dumps.append("\t\t").append(t.getDbName()).append(".").append(t.getName()).append("[").append(t.getTabid()).append(",").append("] \n");
}
dumps.append("\t\t=======================\n");
logger.info(dumps.toString());
// 将所有的表的状态先初始化出来
DumpPhaseStatus dumpPhaseStatus = taskPhaseInfo.getPhaseStatus(execChainContext, FullbuildPhase.FullDump);
DataflowTask tabDump = null;
for (DependencyNode dump : topology.getDumpNodes()) {
tabDump = singleTableDumpFactory.createSingleTableDump(dump, false, /* isHasValidTableDump */
"tableDump.getPt()", execChainContext.getZkClient(), execChainContext, dumpPhaseStatus);
taskMap.put(dump.getId(), new TISReactor.TaskAndMilestone(tabDump));
}
if (topology.isSingleTableModel()) {
return executeDAG(execChainContext, topology, dataProcessFeedback, taskMap);
} else {
final ExecuteResult[] faildResult = new ExecuteResult[1];
TemplateContext tplContext = new TemplateContext(execChainContext);
JoinPhaseStatus joinPhaseStatus = taskPhaseInfo.getPhaseStatus(execChainContext, FullbuildPhase.JOIN);
IPluginStore<FlatTableBuilder> pluginStore = TIS.getPluginStore(FlatTableBuilder.class);
Objects.requireNonNull(pluginStore.getPlugin(), "flatTableBuilder can not be null");
// chainContext.setFlatTableBuilderPlugin(pluginStore.getPlugin());
// execChainContext.getFlatTableBuilder();
final IFlatTableBuilder flatTableBuilder = pluginStore.getPlugin();
final SqlTaskNodeMeta fNode = topology.getFinalNode();
flatTableBuilder.startTask((context) -> {
DataflowTask process = null;
for (SqlTaskNodeMeta pnode : topology.getNodeMetas()) {
/**
* ***********************************
* 构建宽表构建任务节点
* ************************************
*/
process = flatTableBuilder.createTask(pnode, StringUtils.equals(fNode.getId(), pnode.getId()), tplContext, context, joinPhaseStatus.getTaskStatus(pnode.getExportName()));
taskMap.put(pnode.getId(), new TISReactor.TaskAndMilestone(process));
}
faildResult[0] = executeDAG(execChainContext, topology, dataProcessFeedback, taskMap);
});
return faildResult[0];
}
}
Aggregations