You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ignite.apache.org by Denis Magda <dm...@apache.org> on 2017/05/11 23:14:22 UTC

SQL: setting key field name for types registered via CacheConfiguration.setIndexedTypes

Guys,

Let’s suppose there is a cache that stores entries like that:

* key - int
* value - custom object which fields are annotated by @QuerySqlField

Before 2.0 if I wanted to refer to the key in an SQL query I had to use “_key” keyword. In 2.0 this is no longer the requirement. Any name can be used in the condition it’s set via QueryEntity.setKeyFieldName(keyName).

This concept works perfectly fine if both key's and value's types are configured using QueryEntities directly. But what can I do if the value is annotated with @QuerySqlField as in the example above and passed to SQL engine via CacheConfiguration.setIndexedTypes(…) method? How can I set QueryEntity.setKeyFieldName()?

Looks like the only workable way is this one:
- register key and value types via CacheConfiguration.setIndexedTypes(…)
- find the QueryEntity corresponding to the just registered types in a collection of CacheConfiguration.getQueryEntities()
- call QueryEntity.setKeyFieldName(keyName) for the entity of interest.

Basically, this is a workaround but not a user friendly approach. Is there any other way to achieve this?

In the meanwhile, what if we add QueryEntity(Class keyType, Class valueType) that will do totally the same things that CacheConfiguration.setIndexedTypes(…) with the only difference that right after that the user will be able to call QueryEntity.setKeyFieldName(keyName)?

—
Denis


Re: SQL: setting key field name for types registered via CacheConfiguration.setIndexedTypes

Posted by Vladimir Ozerov <vo...@gridgain.com>.
Denis,

This is rather simple change. Hopefully we will get it done by 2.2 release.

On Fri, May 12, 2017 at 9:16 PM, Denis Magda <dm...@apache.org> wrote:

> Here is a ticket:
> https://issues.apache.org/jira/browse/IGNITE-5211
>
> Vovan, can it be done in 2.1?
>
> —
> Denis
>
> > On May 11, 2017, at 4:14 PM, Denis Magda <dm...@apache.org> wrote:
> >
> > Guys,
> >
> > Let’s suppose there is a cache that stores entries like that:
> >
> > * key - int
> > * value - custom object which fields are annotated by @QuerySqlField
> >
> > Before 2.0 if I wanted to refer to the key in an SQL query I had to use
> “_key” keyword. In 2.0 this is no longer the requirement. Any name can be
> used in the condition it’s set via QueryEntity.setKeyFieldName(keyName).
> >
> > This concept works perfectly fine if both key's and value's types are
> configured using QueryEntities directly. But what can I do if the value is
> annotated with @QuerySqlField as in the example above and passed to SQL
> engine via CacheConfiguration.setIndexedTypes(…) method? How can I set
> QueryEntity.setKeyFieldName()?
> >
> > Looks like the only workable way is this one:
> > - register key and value types via CacheConfiguration.setIndexedTypes(…)
> > - find the QueryEntity corresponding to the just registered types in a
> collection of CacheConfiguration.getQueryEntities()
> > - call QueryEntity.setKeyFieldName(keyName) for the entity of interest.
> >
> > Basically, this is a workaround but not a user friendly approach. Is
> there any other way to achieve this?
> >
> > In the meanwhile, what if we add QueryEntity(Class keyType, Class
> valueType) that will do totally the same things that CacheConfiguration.setIndexedTypes(…)
> with the only difference that right after that the user will be able to
> call QueryEntity.setKeyFieldName(keyName)?
> >
> > —
> > Denis
> >
>
>

Re: SQL: setting key field name for types registered via CacheConfiguration.setIndexedTypes

Posted by Denis Magda <dm...@apache.org>.
Here is a ticket:
https://issues.apache.org/jira/browse/IGNITE-5211

Vovan, can it be done in 2.1?

—
Denis

> On May 11, 2017, at 4:14 PM, Denis Magda <dm...@apache.org> wrote:
> 
> Guys,
> 
> Let’s suppose there is a cache that stores entries like that:
> 
> * key - int
> * value - custom object which fields are annotated by @QuerySqlField
> 
> Before 2.0 if I wanted to refer to the key in an SQL query I had to use “_key” keyword. In 2.0 this is no longer the requirement. Any name can be used in the condition it’s set via QueryEntity.setKeyFieldName(keyName).
> 
> This concept works perfectly fine if both key's and value's types are configured using QueryEntities directly. But what can I do if the value is annotated with @QuerySqlField as in the example above and passed to SQL engine via CacheConfiguration.setIndexedTypes(…) method? How can I set QueryEntity.setKeyFieldName()?
> 
> Looks like the only workable way is this one:
> - register key and value types via CacheConfiguration.setIndexedTypes(…)
> - find the QueryEntity corresponding to the just registered types in a collection of CacheConfiguration.getQueryEntities()
> - call QueryEntity.setKeyFieldName(keyName) for the entity of interest.
> 
> Basically, this is a workaround but not a user friendly approach. Is there any other way to achieve this?
> 
> In the meanwhile, what if we add QueryEntity(Class keyType, Class valueType) that will do totally the same things that CacheConfiguration.setIndexedTypes(…) with the only difference that right after that the user will be able to call QueryEntity.setKeyFieldName(keyName)?
> 
> —
> Denis
>