You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Shravya Nethula <sh...@aline-consulting.com> on 2018/01/15 14:12:33 UTC

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/

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

Posted by Shravya Nethula <sh...@aline-consulting.com>.
Hi Andrey,

This information will definitely be useful. Thank you.

Regards,
Shravya Nethula.



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

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

Posted by Andrey Mashenkov <an...@gmail.com>.
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.

[1] https://apacheignite.readme.io/docs/cache-groups
[2] https://apacheignite-sql.readme.io/docs/create-table

On Tue, Jan 16, 2018 at 9:43 AM, Shravya Nethula <
shravya.nethula@aline-consulting.com> 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

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

Posted by Shravya Nethula <sh...@aline-consulting.com>.
Hi Denis,

Thank you for the information.

Regards,
Shravya.



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

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

Posted by Denis Magda <dm...@apache.org>.
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 <sh...@aline-consulting.com> 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/


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

Posted by Shravya Nethula <sh...@aline-consulting.com>.
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/

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

Posted by Andrey Mashenkov <an...@gmail.com>.
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 <
shravya.nethula@aline-consulting.com> 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