Skip to content

Select clause disappear from where clause #3707

@YvanDesPatates

Description

@YvanDesPatates

Version

5.6.0

What happened?

Jena do not handle adding a clause values in a where clause nor in an optional clause.

Here is a minimal exemple (I also give a .zip minimal maven project with .jar in it maybe it's more convenient.).

jena-test.zip

To compile and execute project just go in the decompressed directory and run

mvn clean install
java -jar target/jena-test-1.0-SNAPSHOT.jar

minimal code

    public static void main( String[] args )
    {
        Var uriVar = Converters.makeVar("uri");
        Var siteAdressVar = Converters.makeVar("siteAddress");
        Var cityVar = Converters.makeVar("city");

        SelectBuilder select = new SelectBuilder();
        select.addVar(uriVar);

        SelectBuilder selectOptional = new SelectBuilder();
        selectOptional.addVar(uriVar)
                .addVar(cityVar);

        selectOptional.addWhere(uriVar, ORG.siteAddress, siteAdressVar);
        selectOptional.addWhere(siteAdressVar, VCARD4.locality.asNode(), cityVar);

        System.out.println("[ optional select clause ]");
        System.out.println(selectOptional);
        System.out.println("----------------------------------------");

        select.addOptional(selectOptional);

        System.out.println("[ final select query ]");
        System.out.println(select.build());
        System.out.println("----------------------------------------");
    }

output :

[ optional select clause ]
SELECT  ?uri ?city
WHERE
  { ?uri      <http://www.w3.org/ns/org#siteAddress>  ?siteAddress .
    ?siteAddress  <http://www.w3.org/2006/vcard/ns#locality>  ?city}

----------------------------------------
[ final select query ]
SELECT  ?uri
WHERE
  { OPTIONAL
      { ?uri      <http://www.w3.org/ns/org#siteAddress>  ?siteAddress .
        ?siteAddress  <http://www.w3.org/2006/vcard/ns#locality>  ?city}}

----------------------------------------

expected output :

[ final select query ]
SELECT  ?uri
WHERE
  { OPTIONAL
      SELECT  ?uri ?city
      WHERE
        { ?uri      <http://www.w3.org/ns/org#siteAddress>  ?siteAddress .
          ?siteAddress  <http://www.w3.org/2006/vcard/ns#locality>  ?city
        }
  }

as you may noticed, the SELECT ?uri ?city has disappeared as well as the second where clause.

original exemple

The original purpose was to sort on the ?city var which is not returned. For information here is the original request i want to create (tested and validated on an RDF4J workbench server).

full request here
PREFIX org: 
PREFIX dc: 
PREFIX os-sec: 
PREFIX vcard: 
SELECT DISTINCT  ?uri ?rdfType ?rdfTypeName ?lastUpdateDate ?name ?description ?publisher ?publicationDate ?address ?locationObservationCollection
WHERE
  { ?rdfType (rdfs:subClassOf)* org:Site
    OPTIONAL
      { ?rdfType  rdfs:label  ?rdfTypeName
        FILTER langMatches(lang(?rdfTypeName), "en")
      }
    OPTIONAL
      { ?rdfType  rdfs:label  ?rdfTypeName
        FILTER langMatches(lang(?rdfTypeName), "")
      }
    GRAPH 
      { ?uri  rdf:type  ?rdfType
        OPTIONAL
          { ?uri  dc:modified  ?lastUpdateDate}
        OPTIONAL
          { ?uri  rdfs:label  ?name}
        OPTIONAL
          { ?uri  rdfs:comment  ?description}
        OPTIONAL
          { ?uri  dc:publisher  ?publisher}
        OPTIONAL
          { ?uri  dc:issued  ?publicationDate}
        OPTIONAL
          { ?uri  org:siteAddress  ?address}
      }
    OPTIONAL
      { GRAPH 
          { OPTIONAL
              { ?locationObservationCollection
                            ?uri}}}
    OPTIONAL
      { ?_organization
                  org:hasSite  ?uri}
    OPTIONAL
      { ?uri      os-sec:hasGroup       ?groups .
        ?groups   os-sec:hasUserProfile  ?userProfiles .
        ?userProfiles
                  os-sec:hasUser        }
OPTIONAL {
  {
    SELECT ?uri ?city
    WHERE {
      ?uri org:siteAddress ?address .
      ?address vcard:locality ?city .
    }
  }
}
FILTER ( ! isBlank(?uri) )

}
ORDER BY DESC(?city) ASC(?uri)
LIMIT 100

Relevant output and stacktrace

Are you interested in making a pull request?

None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions