You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by George News <ge...@gmx.net> on 2017/10/06 09:15:27 UTC

Problem with MAX when no result expected

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






Re: Problem with MAX when no result expected

Posted by George News <ge...@gmx.net>.
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
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> 

Re: Problem with MAX when no result expected

Posted by Andy Seaborne <an...@apache.org>.
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
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>

Re: Problem with MAX when no result expected

Posted by George News <ge...@gmx.net>.
On 2017-10-08 13:07, Lorenz B. wrote:
> Hello George,
> 
> right now it's really hard to help you. A complete query + sample data
> is missing to reproduce it. In addition, the second query seems to be an
> invalid SPARQL query - at least I don't see grouping by ?id and the
> other values are not aggregates. I don't think this is valid in standard
> SPARQL 1.1 .

The queries pasted where shortcut, this is why the group by, etc was not
there. However on the real execution they are.

> By the way, which triple store do you use? Virtuoso?

No. I'm using Jena TDB. In the future I'm thinking on moving to Virtuoso
to "get more speed?".


> 
> 
> Cheers,
> Lorenz
> 
>> 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
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>

Re: Problem with MAX when no result expected

Posted by "Lorenz B." <bu...@informatik.uni-leipzig.de>.
Hello George,

right now it's really hard to help you. A complete query + sample data
is missing to reproduce it. In addition, the second query seems to be an
invalid SPARQL query - at least I don't see grouping by ?id and the
other values are not aggregates. I don't think this is valid in standard
SPARQL 1.1 .

By the way, which triple store do you use? Virtuoso?



Cheers,
Lorenz

> 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
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
-- 
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center


Re: Problem with MAX when no result expected

Posted by james anderson <ja...@dydra.com>.
good morning;

> On 2017-10-10, at 23:32, George News <ge...@gmx.net> wrote:
> 
> 
> On 2017-10-10 11:25, Rob Vesse wrote:
>> Personally I am certain that Jena is correct in its interpretation of specification and that the specification is the appropriate.
>> 
>> The key point here is that any aggregation requires at least one group to operate over, in the absence of a GROUP BY then there is an implicit group of all Solutions. In the case where there are zero solutions you have an implicit empty group. As has been pointed it out we can still meaningfully aggregate over an empty group e.g. COUNT is zero
> 
> I'm not an expert and have already expressed my concerns. I'm just using
> common sense. I have also discussed it internally with some of my
> colleagues and they somehow agree with my view.

while both common sense and consensus among developers may help to frame a discussion about sparql conformance, in the end, there is no way to avoid coming to terms with the recommendation.

thus the citation in an earlier message:

>> 
>>    On 09/10/17 15:27, George News wrote:
>>> On 2017-10-09 12:31, james anderson wrote:
>>>> good afternoon;
>>>>> On 2017-10-09, at 12:03, George News <ge...@gmx.net> wrote:
>>>>> 
>>>>>> […]
>>>>> 
>>>>> I understood it, but I don't agree with this behaviour. Is this in the
>>>>> standard or is it just Jena behaviour?
>>>> 
>>>> the recommendation describes the intended behaviour here :
>>>> 
>>>>     https://www.w3.org/TR/sparql11-query/#aggregateAlgebra

this passage describes how a form which involves a “group by” clause it to be interpreted.
the process involves constructing a set of labeled solution sequences and reducing those sets by applying aggregation “set functions" to them.
it says nothing about special treatment for an intermediate state in which the set of labeled sequences is empty.
one reading of the recommendation is that it stipulates that the result of a query of the sort under discussion is empty, rather than a unit table.
if this interpretation stands, then the reported result is non-conformant in this regard.

best regards, from berlin,


Re: Problem with MAX when no result expected

Posted by George News <ge...@gmx.net>.
On 2017-10-10 11:25, Rob Vesse wrote:
> Personally I am certain that Jena is correct in its interpretation of specification and that the specification is the appropriate.
> 
> The key point here is that any aggregation requires at least one group to operate over, in the absence of a GROUP BY then there is an implicit group of all Solutions. In the case where there are zero solutions you have an implicit empty group. As has been pointed it out we can still meaningfully aggregate over an empty group e.g. COUNT is zero

I'm not an expert and have already expressed my concerns. I'm just using
common sense. I have also discussed it internally with some of my
colleagues and they somehow agree with my view.

The currently returned  empty group doesn't have reference to any
variable, etc. From the point of view of coding/automation is not a
generic way of getting things. I will have to check if the resultset
variables exist, etc.

Besided my point is that if I get a result this means that I have a
value. For instance if I looking for the highest temperatures of a set
of weather station and the weather station entities are not registered,
then it is impossible to get the max of the temperatures. In this case,
even if using the GROUP BY, what am I grouping? There is nothing to
group so no resultset should be returned.

Let's say that for instance COUNT is different from other aggregate
functions like MAX. COUNT is a function that always returns an integer,
just by definition. On the contrary, MAX is comparing values and if
there are no values to compare then there is no result.

Please don't take me wrong. I just want to make a point. So sorry for
opening the Pandora box on this issue ;)

Regards,
Jorge

> Rob
> 
> On 09/10/2017 16:19, "Andy Seaborne" <an...@apache.org> wrote:
> 
>     
>     
>     On 09/10/17 15:27, George News wrote:
>     > On 2017-10-09 12:31, james anderson wrote:
>     >> good afternoon;
>     >>> On 2017-10-09, at 12:03, George News <ge...@gmx.net> wrote:
>     >>>
>     >>> On 2017-10-09 11:53, Lorenz Buehmann wrote:
>     >>>>
>     >>>>
>     >>>> On 09.10.2017 10:22, George News wrote:
>     >>>>> 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.
>     >>>>>
>     >>>> Well, I guess Andy already gave you the answer in the beginning of
>     >>>> the thread: A query with an aggregate always returns a row by
>     >>>> convention. But compared to the aggregate function COUNT which simply
>     >>>> can return 0 then, MAX can't return any concrete value because the
>     >>>> MAX of nothing is not specified.
>     >>>
>     >>> I understood it, but I don't agree with this behaviour. Is this in the
>     >>> standard or is it just Jena behaviour?
>     >>
>     >> the recommendation describes the intended behaviour here :
>     >>
>     >>
>     >>      https://www.w3.org/TR/sparql11-query/#aggregateAlgebra
>     >>
>     > 
>     > I guess this is it. If the standard says so, we have to stick to it,
>     > although not in favour of that solution.
>     
>     I haven't convinced myself that Jena is right (I haven't checked - 
>     virtuos seemed to do the same though which isn't proof but it's a 
>     completed unconnected implementation) and even if it is, whether the 
>     spec is saying what it means to say.  I don't see different cases for 
>     COUNT(*) and AnyAgg(?x) because I'd expect them to be different in the 
>     case of no GROUP BY.
>     
>     The presence of GROUP BY fundamentally changes the nature of the query.
>     
>     > 
>     > Does anybody knows a way to avoid loading the whole resultset in memory
>     > to check if it has one row and then rewind it to the beginning?
>     
>     ASK WHERE { pattern }
>     
>     	Andy
>     
>     > 
>     > Thanks.
>     > 
>     >>
>     >>
>     >> best regards, from berlin,
>     >>
>     >>
>     >> ---
>     >> james anderson | james@dydra.com | http://dydra.com
>     >>
>     >>
>     >>
>     >>
>     >>
>     >>
>     
> 
> 
> 
> 
> 

Re: Problem with MAX when no result expected

Posted by Rob Vesse <rv...@dotnetrdf.org>.
Personally I am certain that Jena is correct in its interpretation of specification and that the specification is the appropriate.

The key point here is that any aggregation requires at least one group to operate over, in the absence of a GROUP BY then there is an implicit group of all Solutions. In the case where there are zero solutions you have an implicit empty group. As has been pointed it out we can still meaningfully aggregate over an empty group e.g. COUNT is zero

Rob

On 09/10/2017 16:19, "Andy Seaborne" <an...@apache.org> wrote:

    
    
    On 09/10/17 15:27, George News wrote:
    > On 2017-10-09 12:31, james anderson wrote:
    >> good afternoon;
    >>> On 2017-10-09, at 12:03, George News <ge...@gmx.net> wrote:
    >>>
    >>> On 2017-10-09 11:53, Lorenz Buehmann wrote:
    >>>>
    >>>>
    >>>> On 09.10.2017 10:22, George News wrote:
    >>>>> 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.
    >>>>>
    >>>> Well, I guess Andy already gave you the answer in the beginning of
    >>>> the thread: A query with an aggregate always returns a row by
    >>>> convention. But compared to the aggregate function COUNT which simply
    >>>> can return 0 then, MAX can't return any concrete value because the
    >>>> MAX of nothing is not specified.
    >>>
    >>> I understood it, but I don't agree with this behaviour. Is this in the
    >>> standard or is it just Jena behaviour?
    >>
    >> the recommendation describes the intended behaviour here :
    >>
    >>
    >>      https://www.w3.org/TR/sparql11-query/#aggregateAlgebra
    >>
    > 
    > I guess this is it. If the standard says so, we have to stick to it,
    > although not in favour of that solution.
    
    I haven't convinced myself that Jena is right (I haven't checked - 
    virtuos seemed to do the same though which isn't proof but it's a 
    completed unconnected implementation) and even if it is, whether the 
    spec is saying what it means to say.  I don't see different cases for 
    COUNT(*) and AnyAgg(?x) because I'd expect them to be different in the 
    case of no GROUP BY.
    
    The presence of GROUP BY fundamentally changes the nature of the query.
    
    > 
    > Does anybody knows a way to avoid loading the whole resultset in memory
    > to check if it has one row and then rewind it to the beginning?
    
    ASK WHERE { pattern }
    
    	Andy
    
    > 
    > Thanks.
    > 
    >>
    >>
    >> best regards, from berlin,
    >>
    >>
    >> ---
    >> james anderson | james@dydra.com | http://dydra.com
    >>
    >>
    >>
    >>
    >>
    >>
    





Re: Problem with MAX when no result expected

Posted by George News <ge...@gmx.net>.
On 2017-10-09 17:19, Andy Seaborne wrote:
> 
> 
> On 09/10/17 15:27, George News wrote:
>> On 2017-10-09 12:31, james anderson wrote:
>>> good afternoon;
>>>> On 2017-10-09, at 12:03, George News <ge...@gmx.net> wrote:
>>>>
>>>> On 2017-10-09 11:53, Lorenz Buehmann wrote:
>>>>>
>>>>>
>>>>> On 09.10.2017 10:22, George News wrote:
>>>>>> 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.
>>>>>>
>>>>> Well, I guess Andy already gave you the answer in the beginning of
>>>>> the thread: A query with an aggregate always returns a row by
>>>>> convention. But compared to the aggregate function COUNT which simply
>>>>> can return 0 then, MAX can't return any concrete value because the
>>>>> MAX of nothing is not specified.
>>>>
>>>> I understood it, but I don't agree with this behaviour. Is this in the
>>>> standard or is it just Jena behaviour?
>>>
>>> the recommendation describes the intended behaviour here :
>>>
>>>
>>>      https://www.w3.org/TR/sparql11-query/#aggregateAlgebra
>>>
>>
>> I guess this is it. If the standard says so, we have to stick to it,
>> although not in favour of that solution.
> 
> I haven't convinced myself that Jena is right (I haven't checked -
> virtuos seemed to do the same though which isn't proof but it's a
> completed unconnected implementation) and even if it is, whether the
> spec is saying what it means to say.  I don't see different cases for
> COUNT(*) and AnyAgg(?x) because I'd expect them to be different in the
> case of no GROUP BY.
> 
> The presence of GROUP BY fundamentally changes the nature of the query.

The thing is that it has no sense to return a empty object. This lead to
some misunderstandings for automation.


