This example demonstrates simple queries on a region.
In this example, two servers host a single partitioned region with entries
that represent employee information.
The example does queries through the API and presents example queries
to be invoked through the gfsh command-line interface.
This example assumes that Java and Geode are installed.
-
Set directory
geode-examples/queriesto be the current working directory. Each step in this example specifies paths relative to that directory. -
Build the example (with the
EmployeeDataclass)$ ../gradlew build -
Run a script that starts a locator and two servers, and then creates the
example-regionregion.$ ../gradlew start
-
Run the example to populate
example-regionwith employee information, print out the region information, and then programmatically invoke three queries, printing the results of each query.$ ../gradlew run
gfsh can also be used to issue queries.
-
If you have not already installed Geode, the build step will have installed a
gfshexecutable for you at a path relative to the current working directory within a versioned directory:../build/apache-geode-<version>/bin/gfshYou can use this relative path to invoke gfsh by substituting the appropriate
<version>. -
Start
gfshand connect to the cluster:$ gfsh ... gfsh>connect --locator=127.0.0.1[10334] -
The quantity of entries may be observed with
gfsh:gfsh>describe region --name=example-regionHere are some
gfshqueries to try on theexample-regionregion.Query for all entries in the region:
gfsh>query --query="select * from /example-region"Query for the
emailfield of all entries in the region:gfsh>query --query="SELECT x.email FROM /example-region x"Query for all entries that have a
lastNamefield that starts with the letter 'C':gfsh>query --query="SELECT DISTINCT * FROM /example-region x WHERE x.lastName.startsWith('C')"Exit gfsh:
gfsh>exit
-
Shut down the cluster:
$ ../gradlew stop -
If desired, clean up the generated directories containing logs:
$ ../gradlew cleanServer