Hi,

You answer just realized I committed an error while typing the question.
I have just sent a good one.

But from the answer below you confirm that the current Jena output is
the desired behaviour. I still don't know why the aggregate for MAX or
MIN returns one row in result. I will have to accept it ;) although I
consider the MAX of nothing is nothing and therefore there shouldn't be
a row.

Then, is there any way I can check that there is result with empty row
without modifying the pointer in the ResultSet? I don't want to use the
ResultSetRewindable class as this one I understand it copies all the
results in memory being this the way to enable going back to the initial
value.

Thank you very much for the help and sorry for bothering so much.

Regards,
Jorge


On 2017-10-08 01:01, Andy Seaborne wrote:
> If there is an aggregation, you will get one row.
> 
> SELECT (MAX(?x) AS ?M)
> { FILTER(false) }
> 
> ==>
> (sparql --query Q.rq)
> -----
> | M |
> =====
> |   |
> -----
> which is:
> (sparql --query Q.rq --results json)
> {
>   "head": {
>     "vars": [ "M" ]
>   } ,
>   "results": {
>     "bindings": [
>       {
> 
>       }
>     ]
>   }
> }
> 
> and no aggregation:
> 
> SELECT ?x
> { FILTER(false) }
> ==>
> -----
> | x |
> =====
> -----
> which is:
> {
>   "head": {
>     "vars": [ "x" ]
>   } ,
>   "results": {
>     "bindings": [
> 
>     ]
>   }
> }
> 
> 
> Aggregation: no rows in the WHERE, one row in the result
> 
> No aggregation, no rows in WHERE, no rows in the result.
> 
> The details are inconsistent - see below.
> 
> On 07/10/17 23: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": [
>>              {}
> 
> Not ARQ output. See above.
> 
>>          ]
>>      }
>> }
>>
>> # Case 2)
>> select ?id (MAX(?ti) as ?time) ?value ?latitude ?longitude
>> where {
>> ......
>> }----------
>> {
>>      "head": {
>>          "vars": [
>>              "id", "value", "latitude", "longitude"
> 
> There is no ?time listed
> 
> Your case two is no aggregation - in which case you get no rows and no
> ?time.
> 
> Now, if you had
> select ?id  ?value ?latitude ?longitude
> 
> and no match in the WHERE, then things are correct.
> 
>>          ]
>>      },
>>      "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).
> 
> In the first the array has one item.
> In the second the array has no items.
> 
>> Why is this behaviour? Hope you now understand the issue which in my
>> opinion is a kind of a bug.
> 
> Please provide a complete, verifiable, minimal example.
> 
>>
>> 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