geomesa hbase为已创建好的schema添加字段

记录一次为已创建好的schema添加字段,使用hbase作为数据源。
当迭代不断的向前业务不断的加大,导致前期设计的schema无法满足现在业务的需求,需要在已创建好的schema上新增字段以此来满足需求。
schema新增字段很自然的会想到更新schema,刚好api接口中有个接口void updateSchema(String typeName, SimpleFeatureType featureType) throws IOException,于是在代码中创建一个SimpleFeatureType添加新的字段,调用updateSchema函数修改指定的schema。以为就此大功告成,没想到报错,提示

updating schema columns is not allowed

查看该api接口的源码发现不支持修改已经创建好的schema的字段,源码如下图所示: 在这里插入图片描述
提供的api接口不支持修改已创建schema的字段,但是发现在指定的catalog下创建一个schema都会在hbase中该catalog的元数据表中添加如下图所示信息:
在这里插入图片描述
上图中可以看到rowkey为*attributes的value记录着schema的元数据,尝试使用hbase shell的put命令修改该value的值进行新增,put命令为:

put ‘test’,“testtypename~attributes”,“m:v”,“myid:String,value:String:index=true,temp:String,dtg:Date,*geom:Point:srid=4326;geomesa.keywords=‘testkeywords’,geomesa.index.dtg=‘dtg’,geomesa.table.sharing=‘false’,geomesa.indices=‘z3:2:3,z2:2:3,id:1:3,attr:5:3’,geomesa.z3.interval=‘week’”

其中temp:String为新增字段,设置成功,并且新增数据也可以成功,但是查询的时候报

