Commit 27fb0a75 authored by wenmo's avatar wenmo

fixbug 字段血缘的relation

parent 505d2c3a
...@@ -68,17 +68,17 @@ public class LineageColumnGenerator { ...@@ -68,17 +68,17 @@ public class LineageColumnGenerator {
Trans trans = entry.getValue(); Trans trans = entry.getValue();
if (trans instanceof SinkTrans) { if (trans instanceof SinkTrans) {
TableCA tableCA = new TableCA((SinkTrans) trans); TableCA tableCA = new TableCA((SinkTrans) trans);
matchSinkField(tableCA,trans); matchSinkField(tableCA, trans);
searchColumnCAId(tableCA); searchColumnCAId(tableCA);
} }
} }
chainRelation(); chainRelation();
} }
private void matchSinkField(TableCA tableCA,Trans trans){ private void matchSinkField(TableCA tableCA, Trans trans) {
for(ColumnCA columnCA: columnCAS){ for (ColumnCA columnCA : columnCAS) {
for(String fieldName: tableCA.getFields()){ for (String fieldName : tableCA.getFields()) {
if(columnCA.getName().equals(fieldName)){ if (columnCA.getName().equals(fieldName)) {
int cid = index++; int cid = index++;
ColumnCA sinkColumnCA = new ColumnCA(cid, fieldName, fieldName, fieldName, fieldName, fieldName, tableCA, trans); ColumnCA sinkColumnCA = new ColumnCA(cid, fieldName, fieldName, fieldName, fieldName, fieldName, tableCA, trans);
columnCASMaps.put(cid, sinkColumnCA); columnCASMaps.put(cid, sinkColumnCA);
...@@ -124,7 +124,7 @@ public class LineageColumnGenerator { ...@@ -124,7 +124,7 @@ public class LineageColumnGenerator {
break; break;
} }
} }
if(columnCA.getId()==cid){ if (columnCA.getId() == cid) {
return; return;
} }
if (!isHad) { if (!isHad) {
...@@ -176,20 +176,22 @@ public class LineageColumnGenerator { ...@@ -176,20 +176,22 @@ public class LineageColumnGenerator {
} }
private void chainRelation() { private void chainRelation() {
Set<NodeRel> nodeRelsChain = new HashSet<>();
for (Integer item : sourceColumns) { for (Integer item : sourceColumns) {
nodeRelsChain.add(new NodeRel(item, getNextSuf(item))); buildSinkSuf(item, item);
} }
columnCASRelChain = nodeRelsChain;
} }
private Integer getNextSuf(Integer sufId) { private void buildSinkSuf(Integer preId, Integer sourcePreId) {
for (NodeRel nodeRel : columnCASRel) { for (NodeRel nodeRel : columnCASRel) {
if (nodeRel.getPreId() == sufId) { if (nodeRel.getPreId() == preId) {
return getNextSuf(nodeRel.getSufId()); Integer nextSufId = nodeRel.getSufId();
if (sinkColumns.contains(nextSufId)) {
columnCASRelChain.add(new NodeRel(sourcePreId, nextSufId));
continue;
}
buildSinkSuf(nextSufId, sourcePreId);
} }
} }
return sufId;
} }
public Map<Integer, Trans> getTransMaps() { public Map<Integer, Trans> getTransMaps() {
......
...@@ -115,6 +115,11 @@ public class MapParseUtils { ...@@ -115,6 +115,11 @@ public class MapParseUtils {
} }
Deque<Integer> stack = new LinkedList<>(); Deque<Integer> stack = new LinkedList<>();
for (int i = 0; i < inStr.length(); i++) { for (int i = 0; i < inStr.length(); i++) {
if (inStr.charAt(i) == ']' && stack.size() == 0) {
selects.add(inStr.substring(startIndex, i));
startIndex = i + 1;
return selects;
}
if (inStr.charAt(i) == ',' && stack.size() == 0) { if (inStr.charAt(i) == ',' && stack.size() == 0) {
selects.add(inStr.substring(startIndex, i)); selects.add(inStr.substring(startIndex, i));
startIndex = i + 1; startIndex = i + 1;
......
...@@ -28,7 +28,7 @@ public class LineageTest { ...@@ -28,7 +28,7 @@ public class LineageTest {
") WITH (\n" + ") WITH (\n" +
" 'connector' = 'print'\n" + " 'connector' = 'print'\n" +
");\n" + ");\n" +
"insert into TT select a||c A ,b B from ST"; "insert into TT select a||c A ,b||c B from ST";
LineageResult result = LineageBuilder.getLineage(sql); LineageResult result = LineageBuilder.getLineage(sql);
System.out.println("end"); System.out.println("end");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment