You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by michael <mi...@citi.com> on 2018/05/08 09:16:09 UTC

Example of SQL query

Can you someone give an example of a cache in memory being queried via rest.

Here is a simple person class (cut down from example code):
Person.java
<http://apache-ignite-users.70518.x6.nabble.com/file/t1696/Person.java>  

and a populate it:
PersonTest.java
<http://apache-ignite-users.70518.x6.nabble.com/file/t1696/PersonTest.java>  

Now I try to query from a browser:

cache size works (just to prove Im connected and the cache is there)
http://127.0.0.1:8080/ignite?cmd=size&cacheName=person 
gives
{"successStatus":0,"affinityNodeId":null,"error":null,"response":4,"sessionToken":null}

but a simple query by id fails:
http://127.0.0.1:8080/ignite?cmd=qryexe&cacheName=person&pageSize=1&Type=String&arg1=1&qry=id%20%3D%20%3F 
gives
{"successStatus":1,"error":"class org.apache.ignite.IgniteException:
null","response":null,"sessionToken":null}

incedentally metadat fails too:
http://127.0.0.1:8080/ignite?cmd=metadata&cacheName=person
{"successStatus":1,"error":"Failed to handle request: [req=CACHE_METADATA,
err=Failed to request meta data. person is not
found]","response":null,"sessionToken":null}















--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Example of SQL query

Posted by Alexey Kuznetsov <ak...@apache.org>.
Denis,

If this will be awailable in ignite-2.5

Why link is pointing to 2.4 ?

On Thu, May 10, 2018 at 9:53 PM, Denis Magda <dm...@apache.org> wrote:

> Guys,
>
> Starting with Ignite 2.5 it will be possible to use other types of keys in
> addition to String: https://apacheignite.readme.io/v2.4/docs/rest-api-
> 25#section-data-types
>
> --
> Denis
>
> On Thu, May 10, 2018 at 4:39 AM, Ilya Kasnacheev <
> ilya.kasnacheev@gmail.com> wrote:
>
>> I didn't exactly get 1), but I'm sure your best bet is to use
>> keyConfiguration (CacheKeyConfiguration) in this case to set affinity key.
>> Otherwise you're at risk of getting "incompatible affinity keys" error.
>>
>> BTW isn't it a better topic for dev@? Care to crosspost?
>>
>> Regards,
>>
>> --
>> Ilya Kasnacheev
>>
>> 2018-05-09 14:46 GMT+03:00 aealexsandrov <ae...@gmail.com>:
>>
>>> Hi again,
>>>
>>> We already discussed about it recently. At the moment some things works
>>> incorrect in 2.4:
>>>
>>> 1)Rest API only support String as key and value. And looks like you can't
>>> use affinity key on strings for the same issue. But if you can setup it
>>> using AffinityKeyMapper anotation:
>>>
>>>     public static class Key {
>>>         @AffinityKeyMapped
>>>         @QuerySqlField(index = true)
>>>         private final Stringkey;
>>>
>>>         public Key(Stringkeykey) {
>>>             this.key = key;
>>>         }
>>>
>>>         public Stringkey getKey() {
>>>             return key;
>>>         }
>>>     }
>>>
>>> And put it:
>>>
>>> CacheConfiguration<Key, Person> cfg = new CacheConfiguration<>("cache");
>>>
>>> It should work like example from here:
>>>
>>> http://apache-ignite-users.70518.x6.nabble.com/Inconsistency
>>> -reading-cache-from-code-and-via-REST-td21228.html#a21293
>>>
>>> 2)qryexe doesn't work correct. At some reason it ignores _key and _value
>>> fields. Looks like it could be solved in future releases.
>>>
>>> How I am going to show you some working examples how you avoid second
>>> problem:
>>>
>>> StartServerNode.java
>>> <http://apache-ignite-users.70518.x6.nabble.com/file/t1704/S
>>> tartServerNode.java>
>>> StartClientNode.java
>>> <http://apache-ignite-users.70518.x6.nabble.com/file/t1704/S
>>> tartClientNode.java>
>>>
>>> 1)qryfldexe - exactly the same that you want but had another syntax:
>>>
>>> Here -
>>> select%20firstName%2C%20lastName%20from%20Person%20where%20_
>>> key%20%3D%201%20or%20_key%20%3D%203
>>> is select firstName, lastName from Person where _key = 1 or _key = 3
>>>
>>> http://127.0.0.1:8080/ignite?cmd=qryfldexe&pageSize=10&cache
>>> Name=Person&qry=select%20firstName%2C%20lastName%20from%20Pe
>>> rson%20where%20_key%20%3D%201%20or%20_key%20%3D%203
>>>
>>> {"successStatus":0,"error":null,"sessionToken":null,"respons
>>> e":{"items":[["John1","Doe1"],["John3","Doe3"]],"last":true,
>>> "fieldsMetadata":[{"schemaName":"Person","typeName":"PERSON"
>>> ,"fieldName":"FIRSTNAME","fieldTypeName":"java.lang.
>>> String"},{"schemaName":"Person","typeName":"PERSON","
>>> fieldName":"LASTNAME","fieldTypeName":"java.lang.String"}],"queryId":4}}
>>>
>>> 2)get command return the value of some key:
>>>
>>> http://127.0.0.1:8080/ignite?cmd=get&cacheName=Person&key=3
>>>
>>> {"successStatus":0,"affinityNodeId":"37f9d00d-8a7a-4db4-a1af
>>> -16471a548ce1","error":null,"sessionToken":null,"response":
>>> {"firstName":"John3","lastName":"Doe3","id":"3"}}
>>>
>>> 3)getall command return several values for some keys
>>>
>>> http://127.0.0.1:8080/ignite?cmd=getall&cacheName=Person&k1=1&k2=2
>>>
>>> {"successStatus":0,"affinityNodeId":null,"error":null,"sessi
>>> onToken":null,"response":{"1":{"firstName":"John1","lastName
>>> ":"Doe1","id":"1"},"2":{"firstName":"John2","lastName":
>>> "Doe2","id":"2"}}}
>>>
>>> Hope that it will help you.
>>>
>>> BR,
>>> Andrei
>>>
>>>
>>>
>>> --
>>> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>>>
>>
>>
>


