All Products
Search
Document Center

Lindorm:Create an index table

Last Updated:Mar 20, 2024

Lindorm Ganos provides multiple built-in spatial indexes. You need only to insert -temporal data at the frontend and specify the index that you want to create. You do not need to design or build key-value pairs for your HBase tables. Before you insert data into an index table, specify the schema of the index table.

Lindorm Ganos provides five types of indexes to meet your requirements in different query scenarios. You can create one or more types of indexes based on your business requirements. For example, if only range queries exist in your business scenarios, you need to create only Z2 indexes.

ID indexes

ID indexes are suitable for scenarios in which feature IDs (FIDs) of geometries are used to query data. The FID of a geometry must be unique.

Z2 and XZ2 indexes

Z2 and XZ2 indexes are suitable for spatial queries, such as geo-fence queries and range queries. Z2 indexes are used to query point objects, and XZ2 indexes are used to query line objects and polygon objects.

Z3, XZ3, and XZ2T indexes

Z3, XZ3, and XZ2T indexes are suitable for spatio-temporal queries, such as querying historical trajectory data in a specific spatial range and time period. Z3 indexes are used to query point objects. XZ3 and XZ2T indexes are used to query line objects and polygon objects. For queries based on the trajectory line model, XZ2T indexes are more effective in improving query efficiency.

XYZ indexes

XYZ indexes are three-dimensional indexes. The dimensions are longitude, latitude, and elevation information. XYZ indexes are used to query only point objects.

Attribute indexes

Attribute indexes are used to query other attributes.

Procedure of creating an index

Perform the following steps to create an index:

  1. Specify SimpleFeatureType that indicates a spatial or spatio-temporal data type.

    1. Specify the name of the schema. A schema refers to an index table.

    2. Specify the content of the schema. The content includes definitions of columns such as the attribute, geometry, and date columns.

    3. You can also specify other settings, including:

      1. Specify a compression method.

      2. Specify whether to use the tiny well-known binary (TWKB) format.

      3. Specifies parameters to create an index for a column.

  2. Create objects based on the specified spatial or spatio-temporal data type.

Example of creating an index

You can create one or more types of indexes based on your business requirements. For example, if only range queries exist in your business scenarios, you need to create only Z2 indexes. By default, the five types of indexes are created. This way, excellent query performance can be provided for all query scenarios but more storage space is occupied. If you want to reduce storage usage, you can create one or more types of indexes that are suitable for your query scenario. Lindorm Ganos provides built-in hints. You can use the hints to specify indexes when you specify SimpleFeatureType. You can use the following syntax:

// sft specifies an instance object of SimpleFeatureType.
sft.getUserData().put("geomesa.indices.enabled", "{index_name}:{col1}:{col2}:...,{index_name}:{col}");
  • Valid values of index_name are id, attr, z2, z3, xz2, xz3, and xyz.

  • The col parameter specifies the columns that are specified in SimpleFeatureType.

  • You can create one or more indexes. Separate indexes with commas (,).

  • If you want to add multiple columns to an index, separate the index and column names with colons (:).

In the following example, Z3 and attribute indexes are created. The Z3 index is created on the start and dtg columns. The Z3 index is also created on the end and dtg columns. The attribute index is created on the name and dtg columns.

sft.getUserData().put("geomesa.indices.enabled", "z3:start:dtg,z3:end:dtg,attr:name:dtg");

Spatio-temporal secondary index

Lindorm Ganos provides spatio-temporal secondary indexes based on the native secondary indexes that are supported by Lindorm. A conventional secondary index table is built on an attribute column of the primary table. A secondary index that is built on a serialized spatio-temporal attribute column is ineffective. To make a secondary index take effect, add an encoded spatio-temporal data column to the primary table before you create the secondary index on the encoded spatio-temporal data column. The encoded spatio-temporal data column stores the encoded values of the space-filling curves of spatio-temporal attributes. The following figure shows an example of the storage structure of a secondary index.

image

In this example, a spatio-temporal index key column named z3 is created for the primary table whose ID is used as RowKey, and a secondary index table is created on the z3 spatio-temporal index key column. By default, no redundant columns exist in the secondary index table. Redundant columns will be supported in future versions.

Example for creating a spatio-temporal secondary index

Specify the type of the spatio-temporal secondary index that you want to create when you create a primary table

Specify the userData parameter for the specified SimpleFeatureType (sft in the following example).

// sft specifies an instance object of SimpleFeatureType.
sft.getUserData().put("geomesa.secondary.enabled","true");
sft.getUserData().put("geomesa.primary.index","id");
sft.getUserData().put("geomesa.indices.enabled","id,z3");

After you call the createSchema operation to create a table, the primary table and the secondary index table are generated. The preceding figure shows the storage structure of the primary table and the secondary index table.

Create a secondary index on an existing primary table

Call the LindormDataStore.createIndex method to create a secondary index on the primary table that is created and whose geomesa.secondary.enabled parameter is set to true.

String index = "attr:dtg";
lindormDS.createIndex(schemaName, index);

Take note that you cannot create an index table while synchronizing historical data.