>>
>> Does anybody knows a way to avoid loading the whole resultset in memory
>> to check if it has one row and then rewind it to the beginning?
> 
> ASK WHERE { pattern }

I have considered this option, but then it implies that the pattern is
checked twice, once for the ASK and then for the SELECT. Performance
wise I don't think it is sensible.

Is it possible to rewind a resultset to the initial pointer without
retrieving everything (not using ResultSetRewindable, for instance)?


>     Andy
> 
>>
>> Thanks.
>>
>>>
>>>
>>> best regards, from berlin,
>>>
>>>
>>> ---
>>> james anderson | james@dydra.com | http://dydra.com
>>>
>>>
>>>
>>>
>>>
>>>
> 

Re: Problem with MAX when no result expected

Posted by Andy Seaborne <an...@apache.org>.

On 09/10/17 15:27, George News wrote:
> On 2017-10-09 12:31, james anderson wrote:
>> good afternoon;
>>> On 2017-10-09, at 12:03, George News <ge...@gmx.net> wrote:
>>>
>>> On 2017-10-09 11:53, Lorenz Buehmann wrote:
>>>>
>>>>
>>>> On 09.10.2017 10:22, George News wrote:
>>>>> 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.
>>>>>
>>>> Well, I guess Andy already gave you the answer in the beginning of
>>>> the thread: A query with an aggregate always returns a row by
>>>> convention. But compared to the aggregate function COUNT which simply
>>>> can return 0 then, MAX can't return any concrete value because the
>>>> MAX of nothing is not specified.
>>>
>>> I understood it, but I don't agree with this behaviour. Is this in the
>>> standard or is it just Jena behaviour?
>>
>> the recommendation describes the intended behaviour here :
>>
>>
>>      https://www.w3.org/TR/sparql11-query/#aggregateAlgebra
>>
> 
> I guess this is it. If the standard says so, we have to stick to it,
> although not in favour of that solution.

I haven't convinced myself that Jena is right (I haven't checked - 
virtuos seemed to do the same though which isn't proof but it's a 
completed unconnected implementation) and even if it is, whether the 
spec is saying what it means to say.  I don't see different cases for 
COUNT(*) and AnyAgg(?x) because I'd expect them to be different in the 
case of no GROUP BY.

The presence of GROUP BY fundamentally changes the nature of the query.

> 
> Does anybody knows a way to avoid loading the whole resultset in memory
> to check if it has one row and then rewind it to the beginning?

ASK WHERE { pattern }

	Andy

> 
> Thanks.
> 
>>
>>
>> best regards, from berlin,
>>
>>
>> ---
>> james anderson | james@dydra.com | http://dydra.com
>>
>>
>>
>>
>>
>>

Re: Problem with MAX when no result expected

Posted by George News <ge...@gmx.net>.
On 2017-10-09 12:31, james anderson wrote:
> good afternoon;
>> On 2017-10-09, at 12:03, George News <ge...@gmx.net> wrote:
>>
>> On 2017-10-09 11:53, Lorenz Buehmann wrote:
>>>
>>>
>>> On 09.10.2017 10:22, George News wrote:
>>>> 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.
>>>>
>>> Well, I guess Andy already gave you the answer in the beginning of
>>> the thread: A query with an aggregate always returns a row by
>>> convention. But compared to the aggregate function COUNT which simply
>>> can return 0 then, MAX can't return any concrete value because the
>>> MAX of nothing is not specified.
>>
>> I understood it, but I don't agree with this behaviour. Is this in the
>> standard or is it just Jena behaviour?
> 
> the recommendation describes the intended behaviour here :
> 
> 
>     https://www.w3.org/TR/sparql11-query/#aggregateAlgebra
> 

I guess this is it. If the standard says so, we have to stick to it,
although not in favour of that solution.

Does anybody knows a way to avoid loading the whole resultset in memory
to check if it has one row and then rewind it to the beginning?

Thanks.

> 
> 
> best regards, from berlin,
> 
> 
> ---
> james anderson | james@dydra.com | http://dydra.com
> 
> 
> 
> 
> 
> 

