Index on a Long ?

classic Classic list List threaded Threaded
3 messages Options
Mikael Mikael
Reply | Threaded
Open this post in threaded view
|

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


slava.koptilin slava.koptilin
Reply | Threaded
Open this post in threaded view
|

Re: Index on a Long ?

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/
Andrew Mashenkov Andrew Mashenkov
Reply | Threaded
Open this post in threaded view
|

Re: Index on a Long ?

In reply to this post by Mikael
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?



On Wed, Jan 10, 2018 at 3:20 PM, Mikael <[hidden email]> 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
Regards,
Andrew.