You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Mikael <mi...@telia.com> on 2018/01/10 12:20:35 UTC

Index on a Long ?

Hi!

How do I create an index on a cache key that is a Long, I can't use 
annotations and the QueryEntity look like it requires a class and field 
to set an index ?

Mikael



Re: Index on a Long ?

Posted by Andrey Mashenkov <an...@gmail.com>.
Hi Michael,

There is no need to create index on keys as ignite key-value storage
already has naturally index for it underneath.
It should be enough to register indexing types [1].

Would you please clarify the use case if there is any other questions?


[1]
https://apacheignite.readme.io/v1.8/docs/indexes#section-registering-indexed-types

On Wed, Jan 10, 2018 at 3:20 PM, Mikael <mi...@telia.com> wrote:

> Hi!
>
> How do I create an index on a cache key that is a Long, I can't use
> annotations and the QueryEntity look like it requires a class and field to
> set an index ?
>
> Mikael
>
>
>


-- 
Best regards,
Andrey V. Mashenkov

Re: Index on a Long ?

Posted by "slava.koptilin" <sl...@gmail.com>.
Hi Mikael,

You can specify indexed types via CacheConfiguration#setIndexedTypes()
method.
For instance:
CacheConfiguration<Long, Person> ccfg = new CacheConfiguration<>();
ccfg.setIndexedTypes(Long.class, Person.class);

Another possible way is DDL statement:
// Create table based on PARTITIONED template with one backup.
cache.query(new SqlFieldsQuery(
    "CREATE TABLE person (id LONG, name VARCHAR, city_id LONG, PRIMARY KEY
(id, city_id)) " +
        "WITH \"backups=1, affinity_key=city_id\"")).getAll();
// Create an index.
cache.query(new SqlFieldsQuery("CREATE INDEX on Person
(city_id)")).getAll();

[1]
https://apacheignite-sql.readme.io/docs/schema-and-indexes#section-registering-indexed-types
[2] https://apacheignite-sql.readme.io/docs/create-index
[3]
https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/sql/SqlDdlExample.java

Thanks!



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