Igniters,

Currently Ignite Key/Value API allows to have both Key and Value fields with
the same name. Use of SQL DML to update such an entry will update only the
key field, leaving the value field unchanged. Seems that it's a bit
inconvenient for the mixed K/V and SQL API apps.

This is a proposal to add enhancements to Cache and SQL API to address this
inconvenience.

Proposal to API change:

*Cache API*: add new method /setKeyValueFields(keyValueFields: Set<String>):
QueryEntity/ to class /QueryEntity/

- The method marks Cache API Key and Value fields that SQL API must
initialize (on INSERT/MERGE) and update (on UPDATE/MERGE) together.
- It is still possible to use Cache API to initialize the fields marked with
/setKeyValueFields/ to different values. SQL SELECT statement returns value
of such a field from the Key entity.
- The method accepts a set of field names and returns the declaring class
instance for chaining.
- The method throws /ArgumentException/ if the Key and Value types are
available and the field types are different within the Key and Value
entities.

*SQL API*: add /KEY_VALUE_FIELDS/ parameter to /CREATE TABLE/ statement's
additional parameters list.
- The parameter's value is a space-separated list of field names with the
semantics equivalent to that of the /setKeyValueFields/ method described
above.
- The parameter can be specified only if both the /KEY_TYPE/ and
/VALUE_TYPE/ parameters are specified.

Let's take a look on the following example:

Consider a business domain entity Person { id: int, passportNo: String,
name: String }

Suppose an application development team decided to map the Person entity to
Ignite data model as:

PersonKey { id: int, passportNo: String }
Person { passportNo: String, name: String }

Use Case - inserting into Key and Value fields with same name initializes
both fields in QueryEntity-Defined Cache

- GIVEN a Person cache from the example data model configured like this in
Ignite:

new CacheConfiguration<PersonKey, Person>("CACHE")
            .setQueryEntities(Collections.singleton(
                new QueryEntity(PersonKey.class, Person.class)
                    .addQueryField("id", int.class.getName(), null)
                    .addQueryField("passportNo", String.class.getName(),
null)
                    .addQueryField("name", String.class.getName(), null)
                    .setKeyFields(Collections.singleton("id"))
                    .setKeyValueFields(Collections.singleton("passportNo"))
            ));

- AND an entry is added to the cache with this SQL statement:

 INSERT INTO CACHE.Person (ID, PASSPORTNO, NAME) VALUES (1, '11111',
'Name1') 

- WHEN the user gets the entity using Cache API:

final PersonKey K = new PersonKey(1, "11111");
Person v = cache.get(K); 

- THEN the *passportNo* field is initialized to the same value within the
key and value entities:

assertEquals(K.passportNo, v.passportNo);


Other use cases with inserting and querying could be found at [1].

[1] https://issues.apache.org/jira/browse/IGNITE-12807

WDYT?
Will it be a useful feature for the Apache Ignite?




--
Sent from: http://apache-ignite-developers.2346864.n4.nabble.com/

Reply via email to