Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with multiple OPTIONALs and COALESCE #1761

Open
aindlq opened this issue Feb 4, 2025 · 0 comments · May be fixed by #1847
Open

Issue with multiple OPTIONALs and COALESCE #1761

aindlq opened this issue Feb 4, 2025 · 0 comments · May be fixed by #1847

Comments

@aindlq
Copy link

aindlq commented Feb 4, 2025

  1. If I have a query with multiple optionals where one of them produces no bindings, then the whole query produce no bindings.
PREFIX Platform: <http://www.researchspace.org/resource/system/>
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT * WHERE {
  OPTIONAL {
    <http://www.researchspace.org/resource/system/resource_configurations_container/data/Actor> crm:P67_refers_to ?refersToResourceConfig_1.
  }
  OPTIONAL {
    <http://www.researchspace.org/resource/system/resource_configurations_container/data/Actor> rdf:type Platform:resource_configuration.
    BIND(<http://www.researchspace.org/resource/system/resource_configurations_container/data/Actor> AS ?refersToResourceConfig_2)
  }
  BIND(COALESCE(?refersToResourceConfig_1, ?refersToResourceConfig_2) AS ?resourceConfiguration)
}

query plan:

Image

If I remove first optional then the query actually produce results.

Can be reproduced with a single quad:

<http://www.researchspace.org/resource/system/resource_configurations_container/data/Actor> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.researchspace.org/resource/system/resource_configuration> <http://www.researchspace.org/resource/system/resource_configurations_container/data/Actor> .
  1. I guess related issue with even simpler query, reproducible on any data. I have optional that produce no bindings and then want to use COALESCE to bind some variable to some default value.
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>

SELECT * WHERE {
  OPTIONAL {
    <http://www.researchspace.org/resource/system/resource_configurations_container/data/Actor> crm:P67_refers_to ?refersToResourceConfig_1.
  }
  BIND(COALESCE(?refersToResourceConfig_1, <http://www.researchspace.org/resource/system/resource_configurations_container/data/Actor>) AS ?resourceConfiguration)
}

If OPTIONAL is empty I would expect ?resourceConfiguration to be bound to <http://www.researchspace.org/resource/system/resource_configurations_container/data/Actor>.

Image

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 a pull request may close this issue.

1 participant