0

I am fairly new to Ignite and trying it out. My usecase is I have a model that needs to be cached/persisted. It's not a traditional pojo model moreover i want to keep the storage and the model decoupled. So i cannot use it in the traditional sense with annotating the appropriate keys/indexes in the pojo. And being able to execute a query on the cached data is needed.

So far based on whatever I've read and my usecase, the only option's I see are:

  1. Go the complete SQL route i.e. CREATE TABLE, INSERT, REMOVE, SELECT via jdbc using Batch Exec.

  2. Store it as a BinaryObject i.e.

IgniteCache<BinaryObject, BinaryObject>

But with this, I am not sure if I can get querying support. Since it would get stored as a blob/byte[].

So what I am looking for is, are there other options that I might have missed out? For #1, is there a way to use jdbc/SQL and locking, given I am using atomicity=transactional.

For #2, is there a way I can add querying support to it. I looked at https://github.com/dmagda/ignite_world_demo/blob/master/src/main/java/demo/keyvalue/KeyValueBinaryDataProcessing.java but it does not cover querying.

Update for folks who might run into this.

Tried binary approach and it works. The reference link does use a pojo (not exactly what i wanted). But on looking further, the main point was to set a valueType to the QueryEntity and it need not be a class name, just mapping value to reference back during object creation during put and similarly during query.

queryEntity.setValueType("employee");

//this can be now referenced while creating an object
ignite.binary().builder("employee");

// similarly used while querying
SqlFieldsQuery sqlQuery = new SqlFieldsQuery("select * from employee");
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Victor
  • 1,207
  • 2
  • 13
  • 21

2 Answers2

1

You can store it as BinaryObject, and you can have limited querying support by specifying some fields to map to SQL via QueryEntities.

Then, you can get the whole key/value by doing queries like

SELECT _key, _val FROM pojo WHERE name = ?;

Please note that you will need to use Native SQL API, JDBC won't do.

alamar
  • 18,729
  • 4
  • 64
  • 97
  • Tried this approach. Updated the original post with details. The query is failing with BinaryObject. Am i missing something? – Victor Nov 18 '19 at 23:43
  • 1
    There was some issue with my code, i've updated it and it works ok. Thanks. – Victor Nov 21 '19 at 01:35
0

Most likely you need to define a one-to-many relationship table with affinity colocation by TestPojoId. Take a look at the sample.

ScanQueries could be used without a schema definition but will require full object deserialization.

Alexandr Shapkin
  • 2,350
  • 1
  • 6
  • 10
  • ScanQuery with `keepBinary` probably won't. – alamar Nov 18 '19 at 10:43
  • one-to-many? Why, not sure i get it. This would be one unique id per row/record. Tried using scan with the updated code. But it failed with "class org.apache.ignite.IgniteCheckedException: Query execution failed: GridCacheQueryBean". – Victor Nov 19 '19 at 00:48