This topic describes how to use ApsaraDB for HBase Ganos (HBase Ganos) to write, query, and delete data.

Sample code

  1. Click hbase-ganos-sample to download the sample code.

    After you download and decompress the sample code package, modify the project dependencies in the pom.xml file. For more information, see the "Dependencies" section in this topic.

  2. Understand the sample code.
    1. The trajectory-sample module
      Automatic identification system (AIS) data is used as the sample data to demonstrate how to write and query trajectory data.
      • Main: It is the entry point for the sample program.
      • Writer: It is used to write data to ApsaraDB for HBase databases. The entire procedure consists of the following steps: connect to HBase Ganos, create a Schema object that is used as a spatio-temporal index table, read sample data, and then write the sample data to the spatio-temporal index table.
      • Reader: It is a common query interface. The sample code provides examples of attribute queries such as equal-value queries, prefix queries, and suffix queries, spatial data queries, and spatio-temporal data queries.
    2. The spark-sample module
      AIS data is used as the sample data to demonstrate how to write trajectory data and how to use Apache Spark to query and analyze trajectory data.
      • Writer: It is used to write data to ApsaraDB for HBase databases. The entire procedure consists of the following steps: connect to HBase Ganos, create a Schema object that is used as a spatio-temporal index table, read sample data, and then write the sample data to the spatio-temporal index table.
      • SparkDemo: It is used to read data from HBase Ganos, convert the data to Spark DataFrames, and then perform operations such as spatial data queries by using Spark SQL.

Dependencies

You can use the GeoMesa client or the HBase Ganos client. The HBase Ganos client provides more features than the GeoMesa client.

GeoMesa client

HBase Ganos is compatible with the open source GeoMesa client. If you do not need the specific features of HBase Ganos, you can use the GeoMesa client.

Important The GeoMesa client can be used only to access HBase Ganos of HBase 1.x.
<properties>
       <!-- Note: Specify the version of the ApsaraDB for HBase client -->
       <alihbase.version>1.3.1</alihbase.version>
</properties>

<dependency>
        <groupId>org.locationtech.geomesa</groupId>
        <artifactId>geomesa-hbase-datastore_2.11</artifactId>
        <version>2.2.1</version>
        <exclusions>
            <exclusion>
                <groupId>com.google.protobuf</groupId>
                <artifactId>protobuf-java</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- Dependencies for the ApsaraDB for HBase client-->
      <dependency>
      <groupId>com.aliyun.hbase</groupId>
      <artifactId>alihbase-client</artifactId>
      <version>${alihbase.version}</version>
      <exclusions>
        <exclusion>
          <artifactId>com.google.guava</artifactId>
          <groupId>guava</groupId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>com.aliyun.hbase</groupId>
      <artifactId>alihbase-server</artifactId>
      <version>${alihbase.version}</version>
    </dependency>
    <dependency>
      <groupId>com.aliyun.hbase</groupId>
      <artifactId>alihbase-common</artifactId>
      <version>${alihbase.version}</version>
    </dependency>
    <dependency>
      <groupId>com.aliyun.hbase</groupId>
      <artifactId>alihbase-protocol</artifactId>
      <version>${alihbase.version}</version>
    </dependency>

HBase Ganos client

  • HBase 1.x
    Important The HBase Ganos dependencies for HBase 1.x have not been released to the maven library. Click ganos-hbase-distributed-runtime_2.11-2.2.1-2.1.0.jar to download the package and configure the following dependencies.
    <properties>
         <!-- Note: Specify the version of the ApsaraDB for HBase client -->
         <alihbase.version>1.3.1</alihbase.version>
    </properties>
    
    <dependency>
            <groupId>com.aliyun.tst.ganos</groupId>
            <artifactId>ganos-geomesa-hbase15</artifactId>
            <version>2.0.0</version>
            <scope>system</scope>
            <systemPath>/ganos-jar-path</systemPath>
          </dependency>
          <!-- Dependencies for the ApsaraDB for HBase client-->
          <dependency>
          <groupId>com.aliyun.hbase</groupId>
          <artifactId>alihbase-client</artifactId>
          <version>${alihbase.version}</version>
          <exclusions>
            <exclusion>
              <artifactId>com.google.guava</artifactId>
              <groupId>guava</groupId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>com.aliyun.hbase</groupId>
          <artifactId>alihbase-server</artifactId>
          <version>${alihbase.version}</version>
        </dependency>
        <dependency>
          <groupId>com.aliyun.hbase</groupId>
          <artifactId>alihbase-common</artifactId>
          <version>${alihbase.version}</version>
        </dependency>
        <dependency>
          <groupId>com.aliyun.hbase</groupId>
          <artifactId>alihbase-protocol</artifactId>
          <version>${alihbase.version}</version>
        </dependency>
  • HBase 2.x
    Important The HBase Ganos dependencies for HBase 2.x have not been released to the maven library. Click ganos-hbase-distributed-runtime_2.11-2.2.1-2.5.0.jar to download the package and configure the following dependencies:
    <properties>
        <!-- Note: Specify the version of the ApsaraDB for HBase client -->
        <alihbase.version>2.0.0</alihbase.version>
    </properties>
    
    <dependency>
          <groupId>com.aliyun.tst.ganos</groupId>
          <artifactId>ganos-geomesa-hbase20</artifactId>
          <version>2.5.0</version>
          <scope>system</scope>
          <systemPath>/ganos-jar-path</systemPath>
        </dependency>
          <!-- Dependencies for the ApsaraDB for HBase client-->
          <dependency>
          <groupId>com.aliyun.hbase</groupId>
          <artifactId>alihbase-client</artifactId>
          <version>${alihbase.version}</version>
          <exclusions>
            <exclusion>
              <artifactId>com.google.guava</artifactId>
              <groupId>guava</groupId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>com.aliyun.hbase</groupId>
          <artifactId>alihbase-server</artifactId>
          <version>${alihbase.version}</version>
        </dependency>
        <dependency>
          <groupId>com.aliyun.hbase</groupId>
          <artifactId>alihbase-common</artifactId>
          <version>${alihbase.version}</version>
        </dependency>
        <dependency>
          <groupId>com.aliyun.hbase</groupId>
          <artifactId>alihbase-protocol</artifactId>
          <version>${alihbase.version}</version>
        </dependency>