ERROR Invalid TWKB geometry type 0 java.lang.IllegalArgumentException:
Invalid TWKB geometry type 0 at
org.locationtech.geomesa.features.serialization.TwkbSerialization c l a s s . d e s e r i a l i z e ( T w k b S e r i a l i z a t i o n . s c a l a : 198 a t o r g . l o c a t i o n t e c h . g e o m e s a . f e a t u r e s . k r y o . s e r i a l i z a t i o n . K r y o G e o m e t r y S e r i a l i z a t i o n class.deserialize(TwkbSerialization.scala:198 at org.locationtech.geomesa.features.kryo.serialization.KryoGeometrySerialization class.deserialize(TwkbSerialization.scala:198atorg.locationtech.geomesa.features.kryo.serialization.KryoGeometrySerialization.deserialize(KryoGeometrySeriali
at
org.locationtech.geomesa.features.kryo.impl.KryoFeatureDeserializationKaTeX parse error: Can't use function '$' in math mode at position 8: anonfun$̲matchReader$8.a…anonfun$matchReader 8. a p p l y ( K r y o F e a t u r e a t o r g . l o c a t i o n t e c h . g e o m e s a . f e a t u r e s . k r y o . i m p l . A c t i v e D e s e r i a l i z a t i o n 8.apply(KryoFeature at org.locationtech.geomesa.features.kryo.impl.ActiveDeserialization 8.apply(KryoFeatureatorg.locationtech.geomesa.features.kryo.impl.ActiveDeserializationclass.readFeature(ActiveDeserialization.scala
at
org.locationtech.geomesa.features.kryo.impl.ActiveDeserialization c l a s s . d e s e r i a l i z e ( A c t i v e D e s e r i a l i z a t i o n . s c a l a a t o r g . l o c a t i o n t e c h . g e o m e s a . f e a t u r e s . k r y o . K r y o F e a t u r e S e r i a l i z e r class.deserialize(ActiveDeserialization.scala at org.locationtech.geomesa.features.kryo.KryoFeatureSerializer class.deserialize(ActiveDeserialization.scalaatorg.locationtech.geomesa.features.kryo.KryoFeatureSerializerMutableActiveSerializer.deserialize(KryoFeatureSer
at
org.locationtech.geomesa.hbase.index.HBaseIndexAdapterKaTeX parse error: Can't use function '$' in math mode at position 8: anonfun$̲org$locationtec…anonfun o r g org orglocationtech g e o m e s a geomesa geomesahbase i n d e x index indexHBaseIndex
at scala.collection.IteratorKaTeX parse error: Can't use function '$' in math mode at position 5: anon$̲11.next(Iterato…anon 2. n e x t ( C l o s e a b l e I t e r a t o r . s c a l a : 36 ) a t o r g . l o c a t i o n t e c h . g e o m e s a . u t i l s . c o l l e c t i o n . S e l f C l o s i n g I t e r a t o r 2.next(CloseableIterator.scala:36) at org.locationtech.geomesa.utils.collection.SelfClosingIterator 2.next(CloseableIterator.scala:36)atorg.locationtech.geomesa.utils.collection.SelfClosingIterator$anon 1. n e x t ( C l o s e a b l e I t e r a t o r . s c a l a : 162 ) a t o r g . l o c a t i o n t e c h . g e o m e s a . u t i l s . c o l l e c t i o n . C l o s e a b l e I t e r a t o r 1.next(CloseableIterator.scala:162) at org.locationtech.geomesa.utils.collection.CloseableIterator 1.next(CloseableIterator.scala:162)atorg.locationtech.geomesa.utils.collection.CloseableIterator$anon 5. n e x t ( C l o s e a b l e I t e r a t o r . s c a l a : 101 ) a t o r g . l o c a t i o n t e c h . g e o m e s a . u t i l s . c o l l e c t i o n . C l o s e a b l e I t e r a t o r 5.next(CloseableIterator.scala:101) at org.locationtech.geomesa.utils.collection.CloseableIterator 5.next(CloseableIterator.scala:101)atorg.locationtech.geomesa.utils.collection.CloseableIterator$anon 5. n e x t ( C l o s e a b l e I t e r a t o r . s c a l a : 101 ) a t o r g . l o c a t i o n t e c h . g e o m e s a . i n d e x . g e o t o o l s . G e o M e s a F e a t u r e R e a d e r W i t h A u d i t 5.next(CloseableIterator.scala:101) at org.locationtech.geomesa.index.geotools.GeoMesaFeatureReaderWithAudit 5.next(CloseableIterator.scala:101)atorg.locationtech.geomesa.index.geotools.GeoMesaFeatureReaderWithAudit a n o n f u n anonfun anonfunnext 2. a p p l y ( G e o M e s a F e a t u r e R e a d e a t o r g . l o c a t i o n t e c h . g e o m e s a . i n d e x . g e o t o o l s . G e o M e s a F e a t u r e R e a d e r W i t h A u d i t 2.apply(GeoMesaFeatureReade at org.locationtech.geomesa.index.geotools.GeoMesaFeatureReaderWithAudit 2.apply(GeoMesaFeatureReadeatorg.locationtech.geomesa.index.geotools.GeoMesaFeatureReaderWithAudit a n o n f u n anonfun anonfunnext 2. a p p l y ( G e o M e s a F e a t u r e R e a d e a t o r g . l o c a t i o n t e c h . g e o m e s a . u t i l s . s t a t s . M e t h o d P r o f i l i n g 2.apply(GeoMesaFeatureReade at org.locationtech.geomesa.utils.stats.MethodProfiling 2.apply(GeoMesaFeatureReadeatorg.locationtech.geomesa.utils.stats.MethodProfilingclass.profile(MethodProfiling.scala:19)
at
org.locationtech.geomesa.index.geotools.GeoMesaFeatureReaderWithAudit.profile(GeoMesaFeatureReader.scala:90)
at
org.locationtech.geomesa.index.geotools.GeoMesaFeatureReaderWithAudit.next(GeoMesaFeatureReader.scala:103)
at
org.locationtech.geomesa.index.geotools.GeoMesaFeatureReaderKaTeX parse error: Can't use function '$' in math mode at position 5: anon$̲2.org$locationt…anon 2. n e x t ( G e o M e s a F e a t u r e R e a d e r . s c a l a : 65 ) a t o r g . l o c a t i o n t e c h . g e o m e s a . i n d e x . g e o t o o l s . G e o M e s a F e a t u r e R e a d e r 2.next(GeoMesaFeatureReader.scala:65) at org.locationtech.geomesa.index.geotools.GeoMesaFeatureReader 2.next(GeoMesaFeatureReader.scala:65)atorg.locationtech.geomesa.index.geotools.GeoMesaFeatureReader$anon 2. n e x t ( G e o M e s a F e a t u r e R e a d e r . s c a l a : 65 ) a t o r g . g e o t o o l s . f e a t u r e . F e a t u r e R e a d e r I t e r a t o r . n e x t ( F e a t u r e R e a d e r I t e r a t o r . j a v a : 73 ) a t o r g . g e o t o o l s . f e a t u r e . F e a t u r e R e a d e r I t e r a t o r . n e x t ( F e a t u r e R e a d e r I t e r a t o r . j a v a : 43 ) a t o r g . g e o t o o l s . f e a t u r e . c o l l e c t i o n . D e l e g a t e F e a t u r e I t e r a t o r . n e x t ( D e l e g a t e F e a t u r e I t e r a t o r . j a v a : 66 ) a t o r g . l o c a t i o n t e c h . g e o m e s a . u t i l s . c o l l e c t i o n . C l o s e a b l e I t e r a t o r 2.next(GeoMesaFeatureReader.scala:65) at org.geotools.feature.FeatureReaderIterator.next(FeatureReaderIterator.java:73) at org.geotools.feature.FeatureReaderIterator.next(FeatureReaderIterator.java:43) at org.geotools.feature.collection.DelegateFeatureIterator.next(DelegateFeatureIterator.java:66) at org.locationtech.geomesa.utils.collection.CloseableIterator 2.next(GeoMesaFeatureReader.scala:65)atorg.geotools.feature.FeatureReaderIterator.next(FeatureReaderIterator.java:73)atorg.geotools.feature.FeatureReaderIterator.next(FeatureReaderIterator.java:43)atorg.geotools.feature.collection.DelegateFeatureIterator.next(DelegateFeatureIterator.java:66)atorg.locationtech.geomesa.utils.collection.CloseableIterator$anon 4. n e x t ( C l o s e a b l e I t e r a t o r . s c a l a : 51 ) a t o r g . l o c a t i o n t e c h . g e o m e s a . u t i l s . c o l l e c t i o n . C l o s e a b l e I t e r a t o r 4.next(CloseableIterator.scala:51) at org.locationtech.geomesa.utils.collection.CloseableIterator 4.next(CloseableIterator.scala:51)atorg.locationtech.geomesa.utils.collection.CloseableIterator$anon 4. n e x t ( C l o s e a b l e I t e r a t o r . s c a l a : 49 ) a t s c a l a . c o l l e c t i o n . I t e r a t o r 4.next(CloseableIterator.scala:49) at scala.collection.Iterator 4.next(CloseableIterator.scala:49)atscala.collection.Iteratorclass.foreach(Iterator.scala:742) at
org.locationtech.geomesa.utils.collection.CloseableIteratorKaTeX parse error: Can't use function '$' in math mode at position 5: anon$̲4.foreach(Close…anonfun$export 1. a p p l y ( E x p o r t C o m m a n d . s c a l a : 84 ) a t o r g . l o c a t i o n t e c h . g e o m e s a . t o o l s . e x p o r t . E x p o r t C o m m a n d 1.apply(ExportCommand.scala:84) at org.locationtech.geomesa.tools.export.ExportCommand 1.apply(ExportCommand.scala:84)atorg.locationtech.geomesa.tools.export.ExportCommand a n o n f u n anonfun anonfunexport 1. a p p l y ( E x p o r t C o m m a n d . s c a l a : 84 ) a t o r g . l o c a t i o n t e c h . g e o m e s a . u t i l s . i o . W i t h C l o s e 1.apply(ExportCommand.scala:84) at org.locationtech.geomesa.utils.io.WithClose 1.apply(ExportCommand.scala:84)atorg.locationtech.geomesa.utils.io.WithClose.apply(SafeClose.scala:51)
at
org.locationtech.geomesa.tools.export.ExportCommand c l a s s . e x p o r t ( E x p o r t C o m m a n d . s c a l a : 84 ) a t o r g . l o c a t i o n t e c h . g e o m e s a . h b a s e . t o o l s . e x p o r t . H B a s e E x p o r t C o m m a n d . e x p o r t ( H B a s e E x p o r t C o m m a n d . s c a l a : 19 ) a t o r g . l o c a t i o n t e c h . g e o m e s a . t o o l s . e x p o r t . E x p o r t C o m m a n d class.export(ExportCommand.scala:84) at org.locationtech.geomesa.hbase.tools.export.HBaseExportCommand.export(HBaseExportCommand.scala:19) at org.locationtech.geomesa.tools.export.ExportCommand class.export(ExportCommand.scala:84)atorg.locationtech.geomesa.hbase.tools.export.HBaseExportCommand.export(HBaseExportCommand.scala:19)atorg.locationtech.geomesa.tools.export.ExportCommandclass.export(ExportCommand.scala:77)
at
org.locationtech.geomesa.hbase.tools.export.HBaseExportCommand.export(HBaseExportCommand.scala:19)
at
org.locationtech.geomesa.tools.export.ExportCommandKaTeX parse error: Can't use function '$' in math mode at position 8: anonfun$̲execute$2anonfun$apply 1. a p p l y ( E x p o r t C o m m a n d . s c a a t o r g . l o c a t i o n t e c h . g e o m e s a . t o o l s . e x p o r t . E x p o r t C o m m a n d 1.apply(ExportCommand.sca at org.locationtech.geomesa.tools.export.ExportCommand 1.apply(ExportCommand.scaatorg.locationtech.geomesa.tools.export.ExportCommand a n o n f u n anonfun anonfunexecute 2 2 2 a n o n f u n anonfun anonfunapply 1. a p p l y ( E x p o r t C o m m a n d . s c a a t o r g . l o c a t i o n t e c h . g e o m e s a . t o o l s . D a t a S t o r e C o m m a n d 1.apply(ExportCommand.sca at org.locationtech.geomesa.tools.DataStoreCommand 1.apply(ExportCommand.scaatorg.locationtech.geomesa.tools.DataStoreCommandclass.withDataStore(Command.scala:60)
at
org.locationtech.geomesa.hbase.tools.export.HBaseExportCommand.withDataStore(HBaseExportCommand.scala:19)
at
org.locationtech.geomesa.tools.export.ExportCommandKaTeX parse error: Can't use function '$' in math mode at position 8: anonfun$̲execute$2.apply…anonfun$execute 2. a p p l y ( E x p o r t C o m m a n d . s c a l a : 45 ) a t o r g . l o c a t i o n t e c h . g e o m e s a . u t i l s . s t a t s . M e t h o d P r o f i l i n g 2.apply(ExportCommand.scala:45) at org.locationtech.geomesa.utils.stats.MethodProfiling 2.apply(ExportCommand.scala:45)atorg.locationtech.geomesa.utils.stats.MethodProfilingclass.profile(MethodProfiling.scala:26)
at
org.locationtech.geomesa.hbase.tools.export.HBaseExportCommand.profile(HBaseExportCommand.scala:19)
at
org.locationtech.geomesa.tools.export.ExportCommand c l a s s . e x e c u t e ( E x p o r t C o m m a n d . s c a l a : 45 ) a t o r g . l o c a t i o n t e c h . g e o m e s a . h b a s e . t o o l s . e x p o r t . H B a s e E x p o r t C o m m a n d . e x e c u t e ( H B a s e E x p o r t C o m m a n d . s c a l a : 19 ) a t o r g . l o c a t i o n t e c h . g e o m e s a . t o o l s . R u n n e r class.execute(ExportCommand.scala:45) at org.locationtech.geomesa.hbase.tools.export.HBaseExportCommand.execute(HBaseExportCommand.scala:19) at org.locationtech.geomesa.tools.Runner class.execute(ExportCommand.scala:45)atorg.locationtech.geomesa.hbase.tools.export.HBaseExportCommand.execute(HBaseExportCommand.scala:19)atorg.locationtech.geomesa.tools.Runnerclass.main(Runner.scala:28)
at
org.locationtech.geomesa.hbase.tools.HBaseRunner$.main(HBaseRunner.scala:21)
at
org.locationtech.geomesa.hbase.tools.HBaseRunner.main(HBaseRunner.scala)

看错误好像是序列化错误,想到是不是因为添加的字段在已存在的字段之间导致查询到的未添加新字段之前的数据无法序列化为已添加新字段的结构中。于是尝试将新增的字段放到最后,重新修改hbase中的元数据表,修改后如下图所示:
在这里插入图片描述
其中add:String为新增字段。修改完之后进行插入数据和查询数据都能成功,查询到的数据中未添加新字段前的数据在新字段这一列为空。
至此为已创建的schema新增字段完成,本次是使用hbase作为数据源,其他的数据源应该也可以通过修改元数据的方式进行新增字段。

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Geomesa可以很方便地集成HBase和Spark,实现对HBase的读写操作。具体步骤如下: 1. 首先需要在HBase创建表,可以使用HBase shell或者HBase API进行创建。 2. 在Spark中引入Geomesa的依赖,可以使用Maven或者SBT进行引入。 3. 使用Geomesa提供的HBaseDataStoreFactory创建HBaseDataStore对象,连接到HBase中的表。 4. 使用Spark的API读取HBase中的数据,可以使用RDD或者DataFrame进行读取。 5. 使用Geomesa提供的HBaseFeatureWriter将数据写入到HBase中。 需要注意的是,在使用Geomesa进行读写HBase时,需要使用Geomesa提供的SimpleFeature类型进行操作。同时,需要在HBase创建相应的列族和列,以存储SimpleFeature对象的属性值。 ### 回答2: Geomesa是一个基于地理空间数据管理和分析的开源工具。它集成了HBase和Spark,可以实现读写HBase的功能。 在Geomesa中,HBase作为数据存储和查询的主要工具,Spark则用于并行计算和数据处理。通过这种方式,HBase可以实现大规模的数据存储和高效的数据查询,而Spark可以进行并行计算和数据处理,提高数据分析的效率。 在使用Geomesa集成HBase和Spark进行读写HBase的时候,需要进行以下操作: 1. 配置HBase和Spark的环境:为了保证Geomesa正常运作,需要正确配置HBase和Spark的环境。具体的配置方式可以参考Geomesa的官方文档。 2. 读写HBase数据:通过Geomesa的API,可以实现对HBase数据的读写操作。其中,读操作可以通过Scan类进行,而写操作可以通过Put和Delete类进行。 3. 创建和管理数据表:在Geomesa中,可以通过SimpleFeatureType类来定义数据表结构,并且可以使用Spark和HBase的API来实现数据表的创建和管理。 4. 进行空间查询和空间分析:Geomesa支持空间查询和空间分析的功能,可以通过Spark和HBase的API来实现。 以上就是使用Geomesa集成HBase和Spark进行读写HBase的基本操作流程。通过这种方式,可以实现高效、灵活、可扩展的地理空间数据处理和分析,为地理信息系统的应用提供了强有力的支持。 ### 回答3: geomesa是一个基于Apache Spark和Apache Accumulo的开源地理空间数据分析框架。它提供了丰富的地理空间分析功能,并支持海量地理数据的处理。随着geomesa社区的发展,它也开始支持其他的后端存储引擎,例如HBasegeomesa集成HBase和Spark的主要目的是为了在HBase中存储和查询大规模地理数据,并通过Spark进行批量计算和实时分析。这种集成方式可以实现高效的数据处理和快速的响应时间,尤其适用于对海量地理数据进行地理空间分析和挖掘的场景。 在geomesa中使用HBase的过程主要包括以下几个步骤: 1. 安装HBase和Spark 在使用geomesa之前,需要先安装和配置HBase和Spark环境。HBase是一个开源分布式数据库,可以存储和管理大量的结构化数据;Spark是一个快速的大数据处理引擎,可以进行批量计算和实时分析。 2. 安装geomesa geomesa是一个基于Spark和Accumulo的地理空间分析框架,可以在Spark中快速地进行大规模地理数据的处理和分析。安装geomesa的过程很简单,只需要下载并解压缩geomesa的安装文件即可。 3. 创建HBase数据表 在使用geomesa之前,需要先在HBase创建相应的数据表。通常情况下,geomesa会为每个表创建两个列族,一个是属性列(attributes),用于存储地理对象的属性信息;另一个是空间列(spatial),用于存储地理对象的空间信息。 4. 使用geomesa创建地理数据集 在HBase创建好数据表之后,需要使用geomesa创建相应的地理数据集(SimpleFeatureType)。geomesa提供了多种不同类型的SimpleFeatureType,可以根据实际需求选择相应的类型。 5. 将地理数据写入HBase 将地理数据写入HBase的过程很简单,只需要借助geomesa提供的API即可。geomesa支持将地理数据写入HBase和从HBase中读取地理数据。写入数据时,需要指定相应的地理数据集和HBase表,geomesa会自动将数据按照指定的格式写入HBase。 6. 从HBase中读取地理数据 从HBase中读取地理数据的过程同样也很简单,只需要借助geomesa提供的API即可。读取数据时,需要指定相应的地理数据集和HBase表,geomesa会自动从HBase中读取数据,并将数据以相应的格式返回。 以上就是geomesa集成HBase和Spark读写HBase的主要步骤,通过这种方式可以实现高效的海量地理数据处理和分析。但在实际应用中,还需要考虑数据安全、性能优化等方面的问题。因此,在使用geomesa时需要根据实际需求进行相应的优化和配置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值