After Lindorm Ganos is activated, you can call Ganos API operations to develop applications.
Procedure
Download the sample code package lindorm-ganos-sample.
Go to the lindorm-sample directory after the package is downloaded and decompressed, and execute the following statement:
mvn install -Dmaven.test.skip=true -s ../settings.xmlAfter the compilation is successful,
lindorm-sample-1.0.0.jaris generated in the target directory.Understand the sample code. In the following example, automatic identification system (AIS) data is used to show how to write and query trajectory data.
Main: the entry point for the sample program.
Specify operations and parameters in a JSON file. For more information, see the sample JSON file sample_template.json.
Writer: writes data to Lindorm Ganos. Two write modes are supported:
WRITER: uses a single thread to write data. Connect to Lindorm Ganos, define a schema, create a spatiotemporal index table, read the sample data, and then write the sample data to Lindorm Ganos.
PWRITER: uses multiple threads to write data. Connect to Lindorm Ganos, define a schema, and then create a spatiotemporal index table. Specify the number of threads. Each thread generates random N AIS points in the specified range and writes the AIS points to the table that is created. You must specify parameters in a JSON file. For more information, see the sample JSON file write_template.json.
Reader: the query interface that is used to query AIS data that is written by the writer. Two query modes are supported:
READER: In this query mode, you can run the queries that contain fixed parameters. The queries include attribute queries, spatial queries, and spatiotemporal queries.
UDFQUERY: In this query mode, you can specify parameters in a JSON file and specify query conditions to run a spatial query, spatiotemporal query, or attribute query. For more information, see the sample JSON file query_template.json.
Use the sample code. In the following example, the
zk_addressparameter is set to the endpoint that is used for the ApsaraDB for HBase API for Java to connect to the wide table engine LindormTable.Write data
In the sample_template.json file, set the parameters that are required to write data.
{ "operation" : "WRITER", "zk_address" : $your_zk_address, "catalog" : "example", "schema" : "ship" }Execute the following sample statement to write data:
java -jar lindorm-sample-1.0.0.jar path_to_sample/sample_template.jsonBy default, four index tables (indexes on the id, z2, z3, and attr columns) whose schema is ship are created. If you want to create a specified index table, perform the steps that are described in Create an index table.
Query data
Set query parameters in the sample_template.json file. Use the default query range in the sample code.
{ "operation" : "READER", "zk_address" : $your_zk_address, "catalog" : "example", "schema" : "ship" }You can also set the filter_string parameter to specify a query range.
{ "operation" : "READER", "filter_string" : "bbox(geom, 20, 20, 40, 40)" "zk_address" : $your_zk_address, "catalog" : "example", "schema" : "ship" }Execute the following sample statement to query data:
java -jar lindorm-sample-1.0.0.jar path_to_sample/sample_template.jsonWrite data in parallel
Use PWRITER.{ "operation" : "PWRITER", "zk_address" : $your_zk_address, "catalog" : "example", "schema" : "ship", "write_template_file" : "src_root/src/main/java/com/aliyun/apsaradb/lindorm/ganos/sample/write_template.json" }Run a custom query
Use UDFQUERY.{ "operation" : "UDFQUERY", "zk_address" : $your_zk_address, "catalog" : "example", "schema" : "ship", "query_template_file" : "src_root/src/main/java/com/aliyun/apsaradb/lindorm/ganos/sample/query_template.json" }