Skip to content

Fix extra solution per entity in optional property branches - #184

Merged
karelklima merged 1 commit into
karelklima:mainfrom
ddeboer:fix/optional-union-empty-group
Oct 13, 2026
Merged

karelklima merged 1 commit into
karelklima:mainfrom
ddeboer:fix/optional-union-empty-group

Conversation

@ddeboer

@ddeboer ddeboer commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #183.

That PR starts the UNION of optional properties with an empty group, which keeps the solution for an entity that has none of them. The empty group also adds a solution for every entity that does have them, at each level of a nested schema. A store that does not deduplicate CONSTRUCT output, such as QLever, sends the triples of each of those solutions again.

With this change the UNION sits in an OPTIONAL instead:

?iri x:requiredString ?iri_0 .
OPTIONAL {
  { ?iri x:optionalArray ?iri_1 . }
  UNION { ?iri x:otherOptionalArray ?iri_2 . }
}

An entity with 3 values for one optional array and 3 for another now comes back as 3 + 3 = 6 solutions, where 2.10.0 gives 1 + 3 + 3 = 7. An entity with none still comes back as 1. A level with one optional property gets the same shape, which amounts to the plain OPTIONAL it had before #183.

Measurements

I ran findByIri() against the QLever endpoint of the Dataset Knowledge Graph, on its two largest VoID descriptions, with two schemas:

  • class partitions: three nested levels, with one, one and three optional arrays;
  • summary: one level with six optional values and three optional arrays.

Response size:

2.7.2 2.10.0 this change
class partitions, som-persons-in-music 9968 KB 14792 KB 9984 KB
class partitions, iisg-kg 8849 KB 12488 KB 9460 KB
summary, som-persons-in-music 8736 KB 389 KB 388 KB
summary, iisg-kg 8280 KB 324 KB 324 KB

The last column is the 2.10.0 npm build with this change applied to it by hand, not a build of this branch. I compared the decoded entities whole, ignoring array order: they are identical in all three columns.

On the nested schema 2.10.0 was 48% and 41% larger than 2.7.2. iisg-kg stays 7% above 2.7.2: where two optional properties on one level each have a single value, their sum (2 solutions) is higher than their product (1).

An alternative that does not work

I first made only the first branch optional: { OPTIONAL { … } } UNION { … }. That group is evaluated without the bindings of ?iri, so an entity with none of the optional properties is lost. On iisg-kg that dropped 1085 of the 3148 property partitions: the ones without a nested partition.

Tests

The quad count in “Should not multiply the values of optional properties” goes from 34 to 28.

- Wrap the UNION of optional property branches in an OPTIONAL instead of starting it with an empty group
- The empty group added a solution for every entity that has one of the optional properties, at every level of a nested schema
- Update the expected quad count in the optional properties test
@ddeboer ddeboer changed the title Fixed extra solution per entity in optional property branches Fix extra solution per entity in optional property branches Oct 13, 2026
@karelklima
karelklima merged commit 09fc801 into karelklima:main Oct 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants