Hi all,

Here it goes. The MWE is below.

As you can see when I execute Q_without.rq I get an empty array in bindings. 
However with Qmax_without.rq I get {} (empty object) in bindings.

What I'm saying is that if I'm getting nothing when listing the matching 
entities, I don't know why I get an empty object when listing the matching 
entities with an aggregate operation like MAX. My opinion is that it should be 
an empty resultset as there is nothing matching. That is, I cannot the max of 
nothing.

Hope now it is clear, and sorry for this long thread.

Regards,
Jorge



$ cat dataset.ttl 
<http://example.org/#a> <http://myschema/name> "Jorge" .
<http://example.org/#a> <http://myschema/age> 
"30"^^<http://www.w3.org/2001/XMLSchema#integer> .
<http://example.org/#a> <http://myschema/age> 
"20"^^<http://www.w3.org/2001/XMLSchema#integer> .
<http://example.org/#b> <http://myschema/name> "Jorge" .
<http://example.org/#b> <http://myschema/age> 
"5"^^<http://www.w3.org/2001/XMLSchema#integer> .
<http;//example.org/#b> <http://myschema/age> 
"80"^^<http://www.w3.org/2001/XMLSchema#integer> .
<http://example.org/#c> <http://myschema/name> "Jorge" .
<http://example.org/#c> <http://myschema/age> 
"8"^^<http://www.w3.org/2001/XMLSchema#integer> .
<http://example.org/#c> <http://myschema/age> 
"32"^^<http://www.w3.org/2001/XMLSchema#integer> .
<http://example.org/#d> <http://myschema/name> "Jo" .
<http://example.org/#d> <http://myschema/age> 
"3"^^<http://www.w3.org/2001/XMLSchema#integer> .
<http://example.org/#d> <http://myschema/age> 
"2"^^<http://www.w3.org/2001/XMLSchema#integer> .

$ cat Q_with.rq 
SELECT ?entity ?age  
WHERE {
  ?entity <http://myschema/name> "Jo" .
  ?entity <http://myschema/age> ?age .
}

$ /opt/apache-jena/bin/sparql --query Q_with.rq --data dataset.ttl --results 
json
{
  "head": {
    "vars": [ "entity" , "age" ]
  } ,
  "results": {
    "bindings": [
      {
        "entity": { "type": "uri" , "value": "http://example.org/#d"; } ,
        "age": { "type": "literal" , "datatype": 
"http://www.w3.org/2001/XMLSchema#integer"; , "value": "3" }
      } ,
      {
        "entity": { "type": "uri" , "value": "http://example.org/#d"; } ,
        "age": { "type": "literal" , "datatype": 
"http://www.w3.org/2001/XMLSchema#integer"; , "value": "2" }
      }
    ]
  }
}

$ cat Q_without.rq 
SELECT ?entity ?age  
WHERE {
  ?entity <http://myschema/name> "J" .
  ?entity <http://myschema/age> ?age .
}

$ /opt/apache-jena/bin/sparql --query Q_without.rq --data dataset.ttl --results 
json
{
  "head": {
    "vars": [ "entity" , "age" ]
  } ,
  "results": {
    "bindings": [
      
    ]
  }
}

$ cat Qmax_with.rq 
SELECT ?entity (MAX(?age) AS ?value) 
WHERE {
  ?entity <http://myschema/name> "Jo" .
  ?entity <http://myschema/age> ?age .
} group by ?entity 

$ /opt/apache-jena/bin/sparql --query Qmax_with.rq --data dataset.ttl --results 
json
{
  "head": {
    "vars": [ "entity" , "value" ]
  } ,
  "results": {
    "bindings": [
      {
        "entity": { "type": "uri" , "value": "http://example.org/#d"; } ,
        "value": { "type": "literal" , "datatype": 
"http://www.w3.org/2001/XMLSchema#integer"; , "value": "3" }
      }
    ]
  }
}

$ cat Qmax_without.rq 
SELECT ?entity (MAX(?age) AS ?value) 
WHERE {
  ?entity <http://myschema/name> "J" .
  ?entity <http://myschema/age> ?age .
} group by ?entity 

$ /opt/apache-jena/bin/sparql --query Qmax_without.rq --data dataset.ttl 
--results json
{
  "head": {
    "vars": [ "entity" , "value" ]
  } ,
  "results": {
    "bindings": [
      {
        
      }
    ]
  }
}






On 2017-10-09 09:25, George News wrote:
> On 2017-10-08 11:18, Andy Seaborne wrote:
>> Please - a complete, verifiable, minimal example.
> 
> I will try to compile one simple :(
> 
>> Complete query, small amount of data.
>>
>> Snippets remove details that may matter.
>>
>> With a complete, verifiable, minimal example we can agree on what the
>> question is.
>>
>> Indeed, it is not clear your output is even from Jena. The JSON
>> formatting is not as Jena emits it.
> 
> I just used the Jena one. Only remove newlines in vars to make it shorter.
> 
>>     Andy
>>
>> On 08/10/17 01:37, George News wrote:
>>> Hi,
>>>
>>> Forget the last one. I've just realized again I included a mistake....
>>> this is the good one (I hope ;))
>>>
>>> # Case 1)
>>> select ?id ?value ?latitude ?longitude
>>> where {
>>> ......
>>> }
>>> ----------
>>> {
>>>      "head": {
>>>          "vars": [
>>>              "id", "value", "latitude", "longitude"
>>>          ]
>>>      },
>>>      "results": {
>>>          "bindings": [
>>>          ]
>>>      }
>>> }
>>>
>>> # Case 2)
>>> select ?id (MAX(?ti) as ?time) ?value ?latitude ?longitude
>>> where {
>>> ......
>>> }
>>> ----------
>>> {
>>>      "head": {
>>>          "vars": [
>>>              "id", "time", "value", "latitude", "longitude"
>>>          ]
>>>      },
>>>      "results": {
>>>          "bindings": [
>>>              {}
>>>          ]
>>>      }
>>> }
>>>
>>> Now you can see the difference I was noticing. In the first case
>>> bindings is an empty array (resultset.hasNext() -> false) and the second
>>> is an array with an empty object (resultset.hasNext() -> true).
>>>
>>> Why is this behaviour? Hope you now understand the issue which in my
>>> opinion is a kind of a bug.
>>>
>>> Regards,
>>> Jorge
>>>
>>> On 2017-10-08 00:15, George News wrote:
>>>> Hi Andy,
>>>>
>>>> Now I understand the misunderstanding between you and me. The responses
>>>> I included in my original mail where wrong :( Please accept my
>>>> apologizes.
>>>>
>>>> These are the right query/responses:
>>>>
>>>> # Case 1)
>>>> select ?id (MAX(?ti) as ?time) ?value ?latitude ?longitude
>>>> where {
>>>> ......
>>>> }----------
>>>> {
>>>>      "head": {
>>>>          "vars": [
>>>>              "id", "time", "value", "latitude", "longitude"
>>>>          ]
>>>>      },
>>>>      "results": {
>>>>          "bindings": [
>>>>              {}
>>>>          ]
>>>>      }
>>>> }
>>>>
>>>> # Case 2)
>>>> select ?id (MAX(?ti) as ?time) ?value ?latitude ?longitude
>>>> where {
>>>> ......
>>>> }----------
>>>> {
>>>>      "head": {
>>>>          "vars": [
>>>>              "id", "value", "latitude", "longitude"
>>>>          ]
>>>>      },
>>>>      "results": {
>>>>          "bindings": [
>>>>          ]
>>>>      }
>>>> }
>>>>
>>>> Now you can see the difference I was noticing. In the first case it is
>>>> an empty array (resultset.hasNext() -> false) and the second is an array
>>>> with an empty object (resultset.hasNext() -> true).
>>>>
>>>> Why is this behaviour? Hope you now understand the issue which in my
>>>> opinion is a kind of a bug.
>>>>
>>>> Regards,
>>>> Jorge
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On 2017-10-06 16:11, Andy Seaborne wrote:
>>>>>
>>>>>
>>>>> On 06/10/17 12:26, George News wrote:
>>>>>> On 2017-10-06 11:25, Andy Seaborne wrote:
>>>>>>> The two result sets you show both have one row, with bindings. That's
>>>>>>> consistent with aggregation of nothing (no groups, or if no GROUP
>>>>>>> BY, no
>>>>>>> results from the WHERE pattern.
>>>>>>
>>>>>> I don't see it the same way. The first one (without max) is an empty
>>>>>> array, while the second (with max) has an array with one object
>>>>>> (empty).
>>>>>
>>>>>      "results": {
>>>>>          "bindings": [
>>>>>              {}
>>>>>          ]
>>>>>      }
>>>>>
>>>>> both times.
>>>>>
>>>>> An array of rows, a row is {} i.e. no keys, no variables.
>>>>>
>>>>> But the query isn't legal so I don't know what is actually happening.
>>>>>
>>>>>>
>>>>>>>
>>>>>>> MAX() of nothing is unbound but for any aggregation, there always is
>>>>>>> a row/
>>>>>>>
>>>>>>> c.f. COUNT(*) is 0 when there are no solution.
>>>>>>>
>>>>>>> It's just MAX(...) can't return a "there isn't anything value"
>>>>>>>
>>>>>>>       Andy
>>>>>>>
>>>>>>
>>>>>> I see your point as this gives a wrong idea on the result set as it
>>>>>> really is empty. If I dont get any time I cannot calculate the max of
>>>>>> nothing. In principle this is what Jena is returning as the object is
>>>>>> empty, but there should be a way to not get this empty object
>>>>>> within the
>>>>>> array of bindings.
>>>>>>
>>>>>> Is there anyway I can check the resultset pointer to get the next()
>>>>>> value without moving the pointer? I need to know in advance to
>>>>>> retrieve
>>>>>> all the results if there are or aren't any.
>>>>>>
>>>>>>
>>>>>>>
>>>>>>> On 06/10/17 10:15, George News wrote:
>>>>>>>> Hi all,
>>>>>>>>
>>>>>>>> I am executing a SPARQL with MAX aggregate function and I'm facing a
>>>>>>>> strange behaviour, or at least I think it is.
>>>>>>>>
>>>>>>>> The snipset of the select variables is the following:
>>>>>>>>
>>>>>>>> select ?id (MAX(?ti) as ?time) ?value ?latitude ?longitude
>>>>>>>> where {
>>>>>>>> ......
>>>>>>>> }
>>>>>>>
>>>>>>>>
>>>>>>>> If I launch the SPARQL query and there are results matching there
>>>>>>>> is no
>>>>>>>> problem and I get the expected answer.
>>>>>>>>
>>>>>>>> However if I launch the same query over another database and there
>>>>>>>> should be no match I get the following:
>>>>>>>>
>>>>>>>> {
>>>>>>>>        "head": {
>>>>>>>>            "vars": [
>>>>>>>>                "id", "time", "value", "latitude", "longitude"
>>>>>>>>            ]
>>>>>>>>        },
>>>>>>>>        "results": {
>>>>>>>>            "bindings": [
>>>>>>>>                {}
>>>>>>>>            ]
>>>>>>>>        }
>>>>>>>> }
>>>>>>>>
>>>>>>>> As you can see, although the resultset seems to be empty it is
>>>>>>>> not. It
>>>>>>>> is returning one empty object. Actually by checking
>>>>>>>> resultset.hasNext()
>>>>>>>> within the code it returns true.
>>>>>>>>
>>>>>>>> If I remove the MAX function from the variables everything is ok,
>>>>>>>> and no
>>>>>>>> empty object shows up.
>>>>>>>>
>>>>>>>> select ?id ?value ?latitude ?longitude
>>>>>>>> where {
>>>>>>>> ......
>>>>>>>> }
>>>>>>>> ----------
>>>>>>>> {
>>>>>>>>        "head": {
>>>>>>>>            "vars": [
>>>>>>>>                "id", "value", "latitude", "longitude"
>>>>>>>>            ]
>>>>>>>>        },
>>>>>>>>        "results": {
>>>>>>>>            "bindings": [
>>>>>>>>                {}
>>>>>>>>            ]
>>>>>>>>        }
>>>>>>>> }
>>>>>>>>
>>>>>>>> Why is happening that? Is this the expected behaviour? I guess it
>>>>>>>> shouldn't. When you use COUNT funtion it returns 0, but MIN/MAX/etc
>>>>>>>> arer
>>>>>>>> different functions and if there is no result nothing should appear.
>>>>>>>>
>>>>>>>> Any help/tip is more than welcome.
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>> Jorge
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>
>>>>
>>
> 

Reply via email to