Purpose of cache in cache.query(Create Table ...) statement

classic Classic list List threaded Threaded
7 messages Options
Shravya Nethula Shravya Nethula
Reply | Threaded
Open this post in threaded view
|

Purpose of cache in cache.query(Create Table ...) statement

Hi guys,

I am new to the world of Ignite. I am currently going through the examples
folder.
The following are the statements from example CacheQueryDdlExample
(apache-ignite-fabric-2.3.0-bin/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryDdlExample.java):

cache.query(new SqlFieldsQuery(
                    "CREATE TABLE city (id LONG PRIMARY KEY, name VARCHAR)
WITH \"template=replicated\"")).getAll();

cache.query(new SqlFieldsQuery(
                    "CREATE TABLE person (id LONG, name VARCHAR, city_id
LONG, PRIMARY KEY (id, city_id)) " +
                    "WITH \"backups=1, affinityKey=city_id\"")).getAll();

From the above two statements, "cache" is used to create two other caches
"SQL_PUBLIC_CITY" and "SQL_PUBLIC_PERSON". Why do we need one cache to
create another cache? What is the main purpose of "cache"?

I kindly request you guys to throw some light on this topic. Any related
information is appreciable.

Regards,
Shravya Nethula.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Andrew Mashenkov Andrew Mashenkov
Reply | Threaded
Open this post in threaded view
|

Re: Purpose of cache in cache.query(Create Table ...) statement

Hi Shravya,


This is because of Ignite API allows to run query with having some cache instance.

We are going to deprecate with API and implement SQL API on higher level to avoid dummy cache creation, 
but anyway old API can't be dropped until next major (3.0) version due to compatibility requirements.

On Mon, Jan 15, 2018 at 5:12 PM, Shravya Nethula <[hidden email]> wrote:
Hi guys,

I am new to the world of Ignite. I am currently going through the examples
folder.
The following are the statements from example CacheQueryDdlExample
(apache-ignite-fabric-2.3.0-bin/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryDdlExample.java):

cache.query(new SqlFieldsQuery(
                    "CREATE TABLE city (id LONG PRIMARY KEY, name VARCHAR)
WITH \"template=replicated\"")).getAll();

cache.query(new SqlFieldsQuery(
                    "CREATE TABLE person (id LONG, name VARCHAR, city_id
LONG, PRIMARY KEY (id, city_id)) " +
                    "WITH \"backups=1, affinityKey=city_id\"")).getAll();

From the above two statements, "cache" is used to create two other caches
"SQL_PUBLIC_CITY" and "SQL_PUBLIC_PERSON". Why do we need one cache to
create another cache? What is the main purpose of "cache"?

I kindly request you guys to throw some light on this topic. Any related
information is appreciable.

Regards,
Shravya Nethula.



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



--
Best regards,
Andrey V. Mashenkov
Regards,
Andrew.
Shravya Nethula Shravya Nethula
Reply | Threaded
Open this post in threaded view
|

Re: Purpose of cache in cache.query(Create Table ...) statement

Hi Andrey,

Thank you for the information.

I want to create some tables using cache.query(Create Table ...) statement.
Is there any way in which I can group some of my tables in one cache? Is
there any hierarchy in organizing the caches like a super cache holding some
sub caches?

Regards,
Shravya Nethula.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Andrew Mashenkov Andrew Mashenkov
Reply | Threaded
Open this post in threaded view
|

Re: Purpose of cache in cache.query(Create Table ...) statement

Hi

Seems, you are looking for CacheGroup [1].
You can use same cache group for number of caches [2] via setting additional parameter in 'Create table' query.


On Tue, Jan 16, 2018 at 9:43 AM, Shravya Nethula <[hidden email]> wrote:
Hi Andrey,

Thank you for the information.

I want to create some tables using cache.query(Create Table ...) statement.
Is there any way in which I can group some of my tables in one cache? Is
there any hierarchy in organizing the caches like a super cache holding some
sub caches?

Regards,
Shravya Nethula.



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



--
Best regards,
Andrey V. Mashenkov
Regards,
Andrew.
Shravya Nethula Shravya Nethula
Reply | Threaded
Open this post in threaded view
|

Re: Purpose of cache in cache.query(Create Table ...) statement

Hi Andrey,

This information will definitely be useful. Thank you.

Regards,
Shravya Nethula.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
dmagda dmagda
Reply | Threaded
Open this post in threaded view
|

Re: Purpose of cache in cache.query(Create Table ...) statement

In reply to this post by Shravya Nethula
Hi Shravya,

The best practice is to have a cache (and SQL table) per a business entity of your applications. So, my suggestion is not to mix different business entities in a single cache. Create your data schema as you would do for a relational database.

The CREATE TABLE creates a new Ignite cache and defines an SQL table on top of it. The cache stores the data in the form of key-value pairs while the table allows processing this data with SQL queries. So the table is just a logic thing on top of the cache.

Hope this helps.


Denis

> On Jan 15, 2018, at 10:43 PM, Shravya Nethula <[hidden email]> wrote:
>
> Hi Andrey,
>
> Thank you for the information.
>
> I want to create some tables using cache.query(Create Table ...) statement.
> Is there any way in which I can group some of my tables in one cache? Is
> there any hierarchy in organizing the caches like a super cache holding some
> sub caches?
>
> Regards,
> Shravya Nethula.
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Shravya Nethula Shravya Nethula
Reply | Threaded
Open this post in threaded view
|

Re: Purpose of cache in cache.query(Create Table ...) statement

Hi Denis,

Thank you for the information.

Regards,
Shravya.



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