Geomesa:有没有办法在不丢失数据的情况下在 Geomesa 中创建、删除索引?或者我需要重新创建架构?

Geomesa: is there a way to create, delete indexes in geomesa without loosing data? Or I need to recreate a schema?

我有一个带有 geomesa 的 cassandra,里面有下一个模式

 ~  bin/geomesa-cassandra_2.11-3.3.0/bin/geomesa-cassandra describe-schema -P localhost:9042 -u cassandra -p cassandra -k geomesa -c gsm_events -f SignalBuilder 
INFO  Describing attributes of feature 'SignalBuilder'
geo           | Point   (Spatio-temporally indexed)
time          | Date    (Spatio-temporally indexed) (Attribute indexed)
cam           | String  (Attribute indexed) (Attribute indexed)
imei          | String  (Attribute indexed)
dir           | Double  
alt           | Double  
vlc           | Double  
sl            | Integer 
ds            | Integer 
dir_y         | Double  
poi_azimuth_x | Double  
poi_azimuth_y | Double  

User data:
  geomesa.attr.splits     | 4
  geomesa.feature.expiry  | time(30 days)
  geomesa.index.dtg       | time
  geomesa.indices         | z3:7:3:geo:time,attr:8:3:time,attr:8:3:cam,attr:8:3:cam:time,attr:8:3:imei
  geomesa.stats.enable    | true
  geomesa.table.partition | time
  geomesa.z.splits        | 4
  geomesa.z3.interval     | week

有没有办法在 z3 之外创建 z2 索引,并删除 cam 属性索引,仅保留 cam:time 属性索引而不丢失数据库中的数据?如果我已经有 cam:time 索引,是否不需要 time 属性索引?

P.S。为什么这个查询使用 z2 索引,而不是 z3?

~  bin/geomesa-cassandra_2.11-3.3.0/bin/geomesa-cassandra explain -P 10.200.217.24:9042 -u cassandra -p cassandra -k geomesa -c gsm_events -f SignalBuilder -q "Bbox(geo,1,1,2,2) and time > 123333"; 
Planning 'SignalBuilder' BBOX(geo, 1.0,1.0,2.0,2.0) AND time > 1970-01-01T00:02:03.333+00:00
  Original filter: BBOX(geo, 1.0,1.0,2.0,2.0) AND time > 123333
  Hints: bin[false] arrow[false] density[false] stats[false] sampling[none]
  Sort: none
  Transforms: none
  Max features: none
  Strategy selection:
    Query processing took 21ms for 1 options
    Filter plan: FilterPlan[Z2Index(geo)[BBOX(geo, 1.0,1.0,2.0,2.0)][time > 1970-01-01T00:02:03.333+00:00](1.2)]
    Strategy selection took 2ms for 1 options
  Strategy 1 of 1: Z2Index(geo)
    Strategy filter: Z2Index(geo)[BBOX(geo, 1.0,1.0,2.0,2.0)][time > 1970-01-01T00:02:03.333+00:00](1.2)
    Geometries: FilterValues(List(POLYGON ((1 1, 2 1, 2 2, 1 2, 1 1))),true,false)
    Plan: org.locationtech.geomesa.cassandra.data.StatementPlan
      Tables: 
      Ranges (0): 
      Client-side filter: BBOX(geo, 1.0,1.0,2.0,2.0) AND time > 1970-01-01T00:02:03.333+00:00
      Reduce: class:LocalTransformReducer, state:{name=SignalBuilder, tnam=, tsft=, tdef=, hint=RETURN_SFT,"SignalBuilder,""*geo:Point,time:Date,cam:String,imei:String,dir:Double,alt:Double,vlc:Double,sl:Integer,ds:Integer,dir_y:Double,poi_azimuth_x:Double,poi_azimuth_y:Double;geomesa.stats.enable='true',geomesa.z.splits='4',geomesa.feature.expiry='time(30 days)',geomesa.table.partition='time',geomesa.index.dtg='time',geomesa.indices='z3:7:3:geo:time,z2:5:3:geo,attr:8:3:time,attr:8:3:cam,attr:8:3:cam:time',geomesa.attr.splits='4',geomesa.z3.interval='week'""", spec=*geo:Point,time:Date,cam:String,imei:String,dir:Double,alt:Double,vlc:Double,sl:Integer,ds:Integer,dir_y:Double,poi_azimuth_x:Double,poi_azimuth_y:Double;geomesa.stats.enable='true',geomesa.z.splits='4',geomesa.feature.expiry='time(30 days)',geomesa.table.partition='time',geomesa.index.dtg='time',geomesa.indices='z3:7:3:geo:time,z2:5:3:geo,attr:8:3:time,attr:8:3:cam,attr:8:3:cam:time',geomesa.attr.splits='4',geomesa.z3.interval='week', filt=BBOX(geo, 1.0,1.0,2.0,2.0) AND time > 1970-01-01T00:02:03.333+00:00}
    Plan creation took 110ms
  Query planning took 294ms

这将涉及几个步骤。您可能希望在尝试此操作之前备份您的数据,以防出现问题。首先,您想使用 updateSchema 添加新索引并删除旧索引,并将现有索引设置为“只读”模式。您可以使用 GeoMesa CLI scala-console 命令来 运行 以下内容:

val sft = SimpleFeatureTypes.mutable(ds.getSchema("SignalBuilder"))
// 5 is the latest version of the z2 index as of now
// 1 sets the indices to read only mode
sft.getUserData.put("geomesa.indices", "z3:7:1:geo:time,z2:5:3:geo,attr:8:1:time,attr:8:1:cam:time,attr:8:1:imei")
ds.updateSchema(sft.getTypeName, sft)

在此之后,您将需要重新提取数据以填充 z2 索引。填充索引后,您需要再次更新架构以将索引设置回 read/write 模式:

val sft = SimpleFeatureTypes.mutable(ds.getSchema("SignalBuilder"))
// 5 is the latest version of the z2 index as of now
// 3 sets the indices to read/write mode
sft.getUserData.put("geomesa.indices", "z3:7:3:geo:time,z2:5:3:geo,attr:8:3:time,attr:8:3:cam:time,attr:8:3:imei")
ds.updateSchema(sft.getTypeName, sft)

请注意,旧的 cam 索引 table 仍将存在于 Cassandra 中,但不会收到任何进一步的更新或用于查询。您可以使用标准的 Cassandra 技术删除它。