Indexing Geomesa要素存储计数耗时

Indexing Geomesa要素存储计数耗时,indexing,accumulo,geomesa,Indexing,Accumulo,Geomesa,我正在尝试获取accumulo数据存储中存在的功能的总数。以下是我的示例代码: package com.hps; import java.util.Arrays; import java.util.Map; import org.geotools.data.DataStoreFinder; import org.geotools.data.FeatureSource; import org.geotools.data.FeatureStore; import org.geotools.dat

我正在尝试获取accumulo数据存储中存在的功能的总数。以下是我的示例代码:

package com.hps;

import java.util.Arrays;
import java.util.Map;

import org.geotools.data.DataStoreFinder;
import org.geotools.data.FeatureSource;
import org.geotools.data.FeatureStore;
import org.geotools.data.Query;
import org.geotools.data.Transaction;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.factory.Hints;
import org.geotools.filter.text.cql2.CQL;
import org.geotools.filter.text.ecql.ECQL;
import org.geotools.geometry.jts.JTSFactoryFinder;
import org.locationtech.geomesa.accumulo.data.AccumuloAppendFeatureWriter;
import org.locationtech.geomesa.accumulo.data.AccumuloDataStore;
import org.locationtech.geomesa.utils.interop.SimpleFeatureTypes;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.filter.FilterFactory2;
import org.opengis.filter.sort.SortBy;
import org.opengis.filter.sort.SortOrder;

import com.hps.schemas.Event;
import com.hps.schemas.QueryAdvanced;
import com.hps.schemas.QueryBasic;
import com.vividsolutions.jts.geom.Coordinate;

public class GeomesaClient {
  private AccumuloDataStore ds = null;
  private AccumuloAppendFeatureWriter fw = null;
  private SimpleFeatureSource sfs = null;
  private FeatureSource fs = null;
  private String tableName = "";
  private boolean isFlushed = true;
  private long lastFlushTs = 0;
  private FeatureStore fst = null;
  private SimpleFeatureType sft;

  public GeomesaClient(Map<String, String> dsConf) throws Exception {
    this.ds = (AccumuloDataStore) DataStoreFinder.getDataStore(dsConf);
    this.tableName = dsConf.get("tableName");

    sft = createFeatureType();
    sft.getUserData().put(SimpleFeatureTypes.DEFAULT_DATE_KEY, "ts");

    if(!Arrays.asList(this.ds.getTypeNames()).contains(sft.getTypeName())){
      ds.createSchema(sft);
    }

    this.fw = (AccumuloAppendFeatureWriter) (this.ds.getFeatureWriterAppend(sft.getTypeName(),
        Transaction.AUTO_COMMIT));
    this.sfs = ds.getFeatureSource(sft.getTypeName());
    this.fs = sfs;

    this.fst = (FeatureStore) sfs;
  }

  private SimpleFeatureType createFeatureType() {
    try{
      StringBuilder  simpleFeatureTypeBuilder = new StringBuilder();
      simpleFeatureTypeBuilder.append("r:Long:index=full:cardinality=high,");
      simpleFeatureTypeBuilder.append("*g:Point:srid=4326,");
      simpleFeatureTypeBuilder.append("di:Integer:index=full:cardinality=high,");
      simpleFeatureTypeBuilder.append("al:Float:index=join:cardinality=low,");
      simpleFeatureTypeBuilder.append("s:Float:index=join:cardinality=low,");
      simpleFeatureTypeBuilder.append("b:Float:index=join:cardinality=low,");
      simpleFeatureTypeBuilder.append("an:Float:index=join:cardinality=low,");
      simpleFeatureTypeBuilder.append("he:Float:index=join:cardinality=low,");
      simpleFeatureTypeBuilder.append("ve:Float:index=join:cardinality=low,");
      simpleFeatureTypeBuilder.append("t:Float:index=join:cardinality=low,");
      simpleFeatureTypeBuilder.append("m:Boolean:index=join:cardinality=low,");
      simpleFeatureTypeBuilder.append("i:Boolean:index=join:cardinality=low,");
      simpleFeatureTypeBuilder.append("ts:Long:index=join:cardinality=low;");
      simpleFeatureTypeBuilder.append("geomesa.indexes.enabled='attr_idx,records,z2'");
      return SimpleFeatureTypes.createType(tableName, simpleFeatureTypeBuilder.toString());
    }
    catch(Exception ex){
      ex.printStackTrace();
      return null;
    }
  }
  public int getRideCount(Long rideId) throws Exception {
    int count = 0;
    if(rideId != null)
      count = ((Long) (ds.stats().getCount(sft, CQL.toFilter("r=" + rideId), true).get())).intValue();
    return count;
  }
}

