This is an automated email from the ASF dual-hosted git repository. xxyu pushed a commit to branch kylin5 in repository https://gitbox.apache.org/repos/asf/kylin.git
commit fffe5d3f0ed2b69ad3758c5cfce2672a34d880f8 Author: Pengfei Zhan <dethr...@gmail.com> AuthorDate: Tue May 23 15:49:01 2023 +0800 KYLIN-5633 [FOLLOW UP] match partial segments with high data integrity works between models --- .../org/apache/kylin/query/routing/Candidate.java | 5 +++- .../kylin/query/routing/CandidateSortTest.java | 27 +++++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/query-common/src/main/java/org/apache/kylin/query/routing/Candidate.java b/src/query-common/src/main/java/org/apache/kylin/query/routing/Candidate.java index 12f37cd8c4..1d41875973 100644 --- a/src/query-common/src/main/java/org/apache/kylin/query/routing/Candidate.java +++ b/src/query-common/src/main/java/org/apache/kylin/query/routing/Candidate.java @@ -143,7 +143,10 @@ public class Candidate { } public static Comparator<Candidate> realizationCapabilityCostSorter() { - return Comparator.comparingDouble(c -> c.getCapability().getCost()); + return Comparator.comparingDouble(c -> { + boolean isPartialCompare = c.getCapability().isPartialResult(); + return isPartialCompare ? -1 * c.getCapability().getCost() : c.getCapability().getCost(); + }); } public static Comparator<Candidate> modelUuidSorter() { diff --git a/src/query/src/test/java/org/apache/kylin/query/routing/CandidateSortTest.java b/src/query/src/test/java/org/apache/kylin/query/routing/CandidateSortTest.java index 78cf5845b3..d0c7b41014 100644 --- a/src/query/src/test/java/org/apache/kylin/query/routing/CandidateSortTest.java +++ b/src/query/src/test/java/org/apache/kylin/query/routing/CandidateSortTest.java @@ -108,12 +108,27 @@ class CandidateSortTest { @Test void realizationCapabilityCostSorter() { - Candidate c1 = CandidateTestUtils.mockCandidate("model0001", "modelA", 1, 1); - Candidate c2 = CandidateTestUtils.mockCandidate("model0001", "modelA", 1, 2); - Candidate c3 = CandidateTestUtils.mockCandidate("model0001", "modelA", 1, 2); - Comparator<Candidate> comparator = Candidate.realizationCapabilityCostSorter(); - assertSortResult(c1, comparator, Lists.newArrayList(c1, c2)); - assertSortResult(c2, comparator, Lists.newArrayList(c2, c3)); + { + Candidate c1 = CandidateTestUtils.mockCandidate("model0001", "modelA", 1, 1); + Candidate c2 = CandidateTestUtils.mockCandidate("model0001", "modelA", 1, 2); + Candidate c3 = CandidateTestUtils.mockCandidate("model0001", "modelA", 1, 2); + Comparator<Candidate> comparator = Candidate.realizationCapabilityCostSorter(); + assertSortResult(c1, comparator, Lists.newArrayList(c1, c2)); + assertSortResult(c2, comparator, Lists.newArrayList(c2, c3)); + } + + { + Candidate c1 = CandidateTestUtils.mockCandidate("model0001", "modelA", 2, false); + Candidate c2 = CandidateTestUtils.mockCandidate("model0002", "modelB", 2, true); + Candidate c3 = CandidateTestUtils.mockCandidate("model0003", "modelC", 1, false); + Candidate c4 = CandidateTestUtils.mockCandidate("model0004", "modelD", 1, true); + Comparator<Candidate> comparator = Candidate.partialResultSorter() + .thenComparing(Candidate.realizationCapabilityCostSorter()); + assertSortResult(c1, comparator, Lists.newArrayList(c1, c2)); + assertSortResult(c2, comparator, Lists.newArrayList(c2, c4)); + assertSortResult(c3, comparator, Lists.newArrayList(c1, c3)); + assertSortResult(c3, comparator, Lists.newArrayList(c1, c2, c3, c4)); + } } @Test