-- 
Alexey Kuznetsov

Re: Example of SQL query

Posted by Denis Magda <dm...@apache.org>.
Guys,

Starting with Ignite 2.5 it will be possible to use other types of keys in
addition to String:
https://apacheignite.readme.io/v2.4/docs/rest-api-25#section-data-types

--
Denis

On Thu, May 10, 2018 at 4:39 AM, Ilya Kasnacheev <il...@gmail.com>
wrote:

> I didn't exactly get 1), but I'm sure your best bet is to use
> keyConfiguration (CacheKeyConfiguration) in this case to set affinity key.
> Otherwise you're at risk of getting "incompatible affinity keys" error.
>
> BTW isn't it a better topic for dev@? Care to crosspost?
>
> Regards,
>
> --
> Ilya Kasnacheev
>
> 2018-05-09 14:46 GMT+03:00 aealexsandrov <ae...@gmail.com>:
>
>> Hi again,
>>
>> We already discussed about it recently. At the moment some things works
>> incorrect in 2.4:
>>
>> 1)Rest API only support String as key and value. And looks like you can't
>> use affinity key on strings for the same issue. But if you can setup it
>> using AffinityKeyMapper anotation:
>>
>>     public static class Key {
>>         @AffinityKeyMapped
>>         @QuerySqlField(index = true)
>>         private final Stringkey;
>>
>>         public Key(Stringkeykey) {
>>             this.key = key;
>>         }
>>
>>         public Stringkey getKey() {
>>             return key;
>>         }
>>     }
>>
>> And put it:
>>
>> CacheConfiguration<Key, Person> cfg = new CacheConfiguration<>("cache");
>>
>> It should work like example from here:
>>
>> http://apache-ignite-users.70518.x6.nabble.com/Inconsistency
>> -reading-cache-from-code-and-via-REST-td21228.html#a21293
>>
>> 2)qryexe doesn't work correct. At some reason it ignores _key and _value
>> fields. Looks like it could be solved in future releases.
>>
>> How I am going to show you some working examples how you avoid second
>> problem:
>>
>> StartServerNode.java
>> <http://apache-ignite-users.70518.x6.nabble.com/file/t1704/
>> StartServerNode.java>
>> StartClientNode.java
>> <http://apache-ignite-users.70518.x6.nabble.com/file/t1704/
>> StartClientNode.java>
>>
>> 1)qryfldexe - exactly the same that you want but had another syntax:
>>
>> Here -
>> select%20firstName%2C%20lastName%20from%20Person%20where%20_
>> key%20%3D%201%20or%20_key%20%3D%203
>> is select firstName, lastName from Person where _key = 1 or _key = 3
>>
>> http://127.0.0.1:8080/ignite?cmd=qryfldexe&pageSize=10&cache
>> Name=Person&qry=select%20firstName%2C%20lastName%20from%
>> 20Person%20where%20_key%20%3D%201%20or%20_key%20%3D%203
>>
>> {"successStatus":0,"error":null,"sessionToken":null,"respons
>> e":{"items":[["John1","Doe1"],["John3","Doe3"]],"last":true,
>> "fieldsMetadata":[{"schemaName":"Person","typeName
>> ":"PERSON","fieldName":"FIRSTNAME","fieldTypeName":"ja
>> va.lang.String"},{"schemaName":"Person","typeName":"PERSON",
>> "fieldName":"LASTNAME","fieldTypeName":"java.lang.String"}],"queryId":4}}
>>
>> 2)get command return the value of some key:
>>
>> http://127.0.0.1:8080/ignite?cmd=get&cacheName=Person&key=3
>>
>> {"successStatus":0,"affinityNodeId":"37f9d00d-8a7a-4db4-
>> a1af-16471a548ce1","error":null,"sessionToken":null,"
>> response":{"firstName":"John3","lastName":"Doe3","id":"3"}}
>>
>> 3)getall command return several values for some keys
>>
>> http://127.0.0.1:8080/ignite?cmd=getall&cacheName=Person&k1=1&k2=2
>>
>> {"successStatus":0,"affinityNodeId":null,"error":null,"
>> sessionToken":null,"response":{"1":{"firstName":"John1","
>> lastName":"Doe1","id":"1"},"2":{"firstName":"John2","
>> lastName":"Doe2","id":"2"}}}
>>
>> Hope that it will help you.
>>
>> BR,
>> Andrei
>>
>>
>>
>> --
>> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>>
>
>

Re: Example of SQL query

Posted by Ilya Kasnacheev <il...@gmail.com>.
I didn't exactly get 1), but I'm sure your best bet is to use
keyConfiguration (CacheKeyConfiguration) in this case to set affinity key.
Otherwise you're at risk of getting "incompatible affinity keys" error.

BTW isn't it a better topic for dev@? Care to crosspost?

Regards,

-- 
Ilya Kasnacheev

2018-05-09 14:46 GMT+03:00 aealexsandrov <ae...@gmail.com>:

> Hi again,
>
> We already discussed about it recently. At the moment some things works
> incorrect in 2.4:
>
> 1)Rest API only support String as key and value. And looks like you can't
> use affinity key on strings for the same issue. But if you can setup it
> using AffinityKeyMapper anotation:
>
>     public static class Key {
>         @AffinityKeyMapped
>         @QuerySqlField(index = true)
>         private final Stringkey;
>
>         public Key(Stringkeykey) {
>             this.key = key;
>         }
>
>         public Stringkey getKey() {
>             return key;
>         }
>     }
>
> And put it:
>
> CacheConfiguration<Key, Person> cfg = new CacheConfiguration<>("cache");
>
> It should work like example from here:
>
> http://apache-ignite-users.70518.x6.nabble.com/
> Inconsistency-reading-cache-from-code-and-via-REST-td21228.html#a21293
>
> 2)qryexe doesn't work correct. At some reason it ignores _key and _value
> fields. Looks like it could be solved in future releases.
>
> How I am going to show you some working examples how you avoid second
> problem:
>
> StartServerNode.java
> <http://apache-ignite-users.70518.x6.nabble.com/file/
> t1704/StartServerNode.java>
> StartClientNode.java
> <http://apache-ignite-users.70518.x6.nabble.com/file/
> t1704/StartClientNode.java>
>
> 1)qryfldexe - exactly the same that you want but had another syntax:
>
> Here -
> select%20firstName%2C%20lastName%20from%20Person%
> 20where%20_key%20%3D%201%20or%20_key%20%3D%203
> is select firstName, lastName from Person where _key = 1 or _key = 3
>
> http://127.0.0.1:8080/ignite?cmd=qryfldexe&pageSize=10&
> cacheName=Person&qry=select%20firstName%2C%20lastName%
> 20from%20Person%20where%20_key%20%3D%201%20or%20_key%20%3D%203
>
> {"successStatus":0,"error":null,"sessionToken":null,"
> response":{"items":[["John1","Doe1"],["John3","Doe3"]],"
> last":true,"fieldsMetadata":[{"schemaName":"Person","
> typeName":"PERSON","fieldName":"FIRSTNAME","fieldTypeName":"
> java.lang.String"},{"schemaName":"Person","typeName":"PERSON","fieldName"
> :"LASTNAME","fieldTypeName":"java.lang.String"}],"queryId":4}}
>
> 2)get command return the value of some key:
>
> http://127.0.0.1:8080/ignite?cmd=get&cacheName=Person&key=3
>
> {"successStatus":0,"affinityNodeId":"37f9d00d-
> 8a7a-4db4-a1af-16471a548ce1","error":null,"sessionToken":
> null,"response":{"firstName":"John3","lastName":"Doe3","id":"3"}}
>
> 3)getall command return several values for some keys
>
> http://127.0.0.1:8080/ignite?cmd=getall&cacheName=Person&k1=1&k2=2
>
> {"successStatus":0,"affinityNodeId":null,"error":
> null,"sessionToken":null,"response":{"1":{"firstName":"
> John1","lastName":"Doe1","id":"1"},"2":{"firstName":"John2",
> "lastName":"Doe2","id":"2"}}}
>
> Hope that it will help you.
>
> BR,
> Andrei
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>