您好,Suresh,您可以使用解释查询功能查看GeoMesa查询计划器正在做什么吗?有了这些信息,我们就能知道是否使用了额外的索引。这里的文档()有点简洁,但应该为您指出输出查询计划的正确方向。如果您对此有任何疑问,请随时询问如何执行功能计数操作?。我在ShapeFile上看到了类似的问题,解释了如何打开shx文件,读取头并获取计数。如果是这样的话,那么由于与文件数量成比例的高i/o操作,操作可能会变慢?是的,我确实知道如何执行计数操作。;)获取计数需要运行筛选器指示的查询并手动计算结果(此操作所需的时间大约与查询这些记录所需的时间相同),或者使用给定筛选器的估计统计数据。对于估计的统计数据,并不是所有的查询都可以进行相同的优化。一般来说,看起来您可以每秒扫描250k个功能,这对于GeoMesa来说是正常的。如果您提供查询计划,我们可以确保您使用您创建的索引添加查询计划。
[2017-04-26 16:16:31,537] TRACE Explainer: Planning 'aj_v53' r = 31
0 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  - Planning 'aj_v53' r = 31
[2017-04-26 16:16:31,539] TRACE Explainer:   Original filter: r = 31
2 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -   Original filter: r = 31
[2017-04-26 16:16:31,540] TRACE Explainer:   Hints: density[false] bin[false] stats[false] map-aggregate[false] sampling[none]
3 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -   Hints: density[false] bin[false] stats[false] map-aggregate[false] sampling[none]
[2017-04-26 16:16:31,541] TRACE Explainer:   Sort: none
4 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -   Sort: none
[2017-04-26 16:16:31,542] TRACE Explainer:   Transforms: g=g
5 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -   Transforms: g=g
[2017-04-26 16:16:31,543] TRACE Explainer:   Strategy selection:
6 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -   Strategy selection:
[2017-04-26 16:16:31,565] TRACE Explainer:     Query processing took 19ms and produced 1 options
28 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -     Query processing took 19ms and produced 1 options
[2017-04-26 16:16:31,567] TRACE Explainer:     Filter plan: FilterPlan[AttributeIndex[r = 31][None]]
30 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -     Filter plan: FilterPlan[AttributeIndex[r = 31][None]]
[2017-04-26 16:16:31,568] TRACE Explainer:     Strategy selection took 2ms for 1 options
31 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -     Strategy selection took 2ms for 1 options
[2017-04-26 16:16:31,569] TRACE Explainer:   Strategy 1 of 1: AttributeIndex
32 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -   Strategy 1 of 1: AttributeIndex
[2017-04-26 16:16:31,570] TRACE Explainer:     Strategy filter: AttributeIndex[r = 31][None]
33 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -     Strategy filter: AttributeIndex[r = 31][None]
[2017-04-26 16:16:31,620] TRACE Explainer:     Plan: org.locationtech.geomesa.accumulo.index.BatchScanPlan
83 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -     Plan: org.locationtech.geomesa.accumulo.index.BatchScanPlan
[2017-04-26 16:16:31,621] TRACE Explainer:       Table: aj_v53_attr_v4
84 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -       Table: aj_v53_attr_v4
[2017-04-26 16:16:31,622] TRACE Explainer:       Deduplicate: false
85 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -       Deduplicate: false
[2017-04-26 16:16:31,622] TRACE Explainer:       Column Families (1): List(I)
85 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -       Column Families (1): List(I)
[2017-04-26 16:16:31,624] TRACE Explainer:       Ranges (1): [%01;%00;%00;800000000000001f%00;::%01;%00;%00;800000000000001f%01;)
87 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -       Ranges (1): [%01;%00;%00;800000000000001f%00;::%01;%00;%00;800000000000001f%01;)
[2017-04-26 16:16:31,626] TRACE Explainer:       Iterators (1):
89 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -       Iterators (1):
[2017-04-26 16:16:31,628] TRACE Explainer:         name:filter-transform-iter, priority:25, class:org.locationtech.geomesa.accumulo.iterators.KryoLazyFilterTransformIterator, properties:{sft=*g:Point:srid=4326,ts:Date;geomesa.index.dtg='ts',geomesa.table.sharing='true',geomesa.indices='attr:4:3,records:2:3,z2:3:3',geomesa.table.sharing.prefix='\u0001', tdefs=g=g, index=attr:4, tsft=*g:Point:srid=4326}
91 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -         name:filter-transform-iter, priority:25, class:org.locationtech.geomesa.accumulo.iterators.KryoLazyFilterTransformIterator, properties:{sft=*g:Point:srid=4326,ts:Date;geomesa.index.dtg='ts',geomesa.table.sharing='true',geomesa.indices='attr:4:3,records:2:3,z2:3:3',geomesa.table.sharing.prefix='\u0001', tdefs=g=g, index=attr:4, tsft=*g:Point:srid=4326}
[2017-04-26 16:16:31,629] TRACE Explainer:     Plan creation took 49ms
92 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -     Plan creation took 49ms
[2017-04-26 16:16:31,630] TRACE Explainer:   Query planning took 137ms
93 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -   Query planning took 137ms
[2017-04-26 16:16:31,644] TRACE Explainer: Planning 'aj_v53' r = 31
107 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  - Planning 'aj_v53' r = 31
[2017-04-26 16:16:31,644] TRACE Explainer:   Original filter: r = 31
107 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -   Original filter: r = 31
[2017-04-26 16:16:31,644] TRACE Explainer:   Hints: density[false] bin[false] stats[true] map-aggregate[false] sampling[none]
107 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -   Hints: density[false] bin[false] stats[true] map-aggregate[false] sampling[none]
[2017-04-26 16:16:31,644] TRACE Explainer:   Sort: none
107 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -   Sort: none
[2017-04-26 16:16:31,644] TRACE Explainer:   Transforms: None
107 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -   Transforms: None
[2017-04-26 16:16:31,644] TRACE Explainer:   Strategy selection:
107 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -   Strategy selection:
[2017-04-26 16:16:31,646] TRACE Explainer:     Query processing took 1ms and produced 1 options
109 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -     Query processing took 1ms and produced 1 options
[2017-04-26 16:16:31,646] TRACE Explainer:     Filter plan: FilterPlan[AttributeIndex[r = 31][None]]
109 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -     Filter plan: FilterPlan[AttributeIndex[r = 31][None]]
[2017-04-26 16:16:31,647] TRACE Explainer:     Strategy selection took 0ms for 1 options
110 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -     Strategy selection took 0ms for 1 options
[2017-04-26 16:16:31,647] TRACE Explainer:   Strategy 1 of 1: AttributeIndex
110 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -   Strategy 1 of 1: AttributeIndex
[2017-04-26 16:16:31,647] TRACE Explainer:     Strategy filter: AttributeIndex[r = 31][None]
110 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -     Strategy filter: AttributeIndex[r = 31][None]
[2017-04-26 16:16:31,656] TRACE Explainer:     Plan: org.locationtech.geomesa.accumulo.index.BatchScanPlan
119 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -     Plan: org.locationtech.geomesa.accumulo.index.BatchScanPlan
[2017-04-26 16:16:31,656] TRACE Explainer:       Table: aj_v53_attr_v4
119 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -       Table: aj_v53_attr_v4
[2017-04-26 16:16:31,656] TRACE Explainer:       Deduplicate: false
119 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -       Deduplicate: false
[2017-04-26 16:16:31,656] TRACE Explainer:       Column Families (1): List(I)
119 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -       Column Families (1): List(I)
[2017-04-26 16:16:31,657] TRACE Explainer:       Ranges (1): [%01;%00;%00;800000000000001f%00;::%01;%00;%00;800000000000001f%01;)
120 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -       Ranges (1): [%01;%00;%00;800000000000001f%00;::%01;%00;%00;800000000000001f%01;)
[2017-04-26 16:16:31,657] TRACE Explainer:       Iterators (1):
120 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -       Iterators (1):
[2017-04-26 16:16:31,657] TRACE Explainer:         name:stats-iter, priority:30, class:org.locationtech.geomesa.accumulo.iterators.KryoLazyStatsIterator, properties:{sft=*g:Point:srid=4326,ts:Date;geomesa.index.dtg='ts',geomesa.table.sharing='true',geomesa.indices='attr:4:3,records:2:3,z2:3:3',geomesa.table.sharing.prefix='\u0001', dupes=false, index=attr:4, geomesa.stats.string=Count()}
120 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -         name:stats-iter, priority:30, class:org.locationtech.geomesa.accumulo.iterators.KryoLazyStatsIterator, properties:{sft=*g:Point:srid=4326,ts:Date;geomesa.index.dtg='ts',geomesa.table.sharing='true',geomesa.indices='attr:4:3,records:2:3,z2:3:3',geomesa.table.sharing.prefix='\u0001', dupes=false, index=attr:4, geomesa.stats.string=Count()}
[2017-04-26 16:16:31,657] TRACE Explainer:     Plan creation took 9ms
120 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -     Plan creation took 9ms
[2017-04-26 16:16:31,658] TRACE Explainer:   Query planning took 17ms
121 [Thread-5] TRACE org.locationtech.geomesa.index.utils.Explainer  -   Query planning took 17ms