[improvement][headless-core] 提升join准确性,修复join条件错误问题 (#1945)
Some checks are pending
supersonic CentOS CI / build (11) (push) Waiting to run
supersonic CentOS CI / build (21) (push) Waiting to run
supersonic CentOS CI / build (8) (push) Waiting to run
supersonic mac CI / build (11) (push) Waiting to run
supersonic mac CI / build (21) (push) Waiting to run
supersonic mac CI / build (8) (push) Waiting to run
supersonic ubuntu CI / build (11) (push) Waiting to run
supersonic ubuntu CI / build (21) (push) Waiting to run
supersonic ubuntu CI / build (8) (push) Waiting to run
supersonic windows CI / build (11) (push) Waiting to run
supersonic windows CI / build (21) (push) Waiting to run
supersonic windows CI / build (8) (push) Waiting to run

This commit is contained in:
siriusbo
2024-12-09 22:13:27 +08:00
committed by GitHub
parent 09ea5db0ba
commit 3db9a0dcec
2 changed files with 23 additions and 6 deletions

View File

@@ -343,18 +343,25 @@ public class DataModelNode extends SemanticNode {
Map<String, Long> orders = new HashMap<>();
joinDataModelNames.add(baseDataModel.getName());
orders.put(baseDataModel.getName(), 0L);
// Adjust the order of tables in the data source to facilitate subsequent joins
ArrayList<String> joinTables = new ArrayList<>();
for (JoinRelation joinRelation : ontology.getJoinRelations()) {
if (joinDataModelNames.contains(joinRelation.getLeft())
&& joinDataModelNames.contains(joinRelation.getRight())) {
orders.put(joinRelation.getLeft(), 0L);
orders.put(joinRelation.getRight(), 1L);
joinTables.add(joinRelation.getLeft());
joinTables.add(joinRelation.getRight());
}
}
orders.entrySet().stream().sorted(Map.Entry.comparingByValue()).forEach(d -> {
joinDataModels.add(ontology.getDataModelMap().get(d.getKey()));
});
for (String joinTable : joinTables) {
orders.put(joinTable, orders.getOrDefault(joinTable, 0L) + 1L);
}
orders.entrySet().stream()
.sorted((entry1, entry2) -> entry2.getValue().compareTo(entry1.getValue())) // 倒序排序
.forEach(d -> {
joinDataModels.add(ontology.getDataModelMap().get(d.getKey()));
});
}
return joinDataModels;
}

View File

@@ -306,6 +306,16 @@ public class JoinRender extends Renderer {
r.getMiddle(), tableView.getAlias() + "." + r.getRight()))
.collect(Collectors.toList()));
matchJoinRelation.setJoinType(joinRelation.getJoinType());
// Added join condition judgment to solve the problem of join condition order
} else if (joinRelation.getLeft()
.equalsIgnoreCase(tableView.getDataModel().getName())
&& before.containsKey(joinRelation.getRight())) {
matchJoinRelation.setJoinCondition(joinRelation.getJoinCondition().stream()
.map(r -> Triple.of(
before.get(joinRelation.getRight()) + "." + r.getRight(),
r.getMiddle(), tableView.getAlias() + "." + r.getLeft()))
.collect(Collectors.toList()));
matchJoinRelation.setJoinType(joinRelation.getJoinType());
}
}
}