Skip to content

Commit 156d5c2

Browse files
committed
fixes based on review
1 parent bcc695a commit 156d5c2

5 files changed

Lines changed: 95 additions & 2 deletions

File tree

core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/iterator/GroupIterator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*
99
* SPDX-License-Identifier: BSD-3-Clause
1010
*******************************************************************************/
11+
// Some portions generated by Codex
1112
package org.eclipse.rdf4j.query.algebra.evaluation.iterator;
1213

1314
import java.util.ArrayList;
@@ -332,7 +333,7 @@ private List<Entry> emptySolutionSpecialCase(List<AggregatePredicateCollectorSup
332333
// Even in the case that the Count is of a constant value.
333334
predicates.add(ALWAYS_FALSE_VALUE);
334335
} else {
335-
predicates.add(ALWAYS_TRUE_VALUE);
336+
predicates.add(ag.makePotentialDistinctTest.get());
336337
}
337338
}
338339
final Entry entry = new Entry(null, collectors, predicates);

core/queryalgebra/evaluation/src/test/java/org/eclipse/rdf4j/query/algebra/evaluation/iterator/GroupIteratorTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*
99
* SPDX-License-Identifier: BSD-3-Clause
1010
*******************************************************************************/
11+
// Some portions generated by Codex
1112
package org.eclipse.rdf4j.query.algebra.evaluation.iterator;
1213

1314
import static org.assertj.core.api.Assertions.assertThat;
@@ -315,6 +316,23 @@ public void testCustomNAryAggregateFunction_Empty() throws QueryEvaluationExcept
315316
}
316317
}
317318

319+
@Test
320+
public void testCustomNAryAggregateFunction_Empty_DistinctTuplePredicateInvoked() throws QueryEvaluationException {
321+
AggregateNAryFunctionFactory nAryFactory = new DistinctTupleTouchingAggregateNAryFunctionFactory();
322+
CustomAggregateNAryFunctionRegistry.getInstance().add(nAryFactory);
323+
try {
324+
Group group = new Group(EMPTY_ASSIGNMENT);
325+
group.addGroupElement(new GroupElem("naryDistinct",
326+
new AggregateFunctionCall(List.of(Var.of("a"), Var.of("b")), nAryFactory.getIri(), false)));
327+
try (GroupIterator gi = new GroupIterator(EVALUATOR, group, EmptyBindingSet.getInstance(), CONTEXT)) {
328+
assertThat(gi.next().getBinding("naryDistinct").getValue())
329+
.isEqualTo(VF.createLiteral("0", XSD.INTEGER));
330+
}
331+
} finally {
332+
CustomAggregateNAryFunctionRegistry.getInstance().remove(nAryFactory);
333+
}
334+
}
335+
318336
@Test
319337
public void testCustomNAryAggregateFunction_WrongIri() throws QueryEvaluationException {
320338
Group group = new Group(EMPTY_ASSIGNMENT);
@@ -475,6 +493,35 @@ public SumCollector getCollector() {
475493
}
476494
}
477495

496+
private static final class DistinctTupleTouchingAggregateNAryFunctionFactory
497+
implements AggregateNAryFunctionFactory {
498+
@Override
499+
public String getIri() {
500+
return "https://www.rdf4j.org/aggregate#nary-distinct-touching";
501+
}
502+
503+
@Override
504+
public AggregateNAryFunction<SumCollector, Value> buildFunction(
505+
BiFunction<Integer, BindingSet, Value> evaluationStepByIndex) {
506+
return new AggregateNAryFunction<>(evaluationStepByIndex) {
507+
508+
@Override
509+
public void processAggregate(BindingSet bindingSet, Predicate<List<Value>> distinctValue,
510+
SumCollector sumCollector) throws QueryEvaluationException {
511+
List<Value> tuple = new ArrayList<>(2);
512+
tuple.add(evaluate(0, bindingSet));
513+
tuple.add(evaluate(1, bindingSet));
514+
distinctValue.test(tuple);
515+
}
516+
};
517+
}
518+
519+
@Override
520+
public SumCollector getCollector() {
521+
return new SumCollector();
522+
}
523+
}
524+
478525
/**
479526
* Dummy collector to verify custom aggregate functions
480527
*/

core/queryalgebra/model/src/main/java/org/eclipse/rdf4j/query/algebra/AggregateFunctionCall.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*
99
* SPDX-License-Identifier: BSD-3-Clause
1010
******************************************************************************/
11+
// Some portions generated by Codex
1112

1213
package org.eclipse.rdf4j.query.algebra;
1314

@@ -33,7 +34,7 @@ public AggregateFunctionCall(String iri, boolean distinct) {
3334
}
3435

3536
public AggregateFunctionCall(List<ValueExpr> args, String iri, boolean distinct) {
36-
super(args, distinct);
37+
super(args instanceof ArrayList ? args : new ArrayList<>(args), distinct);
3738
this.iri = iri;
3839
}
3940

core/queryalgebra/model/src/main/java/org/eclipse/rdf4j/query/algebra/NAryValueOperator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ protected NAryValueOperator(List<ValueExpr> args) {
5151

5252
public void setArguments(List<ValueExpr> args) {
5353
this.args = args;
54+
for (ValueExpr arg : args) {
55+
arg.setParentNode(this);
56+
}
5457
}
5558

5659
public List<ValueExpr> getArguments() {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 Eclipse RDF4J contributors.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Distribution License v1.0
6+
* which accompanies this distribution, and is available at
7+
* http://www.eclipse.org/org/documents/edl-v10.php.
8+
*
9+
* SPDX-License-Identifier: BSD-3-Clause
10+
*******************************************************************************/
11+
// Some portions generated by Codex
12+
package org.eclipse.rdf4j.query.algebra;
13+
14+
import static org.assertj.core.api.Assertions.assertThat;
15+
16+
import java.util.List;
17+
18+
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
19+
import org.junit.jupiter.api.Test;
20+
21+
class AggregateFunctionCallTest {
22+
23+
@Test
24+
void constructorSetsParentForEachArgument() {
25+
Var argument = Var.of("a");
26+
AggregateFunctionCall aggregateFunctionCall = new AggregateFunctionCall(List.of(argument), "urn:test", false);
27+
28+
assertThat(argument.getParentNode()).isSameAs(aggregateFunctionCall);
29+
}
30+
31+
@Test
32+
void constructorCopiesArgumentsIntoMutableList() {
33+
Var argument = Var.of("a");
34+
AggregateFunctionCall aggregateFunctionCall = new AggregateFunctionCall(List.of(argument), "urn:test", false);
35+
ValueConstant replacement = new ValueConstant(SimpleValueFactory.getInstance().createLiteral(1));
36+
37+
aggregateFunctionCall.replaceChildNode(argument, replacement);
38+
39+
assertThat(aggregateFunctionCall.getArguments()).containsExactly(replacement);
40+
}
41+
}

0 commit comments

Comments
 (0)