Re: Example of SQL query

Posted by aealexsandrov <ae...@gmail.com>.
Hi again,

We already discussed about it recently. At the moment some things works
incorrect in 2.4:

1)Rest API only support String as key and value. And looks like you can't
use affinity key on strings for the same issue. But if you can setup it
using AffinityKeyMapper anotation:

    public static class Key {
        @AffinityKeyMapped
        @QuerySqlField(index = true)
        private final Stringkey;

        public Key(Stringkeykey) {
            this.key = key;
        }

        public Stringkey getKey() {
            return key;
        }
    } 

And put it:

CacheConfiguration<Key, Person> cfg = new CacheConfiguration<>("cache");

It should work like example from here:

http://apache-ignite-users.70518.x6.nabble.com/Inconsistency-reading-cache-from-code-and-via-REST-td21228.html#a21293

2)qryexe doesn't work correct. At some reason it ignores _key and _value
fields. Looks like it could be solved in future releases.

How I am going to show you some working examples how you avoid second
problem:

StartServerNode.java
<http://apache-ignite-users.70518.x6.nabble.com/file/t1704/StartServerNode.java>  
StartClientNode.java
<http://apache-ignite-users.70518.x6.nabble.com/file/t1704/StartClientNode.java>  

1)qryfldexe - exactly the same that you want but had another syntax:

