Skip to content

Commit 6d40bbd

Browse files
committed
Try to improve the distinct behavior
1 parent 538bf77 commit 6d40bbd

File tree

1 file changed

+13
-3
lines changed
  • lib/graphfusion-logical/src/paths/path_node

1 file changed

+13
-3
lines changed

lib/graphfusion-logical/src/paths/path_node/rewrite.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ impl PathToJoinsRule {
135135
.reduce(|lhs, rhs| or(lhs, rhs))
136136
.expect("There must be at least one element in the negated property set.");
137137

138-
self.scan_quads(graph, Some(not(test_expression)))
138+
let paths = self.scan_quads(graph, Some(not(test_expression)))?;
139+
make_distinct(paths)
139140
}
140141

141142
/// Reverses the inner path by swapping [COL_SOURCE] and [COL_TARGET].
@@ -173,7 +174,7 @@ impl PathToJoinsRule {
173174
) -> DFResult<LogicalPlanBuilder> {
174175
let lhs = self.rewrite_property_path_expression(graph, lhs)?;
175176
let rhs = self.rewrite_property_path_expression(graph, rhs)?;
176-
join_path_sequence(lhs, rhs)
177+
make_distinct(join_path_sequence(lhs, rhs)?)
177178
}
178179

179180
/// Rewrites a zero or more to a CTE.
@@ -184,7 +185,8 @@ impl PathToJoinsRule {
184185
) -> DFResult<LogicalPlanBuilder> {
185186
let zero = self.zero_length_paths(graph)?;
186187
let repetition = self.rewrite_one_or_more(graph, inner)?;
187-
join_path_alternatives(zero, repetition)
188+
let paths = join_path_alternatives(zero, repetition)?;
189+
make_distinct(paths)
188190
}
189191

190192
/// Rewrites a one or more by building a recursive query.
@@ -308,6 +310,14 @@ fn join_path_alternatives(
308310

309311
/// Makes the path set distinct.
310312
fn make_distinct(builder: LogicalPlanBuilder) -> DFResult<LogicalPlanBuilder> {
313+
// TODO: Behavior is weird for pp02 and pp12. The missing results are present.
314+
// E.g., Result for pp02:
315+
//
316+
// Note: missing solutions in yellow and extra solutions in blue
317+
// {?x = <http://www.example.org/instance#a> }
318+
// {?x = <http://www.example.org/instance#a> }
319+
// {?x = <http://www.example.org/instance#a> }
320+
// {?x = <http://www.example.org/instance#c> }
311321
builder.distinct_on(
312322
vec![
313323
ENC_WITH_SORTABLE_ENCODING.call(vec![col(COL_GRAPH)]),

0 commit comments

Comments
 (0)