全部产品
Search
文档中心

云数据库 HBase:创建索引表

更新时间:Oct 21, 2021

HBase Ganos API通过索引表来存储和查询数据。用户通过调用DataStore的createSchema(SimpleFeatureType)方法来创建索引。SimpleFeatureType定义Ganos中SimpleFeature的模式,由一系列常见的属性组成。 HBase Ganos支持所有标准GeoTools属性类型,同时也扩展了一些其他属性类型。在HBase Ganos通过Geomesa提供的SimpleFeatureTypes类来创建SimpleFeatureTypes的实例:

1. 创建SimpleFeatureType

HBase Ganos API通过索引表来存储和查询数据。用户通过调用DataStore的createSchema(SimpleFeatureType)方法来创建索引。SimpleFeatureType定义Ganos中SimpleFeature的模式,由一系列常见的属性组成。 HBase Ganos支持所有标准GeoTools属性类型,同时也扩展了一些其他属性类型。在HBase Ganos通过Geomesa提供的SimpleFeatureTypes类来创建SimpleFeatureTypes的实例:

import org.locationtech.geomesa.utils.interop.SimpleFeatureTypes;

SimpleFeatureTypes.createType("sft_name", "dtg:Date,*geom:Point:srid=4326,name1:type1,name2,type2,...,nameN,typeN");

上例中我们创建了一个名为sft_name的SimpleFeatureType,该SimpleFeatureType包含了一个时间字段(dtg)、空间字段(geom,点要素类型,空间左边参考4326)以及若干属性字段(name1、name2、…)。

HBase Ganos支持的类型列表如下:

HBase Ganos类型 Java类型 是否支持创建索引
String java.lang.String Yes
Integer java.lang.Integer Yes
Double java.lang.Double Yes
Long java.lang.Long Yes
Float java.lang.Float Yes
Boolean java.lang.Boolean Yes
UUID java.util.UUID Yes
Date java.util.Date Yes
Timestamp java.sql.Timestamp Yes
Point org.locationtech.jts.geom.Point Yes
LineString org.locationtech.jts.geom.LineString Yes
Polygon org.locationtech.jts.geom.Polygon Yes
MultiPoint org.locationtech.jts.geom.MultiPoint Yes
MultiLineString org.locationtech.jts.geom.MultiLineString Yes
MultiPolygon org.locationtech.jts.geom.MultiPolygon Yes
GeometryCollection org.locationtech.jts.geom.GeometryCollection Yes
Geometry org.locationtech.jts.geom.Geometry Yes
List[A] java.util.List Yes
Map[A,B] java.util.Map No
Bytes byte[] No

注意:

  1. geom为必需指定属性,而且一次只能对一个空间类型字段创建索引,此字段会被应用于主时空索引系统中(Z2、Z3、XZ2、XZ3)。
  2. 日期类型Date字段可以用于主时空索引,也可用作普通属性索引

2. 配置索引参数

创建索引所需要的一些列参数都通过设置SimpleFeatureType的静态属性来指定:

  • 指定属性索引HBase Ganos允许对普通属性创建索引,这样在不指定时空参数的情况下可以大大提高查询效率,如下例单独对name字段创建索引:

    SimpleFeatureType sft = ...
    sft.getDescriptor("name").getUserData().put("index", "true");
  • 指定压缩方式通过设置适当的用户数据提示或通过命令行选项,可以在创建新的SimpleFeatureType时启用HBase文件压缩。有效的压缩类型是snappy,lzo,gz,bzip2,lz4或zstd。

SimpleFeatureType sft = ....;
sft.getUserData().put("geomesa.table.compression.enabled", "true");
sft.getUserData().put("geomesa.table.compression.type", "snappy");