Here -
select%20firstName%2C%20lastName%20from%20Person%20where%20_key%20%3D%201%20or%20_key%20%3D%203
is select firstName, lastName from Person where _key = 1 or _key = 3

http://127.0.0.1:8080/ignite?cmd=qryfldexe&pageSize=10&cacheName=Person&qry=select%20firstName%2C%20lastName%20from%20Person%20where%20_key%20%3D%201%20or%20_key%20%3D%203

{"successStatus":0,"error":null,"sessionToken":null,"response":{"items":[["John1","Doe1"],["John3","Doe3"]],"last":true,"fieldsMetadata":[{"schemaName":"Person","typeName":"PERSON","fieldName":"FIRSTNAME","fieldTypeName":"java.lang.String"},{"schemaName":"Person","typeName":"PERSON","fieldName":"LASTNAME","fieldTypeName":"java.lang.String"}],"queryId":4}}

2)get command return the value of some key:

http://127.0.0.1:8080/ignite?cmd=get&cacheName=Person&key=3

{"successStatus":0,"affinityNodeId":"37f9d00d-8a7a-4db4-a1af-16471a548ce1","error":null,"sessionToken":null,"response":{"firstName":"John3","lastName":"Doe3","id":"3"}}

3)getall command return several values for some keys

http://127.0.0.1:8080/ignite?cmd=getall&cacheName=Person&k1=1&k2=2

{"successStatus":0,"affinityNodeId":null,"error":null,"sessionToken":null,"response":{"1":{"firstName":"John1","lastName":"Doe1","id":"1"},"2":{"firstName":"John2","lastName":"Doe2","id":"2"}}}

Hope that it will help you.

BR,
Andrei



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/