You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Vladimir Ozerov <vo...@gridgain.com> on 2018/02/14 08:58:01 UTC

Re: query on BinaryObject index and table

He Rajesh,

Method CacheConfiguration.setIndexedTypes() should only be used for classes
with SQL annotations. Since you operate on binary objects, you should use
CacheConfiguration.setQueryEntity(), and define QueryEntity with all
necessary fields. Also there is a property QueryEntity.tableName which you
can use to specify concrete table name.

Vladimir.


On Mon, Jan 22, 2018 at 7:41 PM, Denis Magda <dm...@apache.org> wrote:

> The schema can be changed with ALTER TABLE ADD COLUMN command:
> https://apacheignite-sql.readme.io/docs/alter-table
>
> To my knowledge this is supported for schemas that were initially
> configured by both DDL and QueryEntity/Annotations.
>
> —
> Denis
>
>
> On Jan 22, 2018, at 5:44 AM, Ilya Kasnacheev <il...@gmail.com>
> wrote:
>
> Hello Rajesh!
>
> Table name can be specified in cache configuration's query entity. If not
> supplied, by default it is equal to value type name, e.g. BinaryObject :)
>
> Also, note that SQL tables have fixed schemas. This means you won't be
> able to add a random set of fields in BinaryObject and be able to do SQL
> queries on them all. You will have to declare all fields that you are going
> to use via SQL, either by annotations or query entity:
> see https://apacheignite-sql.readme.io/docs/schema-and-indexes
>
> To add index, you should either specify it in annotations (via index=true)
> or in query entity.
>
> Regards,
> Ilya.
>
> --
> Ilya Kasnacheev
>
> 2018-01-21 15:12 GMT+03:00 Rajesh Kishore <ra...@gmail.com>:
>
>> Hi Denis,
>>
>> This is my code:
>>
>>     CacheConfiguration<Long, BinaryObject> cacheCfg =
>>         new CacheConfiguration<>(ORG_CACHE);
>>
>>     cacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
>>     cacheCfg.setBackups(1);
>>     cacheCfg
>>         .setWriteSynchronizationMode(CacheWriteSynchronizationMode.F
>> ULL_SYNC);
>>     cacheCfg.setIndexedTypes(Long.class, BinaryObject.class);
>>
>>     IgniteCache<Long, BinaryObject> cache = ignite.getOrCreateCache(cacheC
>> fg);
>>
>>     if ( UPDATE ) {
>>       System.out.println("Populating the cache...");
>>
>>       try (IgniteDataStreamer<Long, BinaryObject> streamer =
>>           ignite.dataStreamer(ORG_CACHE)) {
>>         streamer.allowOverwrite(true);
>>         IgniteBinary binary = ignite.binary();
>>         BinaryObjectBuilder objBuilder = binary.builder(ORG_CACHE);
>>         ;
>>         for ( long i = 0; i < 100; i++ ) {
>>           streamer.addData(i,
>>               objBuilder.setField("id", i)
>>                   .setField("name", "organization-" + i).build());
>>
>>           if ( i > 0 && i % 100 == 0 )
>>             System.out.println("Done: " + i);
>>         }
>>       }
>>     }
>>
>>     IgniteCache<Long, BinaryObject> binaryCache =
>>         ignite.cache(ORG_CACHE).withKeepBinary();
>>     BinaryObject binaryPerson = binaryCache.get(54l);
>>     System.out.println("name " + binaryPerson.field("name"));
>>
>>
>> Not sure, If I am missing some context here , if I have to use sqlquery ,
>> what table name should I specify - I did not create table explicitly, do I
>> need to that?
>> How would I create the index?
>>
>> Thanks,
>> Rajesh
>>
>> On Sun, Jan 21, 2018 at 12:25 PM, Denis Magda <dm...@apache.org> wrote:
>>
>>>
>>>
>>> > On Jan 20, 2018, at 7:20 PM, Rajesh Kishore <ra...@gmail.com>
>>> wrote:
>>> >
>>> > Hi,
>>> >
>>> > I have requirement that my schema is not fixed , so I have to use the
>>> BinaryObject approach instead of fixed POJO
>>> >
>>> > I am relying on OOTB file system persistence mechanism
>>> >
>>> > My questions are:
>>> > - How can I specify the indexes on BinaryObject?
>>>
>>> https://apacheignite-sql.readme.io/docs/create-index
>>> https://apacheignite-sql.readme.io/docs/schema-and-indexes
>>>
>>> > - If I have to use sql query for retrieving objects , what table name
>>> should I specify, the one which is used for cache name does not work
>>> >
>>>
>>> Was the table and its queryable fields/indexes created with CREATE TABLE
>>> or Java annotations/QueryEntity?
>>>
>>> If the latter approach was taken then the table name corresponds to the
>>> Java type name as shown in this doc:
>>> https://apacheignite-sql.readme.io/docs/schema-and-indexes
>>>
>>> —
>>> Denis
>>>
>>> > -Rajesh
>>>
>>>
>>
>
>