Querying the Space

  GigaSpaces 5.X

Documentation Home
Quick Start Guide
Release Notes

Previous release

  Search Here
Searching GigaSpaces Platform 5.X Documentation

                                               

Summary: An extension to the JavaSpaces API which allows object matching by SQL syntax or regular expression.

This page is specific to:
GigaSpaces 5.x

If you're interested in another version, click it below:
GigaSpaces 6.0
[GigaSpaces 6.5]

Overview

JavaSpaces – the underlying technology of GigaSpaces XAP – provides the ability to search for Entries using exact matching. In some cases there is a need to query Entries with attribute values larger or smaller than a specific value. There are also cases where there is a need to locate Entries with string attributes that match a regular expression.

The GigaSpaces Space API provides the ability to query space Entries using the SELECT SQL syntax, as well as Java regular expressions. To do this, construct a SQLQuery Entry com.j_spaces.core.client.SQLQuery for all SQL based queries. Alternatively, you can construct a com.j_spaces.core.client.RegExQuery Entry for every regular expression that matches the relevant values and uses the read, take, notify, readMultiple, takeMultiple operations as usual.

  • For more details on the SQL syntax, refer to:
  • For more details on Java regular expression syntax, see Javadoc.
  • For a more precise description of the behavior of regular expression constructs, refer to: Mastering Regular Expressions, 2nd Edition, Jeffrey E. F. Friedl, O'Reilly and Associates, 2002.

JavaSpaces Query Interface

The query interface extends the net.jini.core.entry.Entry interface and is the base interface for the SQLquery and the RegExquery classes. Future query syntaxes will implement this interface.

Methods

Return Value Method
void setClassName(String className)
Sets the template class name.
void setquery(String query)
Sets the query statement.
void setTemplate(Entry entry)
Sets the template.

SQLQuery in JavaSpaces

The SQLQuery class is used to query the space using the SQL like syntax. The query statement should only include the WHERE clause.

For more details, refer to the SQLQuery in JavaSpaces section.

Regular Expression Queries in JavaSpaces

The RegExQuery class is used to query the space using the Java Regular Expression syntax.

For more details, refer to the Regular Expression Queries in JavaSpaces section.

Indexing for JavaSpaces Queries

An Entry's attributes can be indexed using explicit or implicit indexing (see Indexing). By default, when class attributes are indexed, a hash-based index is maintained. The hash-based index is used for the regular JavaSpaces matching (i.e., "equals") and accelerates the read () and take () operations. In order to accelerate the read () and take () operations that use SQLQuery with greater than/less than operations, turn on the btree index.

To turn on the btree index, modify the space configuration file as follows (note the asterisk):

<extended-match>
     <enabled-classes>*</enabled-classes>
     <regular-expressions-cache-size>300</regular-expressions-cache-size>
</extended-match>
By default, the btree index is not maintained for indexed class attributes. Leaving the btree index turned on impacts the write performance.

The <enabled-classes>*</enabled-classes> can be replaced with a list of class names separated with commas that you want to index using the btree index
For example:

<enabled-classes>classA,classB</enabled-classes>

The Matching Algorithm

When a read, take, readMultiple, or takeMultiple call is performed, a template is used to locate matching Entries inside the space. The template might have multiple field values – some might include values and some might not (null field values). The fields that do not include values are ignored during the matching process. In addition, some class fields might be indexed and some might not be indexed.

When multiple class fields are indexed, the space looks for the field value index that includes the smallest amount of matching Entries with the corresponding template field value as the index key.

The smallest set of Entries is the list of Entries to perform the matching against (candidates). Once the candidates Entries list has been constructed, it is scanned to locate Entries that fully match the given template – i.e. all non-null template fields match the corresponding Entry fields.

Class fields that are not indexed are not used to construct the candidates list.

More in this Section

Query Complex Entry Attribute – Performing queries on complex Entry attributes using the Comparable interface.
Custom Query Pattern – The purpose of the custom query pattern is to extend the existing query capabilities by enabling users to write code and execute it as part of the query path.


Wiki Content Tree


Your Feedback Needed!

We need your help to improve this wiki site. If you have any suggestions or corrections, write to us at techw@gigaspaces.com. Please provide a link to the wiki page you are referring to.

Labels