@Override public BaseStatisticsQueryBuilder<Long> count() { return CountDataStatistics.STATS_TYPE.newBuilder(); }
@Override public StatisticsId[] getSupportedStatistics() { return new StatisticsId[] { new StatisticsId(new BaseStatisticsType<>(statType), fieldName)}; } };
@Override public InternalDataStatistics<GridCoverage, ?, ?> createDataStatistics( final StatisticsId statisticsId) { InternalDataStatistics<GridCoverage, ?, ?> retVal = null; if (OverviewStatistics.STATS_TYPE.equals(statisticsId.getType())) { retVal = new OverviewStatistics(); } else if (BoundingBoxDataStatistics.STATS_TYPE.equals(statisticsId.getType())) { retVal = new RasterBoundingBoxStatistics(); } else if (RasterFootprintStatistics.STATS_TYPE.equals(statisticsId.getType())) { retVal = new RasterFootprintStatistics(); } else if (HistogramStatistics.STATS_TYPE.equals(statisticsId.getType()) && (histogramConfig != null)) { retVal = new HistogramStatistics(histogramConfig); } else { // HP Fortify "Log Forging" false positive // What Fortify considers "user input" comes only // from users with OS-level access anyway LOGGER.warn( "Unrecognized statistics type " + statisticsId.getType().getString() + " using count statistic"); retVal = new CountDataStatistics<>(); } return retVal; }
private Histogram getHistogram(final String coverageName, final double resX, final double resY) throws IOException { final Map<Resolution, Histogram> histograms = geowaveDataStore.aggregateStatistics( HistogramStatistics.STATS_TYPE.newBuilder().setAuthorizations( authorizationSPI.getAuthorizations()).dataType(coverageName).build()); if (histograms != null) { return histograms.get(new Resolution(new double[] {resX, resY})); } else { LOGGER.warn("Cannot find histogram for coverage '" + coverageName + "'"); } return null; }
protected ByteBuffer binaryBuffer(final byte[] bytes) { final ByteBuffer buffer = ByteBuffer.wrap(bytes); adapterId = VarintUtils.readUnsignedShort(buffer); final int typeLength = VarintUtils.readUnsignedInt(buffer); final int extenedIdLength = VarintUtils.readUnsignedInt(buffer); final byte typeBytes[] = new byte[typeLength]; buffer.get(typeBytes); statisticsType = new BaseStatisticsType(); statisticsType.fromBinary(typeBytes); final byte[] extendedIdBytes = new byte[extenedIdLength]; buffer.get(extendedIdBytes); extendedId = StringUtils.stringFromBinary(extendedIdBytes); return buffer; }
private void init() { int supportedStatsLength = 2; if (histogramConfig != null) { supportedStatsLength++; } supportedStats = new StatisticsId[supportedStatsLength]; supportedStats[0] = OverviewStatistics.STATS_TYPE.newBuilder().build().getId(); supportedStats[1] = BoundingBoxDataStatistics.STATS_TYPE.newBuilder().build().getId(); if (histogramConfig != null) { supportedStats[2] = HistogramStatistics.STATS_TYPE.newBuilder().build().getId(); } visibilityHandler = new DefaultFieldStatisticVisibility<>(); }
@Override protected boolean performStatsCommand( final DataStorePluginOptions storeOptions, final InternalDataAdapter<?> adapter, final StatsCommandLineOptions statsOptions) throws IOException { // Remove the stat final DataStatisticsStore statStore = storeOptions.createDataStatisticsStore(); final String[] authorizations = getAuthorizations(statsOptions.getAuthorizations()); if (!statStore.removeStatistics( adapter.getAdapterId(), fieldName, new BaseStatisticsType<>(statType), authorizations)) { throw new RuntimeException("Unable to remove statistic: " + statType); } return true; }
/** * Get an array of stats object IDs for the Stats Manager * * @return Array of stats object IDs as 'ByteArrayId' */ public StatisticsId[] getSupportedStatistics() { // Why are we adding a CountDataStatistics?? final StatisticsId[] statObjIds = new StatisticsId[statsObjList.size() + 1]; int i = 0; for (final InternalDataStatistics<SimpleFeature, ?, ?> statObj : statsObjList) { statObjIds[i++] = new StatisticsId(statObj.getType(), statObj.getExtendedId()); } statObjIds[i] = CountDataStatistics.STATS_TYPE.newBuilder().build().getId(); return statObjIds; } }
public static InternalDataStatistics<?, ?, ?> setFields( final GeoWaveMetadata entry, final InternalDataStatistics<?, ?, ?> basicStats, final short adapterId) { if (basicStats != null) { basicStats.setAdapterId(adapterId); final int index = Bytes.indexOf(entry.getPrimaryId(), (byte) 0); if ((index > 0) && (index < (entry.getPrimaryId().length - 1))) { basicStats.setType( new BaseStatisticsType(Arrays.copyOfRange(entry.getPrimaryId(), 0, index))); basicStats.setExtendedId( StringUtils.stringFromBinary( Arrays.copyOfRange(entry.getPrimaryId(), index + 1, entry.getPrimaryId().length))); } else { basicStats.setType(new BaseStatisticsType(entry.getPrimaryId())); } final byte[] visibility = entry.getVisibility(); if (visibility != null) { basicStats.setVisibility(visibility); } } return basicStats; }
@Override public double[][] getResolutionLevels(final String coverageName) throws IOException { final Resolution[] resolutions = geowaveDataStore.aggregateStatistics( OverviewStatistics.STATS_TYPE.newBuilder().setAuthorizations( authorizationSPI.getAuthorizations()).dataType(coverageName).build()); if (resolutions == null) { LOGGER.warn("Cannot find resolutions for coverage '" + coverageName + "'"); return null; } final double[][] retVal = new double[resolutions.length][]; int i = 0; for (final Resolution res : resolutions) { retVal[i++] = res.getResolutionPerDimension(); } return retVal; }
@Override public int getCount() { if (query.getFilter().equals(Filter.INCLUDE)) { // GEOWAVE-60 optimization final Map<StatisticsId, InternalDataStatistics<SimpleFeature, ?, ?>> statsMap = reader.getTransaction().getDataStatistics(); StatisticsId id = CountDataStatistics.STATS_TYPE.newBuilder().build().getId(); if (statsMap.containsKey(id)) { final CountDataStatistics stats = (CountDataStatistics) statsMap.get(id); if ((stats != null) && stats.isSet()) { return (int) stats.getCount(); } } } else if (query.getFilter().equals(Filter.EXCLUDE)) { return 0; } QueryConstraints constraints; try { constraints = getQueryConstraints(); return (int) reader.getCountInternal( constraints.jtsBounds, constraints.timeBounds, getFilter(query), constraints.limit); } catch (TransformException | FactoryException e) { LOGGER.warn("Unable to transform geometry, can't get count", e); } // fallback return 0; }