How can query data from multiple caches,like sql UNION

classic Classic list List threaded Threaded
4 messages Options
cuike cuike
Reply | Threaded
Open this post in threaded view
|

How can query data from multiple caches,like sql UNION

This post has NOT been accepted by the mailing list yet.
I have a two cache,threy are store same object .But I want to qurey all data from the two cache,like sql union ,union all data from the  two cache.


code in https://github.com/sdcuike/Ignite-2015/blob/master/src/main/java/com/doctor/ignite/example/spring/CrossCacheQueries.java

The result is: only have one cache values,not all cache values;


I see :http://apache-ignite-users.70518.x6.nabble.com/UNION-still-not-working-with-1-0-2-td178.html#a182

vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: How can query data from multiple caches,like sql UNION

cuike wrote
I have a two cache,threy are store same object .But I want to qurey all data from the two cache,like sql union ,union all data from the  two cache.

code in https://github.com/sdcuike/Ignite-2015/blob/master/src/main/java/com/doctor/ignite/example/spring/CrossCacheQueries.java

The result is: only have one cache values,not all cache values;

I see :http://apache-ignite-users.70518.x6.nabble.com/UNION-still-not-working-with-1-0-2-td178.html#a182
Hi,

You query doesn't have UNION clause at all, that's why it returns values from one cache only. To make it work you should use SqlFieldsQuery and select special _val field from both caches. This is an internal field that is automatically added to any table and contains the reference to the corresponding cache entry value. Here is how you should declare the query:

SqlFieldsQuery sqlQuery = new SqlFieldsQuery("select _val from Person union select _val from \"person2\".Person");

Actually, is there any reason for having two caches with one data type? I'm not sure I understand your use case. Can you clarify?

-Val
cuike cuike
Reply | Threaded
Open this post in threaded view
|

Re: How can query data from multiple caches,like sql UNION

This post has NOT been accepted by the mailing list yet.
This post was updated on .
Thank you ,I understand what you mean. I want to store data day by day,like Time Series DataBase. My data is very big, so a day store today's data. When I want data of a week, I should use like sql 'select * from table_201208024 union select * from table_201208025,...' Thank you again,It works: https://github.com/sdcuike/Ignite-2015/blob/master/src/main/java/com/doctor/ignite/example/spring/SqlUnion.java
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: How can query data from multiple caches,like sql UNION

cuike wrote
Thank you ,I understand what you mean.

I want to store data day by day,like Time Series DataBase.
My data is very big, so a day store today's data.
When I want data of a week, I should use like sql 'select * from table_201208024 union select * from table_201208025,...'

Thank you again,It works:
https://github.com/sdcuike/Ignite-2015/blob/master/src/main/java/com/doctor/ignite/example/spring/SqlUnion.java
Your approach will also work, but you actually do not need separate caches for this. I would just add an indexed timestamp field and query by the required timeframe. This looks more flexible, because what if you need data for some part of the day only?

-Val