You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Aolean <se...@gmail.com> on 2015/12/20 20:32:08 UTC

Queries including sub-classes

Hello,

I'm trying to define the best design for the following situation:

- I have an abstract class File representing a description of a file (with
attributes like name, machine on which it is hosted, path, ...)
- I have several sub-classes extending File (Image, Doc, CSV, Excel, ...)
with more details.

I want to push those descriptions in the cache, and being able to do queries
on them:
- Searching all files with a given name
- Searching all images with a given name, ...

Declaring a sql search like this:
SqlQuery<Integer, File > sql = new SqlQuery(File.class, "name = 'Test'");

will not give the desired result because only classes exactly matching
"File" will be returned.
Is there a way to indicate that we want to include sub-classes as well in
the query ?

I didn't find any example corresponding to this situation so far.

Thanks



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Queries-including-sub-classes-tp2259.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Queries including sub-classes

Posted by Denis Magda <dm...@gridgain.com>.
Hi,

However please be careful with scan queries in a sense that they are doing
full scans. So if your data set is significant then it can effect the
performance.

Regards,
Denis



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Queries-including-sub-classes-tp2259p2272.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Queries including sub-classes

Posted by Aolean <se...@gmail.com>.
Hi Denis,

Thanks for your answer,

Actually using SQL is so far not a strong requirement on my side and the
scan version works fine so I'm just using this :

But yes it would be good to be able to use the flexibility and indexing
capabilities of SQL-based queries in this case !

Thanks,

Sébastien



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Queries-including-sub-classes-tp2259p2269.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Queries including sub-classes

Posted by Denis Magda <dm...@gridgain.com>.
Hi,

Presently in SQL queries you can't use a predecessor's name to retrieve 
data for all its subclasses stored in a cache.
The reason is that for every type, registered with CacheConfiguration, 
Ignite creates a corresponding flat H2 type descriptor that doesn't 
store hierarchy information.

The only way to support your use case is to list all the types you want 
to choose from explicitly in a query.

As an example if you want to get all text files and images named 'test' 
you can use the query below

SqlFieldsQuery query =new SqlFieldsQuery(
     "SELECT _val FROM Image WHERE name = 'test' " +
     "UNION " +
     "SELECT _val FROM Text WHERE name = 'test'");

List<List<?>> result = cache.query(query).getAll();

for (List val : result)
     for (Object file : val)
         System.out.println("File: " + file);



Community, what do you think if we introduce a kind of types aliasing 
that will support use cases like this?

Regards,
Denis

On 12/20/2015 10:32 PM, Aolean wrote:
> Hello,
>
> I'm trying to define the best design for the following situation:
>
> - I have an abstract class File representing a description of a file (with
> attributes like name, machine on which it is hosted, path, ...)
> - I have several sub-classes extending File (Image, Doc, CSV, Excel, ...)
> with more details.
>
> I want to push those descriptions in the cache, and being able to do queries
> on them:
> - Searching all files with a given name
> - Searching all images with a given name, ...
>
> Declaring a sql search like this:
> SqlQuery<Integer, File > sql = new SqlQuery(File.class, "name = 'Test'");
>
> will not give the desired result because only classes exactly matching
> "File" will be returned.
> Is there a way to indicate that we want to include sub-classes as well in
> the query ?
>
> I didn't find any example corresponding to this situation so far.
>
> Thanks
>
>
>
> --
> View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Queries-including-sub-classes-tp2259.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.