Re: Problem with MAX when no result expected

Posted by james anderson <ja...@dydra.com>.
good afternoon;
> On 2017-10-09, at 12:03, George News <ge...@gmx.net> wrote:
> 
> On 2017-10-09 11:53, Lorenz Buehmann wrote:
>> 
>> 
>> On 09.10.2017 10:22, George News wrote:
>>> 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.
>>> 
>> Well, I guess Andy already gave you the answer in the beginning of
>> the thread: A query with an aggregate always returns a row by
>> convention. But compared to the aggregate function COUNT which simply
>> can return 0 then, MAX can't return any concrete value because the
>> MAX of nothing is not specified.
> 
> I understood it, but I don't agree with this behaviour. Is this in the
> standard or is it just Jena behaviour?

the recommendation describes the intended behaviour here :


    https://www.w3.org/TR/sparql11-query/#aggregateAlgebra

> …


best regards, from berlin,


---
james anderson | james@dydra.com | http://dydra.com






Re: Problem with MAX when no result expected

Posted by George News <ge...@gmx.net>.
On 2017-10-09 11:53, Lorenz Buehmann wrote:
> 
> 
> On 09.10.2017 10:22, George News wrote:
>> 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.
>> 
> Well, I guess Andy already gave you the answer in the beginning of
> the thread: A query with an aggregate always returns a row by
> convention. But compared to the aggregate function COUNT which simply
> can return 0 then, MAX can't return any concrete value because the
> MAX of nothing is not specified.

I understood it, but I don't agree with this behaviour. Is this in the
standard or is it just Jena behaviour?

The issue here is that returning a row in the resultset in something
that leads to misunderstanding, as it seems there is a result available
when there isn't. In this sense, if there were a procedure to know in
advance that the object is empty, it will be ok, but you don't know it
is empty till you call next() and try to get the actual value. In that
case, if you want to print it you cannot rewind (if not stored
everything in memmory).

This is just my humble opinion on the issue. Nothing is nothing and not
one row although empty ;)

Thanks a lot for your understanding.

Regards,
Jorge






>> 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
>> 
>> 
[...snip...]

Re: Problem with MAX when no result expected

Posted by Lorenz Buehmann <bu...@informatik.uni-leipzig.de>.

On 09.10.2017 10:22, George News wrote:
> 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. 
Well, I guess Andy already gave you the answer in the beginning of the
thread:
A query with an aggregate always returns a row by convention. But
compared to the aggregate function COUNT which simply can return 0 then,
MAX can't return any concrete value because the MAX of nothing is not
specified.
> 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
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>


Re: Problem with MAX when no result expected

Posted by George News <ge...@gmx.net>.
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
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>
>>>>
>>
> 

Re: Problem with MAX when no result expected

Posted by George News <ge...@gmx.net>.
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
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>
>>>
> 

Re: Problem with MAX when no result expected

Posted by Andy Seaborne <an...@apache.org>.
Please - a complete, verifiable, minimal example.

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.

     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
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
>>

Re: Problem with MAX when no result expected

Posted by George News <ge...@gmx.net>.
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
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>
> 

Re: Problem with MAX when no result expected

Posted by George News <ge...@gmx.net>.
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
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
> 

Re: Problem with MAX when no result expected

Posted by Andy Seaborne <an...@apache.org>.

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
>>>
>>>
>>>
>>>
>>>
>>

Re: Problem with MAX when no result expected

Posted by Martynas Jusevičius <ma...@atomgraph.com>.
hasNext()?
https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/query/ResultSet.html#hasNext--

On Fri, Oct 6, 2017 at 1:26 PM, George News <ge...@gmx.net> 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).
>
> >
> > 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
> >>
> >>
> >>
> >>
> >>
> >
>

Re: Problem with MAX when no result expected

Posted by George News <ge...@gmx.net>.
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).

> 
> 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
>>
>>
>>
>>
>>
> 

Re: Problem with MAX when no result expected

Posted by Andy Seaborne <an...@apache.org>.
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.

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



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
> 
> 
> 
> 
>