Search code examples
gemfireoqlspring-data-gemfire

Can GemFire OQL query be done on all the child-regions of a parent-region, in a single query


I need to make a hierarchy of regions like following, as usually I query by country and type. I put all data in country level regions. Sometimes I query across countries in NAM_Type1 and sometimes Global.

Global_Type1
-> NAM_Type1
-->  USA
-->  Mexico
-> APAC_Type1
-->  Japan
-->  HongKong

Is there a way I can query parent-region, without querying multiple times on individual countries?

Can indexes be made at parent level?

I use GemFire 7.0 with spring-gemfire for connection.


Solution

  • @Ashish

    If I understand your problem correctly, the quick answer is no.

    It seems you want to use a parent (e.g. NAM_Type1) Region to refer to, or rather query across data contained in multiple Sub-Regions of the parent (e.g. USA, MEXICO, etc) and "aggregate" the results from all the Sub-Regions???

    For example, assuming your Sub-Regions contain Customer objects...

    public class Customer ... {
      private String firstName;
      private String lastName;
      private boolean active;
      ...
    }
    

    Then...

    SELECT * FROM /NAM_Type1 nam WHERE nam.active = 'true';
    

    This OQL query is broken as their is no reference between the parent Region (e.g. NAM_Type1) and the entries in the Sub-Regions (e.g. USA, etc). If you are using the "parent" Regions just for a namespace hierarchy, then they contain no data at all.

    I am wondering what the need is to have "Sub-Regions"? A Sub-Region is not viewed any differently than a top-level Region when it comes to data access (particularly with OQL/querying).

    By using Sub-Regions, it implies you are using and are limited to using REPLICATE Regions as mentioned in the GemFire User Guide here (http://gemfire.docs.pivotal.io/latest/userguide/index.html#basic_config/data_regions/managing_data_regions.html). For this reason, amongst others, the GemFire team generally discourages the use of Sub-Regions, especially where the transactional data might change a lot.

    In general, you want to use PARTITION Regions for transactional data and REPLICATE Regions mostly for smaller data sets and usually reference/lookup type data.

    So, in your case, you might achieve similar behavior by...

    1. Using PARTITION Regions...
    2. Configured and created on different Servers...
    3. Organized into different server groups based the hierarchical organization you stated above.

    Then, you can target and run a GemFire Function on Servers in specific server groups hosting the data for the demographic area(s) of interest to run an OQL Query on the local data set of the Region. The Function will aggregate and then return the results.

    There are different ways to organize and partition the data, even using custom "PartitionResolvers", etc, or to target Functions, and so on.

    By using PARTITION Regions you can still achieve HA (redundancy) using the "copies" attribute on (which corresponds to GemFire's PartitionAttributes.redundantCopies property). You have the option to "co-locate" data making equi-join Queries possible/optimal.

    DISCLAIMER: not being intimately familiar with your use case(s) and requirement(s), my suggestions may or may not work for your situation, but usually the effects of Sub-Regions can be achieved more elegantly and effectively using GemFire's other features. If anything, maybe this will give you some ideas.

    Hope this helps!

    -John