public boolean isWithin(final NumericData timeRange) { final double st = startTime.getTime(); final double et = endTime.getTime(); final double rst = timeRange.getMin(); final double ret = timeRange.getMax(); return (((st < rst) && (et > rst)) || ((st < ret) && (et > ret)) || ((st < rst) && (et > ret))); }
@Override public boolean overlaps(final NumericDimensionField[] field, final NumericData[] rangeData) { assert (field[0] instanceof TimeField); return (long) Math.floor(rangeData[0].getMin()) <= this.time && (long) Math.ceil(rangeData[0].getMax()) >= this.time; } }
@Override public boolean overlaps(final NumericDimensionField[] field, final NumericData[] rangeData) { assert (field[0] instanceof TimeField); long t0 = (long) Math.ceil(rangeData[0].getMax()) - this.startTime; long t1 = this.endTime - (long) Math.floor(rangeData[0].getMin()); return Math.abs(t0 - t1) <= (t0 + t1); } }
/** @return all of the minimum values (for each dimension) */ @Override public double[] getMinValuesPerDimension() { final NumericData[] ranges = getDataPerDimension(); final double[] minPerDimension = new double[ranges.length]; for (int d = 0; d < ranges.length; d++) { minPerDimension[d] = ranges[d].getMin(); } return minPerDimension; }
public boolean intersects(final ConstraintData cd) { final double i1 = cd.range.getMin(); final double i2 = cd.range.getMax(); final double j1 = range.getMin(); final double j2 = range.getMax(); return ((i1 < j2) || DoubleMath.fuzzyEquals(i1, j2, DOUBLE_TOLERANCE)) && ((i2 > j1) || DoubleMath.fuzzyEquals(i2, j1, DOUBLE_TOLERANCE)); }
public ConstraintData merge(final ConstraintData cd) { if (range.equals(cd.range)) { return new ConstraintData(range, isDefault); } return new ConstraintData( new NumericRange( Math.min(cd.range.getMin(), range.getMin()), Math.max(cd.range.getMax(), range.getMax())), false); // TODO: ideally, this would be set // based on some // logic }
public byte[] toBinary() { final List<byte[]> bytes = new ArrayList<>(constraintsPerTypeOfDimensionDefinition.size()); int totalBytes = VarintUtils.unsignedIntByteLength(bytes.size()); for (final Entry<Class<? extends NumericDimensionDefinition>, ConstraintData> c : constraintsPerTypeOfDimensionDefinition.entrySet()) { final byte[] className = StringUtils.stringToBinary(c.getKey().getName()); final double min = c.getValue().range.getMin(); final double max = c.getValue().range.getMax(); final int entryLength = className.length + 17 + VarintUtils.unsignedIntByteLength(className.length); final byte isDefault = (byte) (c.getValue().isDefault ? 1 : 0); final ByteBuffer entryBuf = ByteBuffer.allocate(entryLength); VarintUtils.writeUnsignedInt(className.length, entryBuf); entryBuf.put(className); entryBuf.putDouble(min); entryBuf.putDouble(max); entryBuf.put(isDefault); bytes.add(entryBuf.array()); totalBytes += entryLength; } final ByteBuffer buf = ByteBuffer.allocate(totalBytes); VarintUtils.writeUnsignedInt(bytes.size(), buf); for (final byte[] entryBytes : bytes) { buf.put(entryBytes); } return buf.array(); }
/** * Ignores 'default' indicator * * @param other * @return */ public boolean matches(final ConstraintData other) { if (this == other) { return true; } if (range == null) { if (other.range != null) { return false; } } else if (!DoubleMath.fuzzyEquals(range.getMin(), other.range.getMin(), DOUBLE_TOLERANCE) || !DoubleMath.fuzzyEquals(range.getMax(), other.range.getMax(), DOUBLE_TOLERANCE)) { return false; } return true; } }
@Override public NumericData getNumericData(final ArrayWrapper<T> dataElement) { Double min = null, max = null; for (final T element : dataElement.getArray()) { final NumericData data = elementField.getNumericData(element); if ((min == null) || (max == null)) { min = data.getMin(); max = data.getMax(); } else { min = Math.min(min, data.getMin()); max = Math.max(max, data.getMax()); } } if ((min == null) || (max == null)) { return null; } if (min.equals(max)) { return new NumericValue(min); } return new NumericRange(min, max); }
@Override public BinRange[] getNormalizedRanges(final NumericData range) { if (range == null || range.getMax() < range.getMin()) { return new BinRange[] {}; startEpoch.setTimeInMillis((long) range.getMin()); setToEpoch(startEpoch); boolean firstBin = ((long) range.getMin() != startEpochMillis); boolean lastBin = false; do { startMillis = (long) range.getMin(); firstBin = false; } else {
@Override public BinRange[] getNormalizedRanges(final NumericData range) { if (range == null) { return new BinRange[0]; } return new BinRange[] { new BinRange( // by default clamp to the min and max clamp(range.getMin()), clamp(range.getMax()))}; }
@Override public byte[] toBinary() { int byteBufferLength = VarintUtils.unsignedIntByteLength(compareOp.ordinal()); final int dimensions = Math.min(constraints.getDimensionCount(), dimensionFields.length); byteBufferLength += VarintUtils.unsignedIntByteLength(dimensions); final byte[][] lengthDimensionAndQueryBinaries = new byte[dimensions][]; final NumericData[] dataPerDimension = constraints.getDataPerDimension(); for (int d = 0; d < dimensions; d++) { final NumericDimensionField<?> dimension = dimensionFields[d]; final NumericData data = dataPerDimension[d]; final byte[] dimensionBinary = PersistenceUtils.toBinary(dimension); final int currentDimensionByteBufferLength = (16 + dimensionBinary.length + VarintUtils.unsignedIntByteLength(dimensionBinary.length)); final ByteBuffer buf = ByteBuffer.allocate(currentDimensionByteBufferLength); VarintUtils.writeUnsignedInt(dimensionBinary.length, buf); buf.putDouble(data.getMin()); buf.putDouble(data.getMax()); buf.put(dimensionBinary); byteBufferLength += currentDimensionByteBufferLength; lengthDimensionAndQueryBinaries[d] = buf.array(); } final ByteBuffer buf = ByteBuffer.allocate(byteBufferLength); VarintUtils.writeUnsignedInt(compareOp.ordinal(), buf); VarintUtils.writeUnsignedInt(dimensions, buf); for (final byte[] binary : lengthDimensionAndQueryBinaries) { buf.put(binary); } return buf.array(); }
@Override public BinRange[] getNormalizedRanges(NumericData index) { if (!index.isRange()) { BinValue value = getBinnedValue(index.getMin()); return new BinRange[] { new BinRange( false)}; int minBin = (int) Math.ceil((index.getMin() - halfInterval) / interval); int maxBin = (int) Math.ceil((index.getMax() - halfInterval) / interval); if (minBin == maxBin) { double min = (index.getMin() - interval * minBin); double max = (index.getMax() - interval * maxBin); ByteBuffer buf = ByteBuffer.allocate(4); new BinRange( intToBinary(minBin), (index.getMin() - interval * minBin), halfInterval, false);
public static MultiDimensionalNumericData getRangeForId( final byte[] rowId, final NumericDimensionDefinition[] baseDefinitions, final SpaceFillingCurve sfc) { final SFCIdAndBinInfo sfcIdAndBinInfo = getSFCIdAndBinInfo(rowId, baseDefinitions); final MultiDimensionalNumericData numericData = sfc.getRanges(sfcIdAndBinInfo.sfcId); // now we need to unapply the bins to the data, denormalizing the // ranges to the native bounds if (sfcIdAndBinInfo.rowIdOffset > 1) { final NumericData[] data = numericData.getDataPerDimension(); for (final Entry<Integer, byte[]> entry : sfcIdAndBinInfo.binIds.entrySet()) { final int dimension = entry.getKey(); final NumericRange range = baseDefinitions[dimension].getDenormalizedRange( new BinRange( entry.getValue(), data[dimension].getMin(), data[dimension].getMax(), false)); data[dimension] = range; } return new BasicNumericDataset(data); } return numericData; }
latPosition == 0 ? new NumericRange(env.getMinY(), env.getMaxY()) : new NumericRange(env.getMinX(), env.getMaxX()); return ((rangeData[0].getMin() < r.getMax()) || DoubleMath.fuzzyEquals(rangeData[0].getMin(), r.getMax(), DOUBLE_TOLERANCE)) && ((rangeData[0].getMax() > r.getMin()) || DoubleMath.fuzzyEquals(rangeData[0].getMax(), r.getMin(), DOUBLE_TOLERANCE)); new Coordinate[] { new Coordinate( rangeData[longPosition].getMin() - DOUBLE_TOLERANCE, rangeData[latPosition].getMin() - DOUBLE_TOLERANCE), new Coordinate( rangeData[longPosition].getMin() - DOUBLE_TOLERANCE, rangeData[latPosition].getMax() + DOUBLE_TOLERANCE), new Coordinate( new Coordinate( rangeData[longPosition].getMax() + DOUBLE_TOLERANCE, rangeData[latPosition].getMin() - DOUBLE_TOLERANCE), new Coordinate( rangeData[longPosition].getMin() - DOUBLE_TOLERANCE, rangeData[latPosition].getMin() - DOUBLE_TOLERANCE)}).intersects(geometry);
protected boolean validateConstraints( final BasicQueryCompareOp op, final MultiDimensionalNumericData queryRange, final MultiDimensionalNumericData dataRange) { final NumericData[] queryRangePerDimension = queryRange.getDataPerDimension(); final double[] minPerDimension = dataRange.getMinValuesPerDimension(); final double[] maxPerDimension = dataRange.getMaxValuesPerDimension(); boolean ok = true; for (int d = 0; (d < dimensionFields.length) && ok; d++) { ok &= op.compare( minPerDimension[d], maxPerDimension[d], queryRangePerDimension[d].getMin(), queryRangePerDimension[d].getMax()); } return ok; }
/** * Tool can be used custom index strategies to check if the tiles actual intersect with the * provided bounding box. * * @param boxRangeData * @param innerTile * @return */ private boolean checkCoverage( final MultiDimensionalNumericData boxRangeData, final MultiDimensionalNumericData innerTile) { for (int i = 0; i < boxRangeData.getDimensionCount(); i++) { final double i1 = innerTile.getDataPerDimension()[i].getMin(); final double i2 = innerTile.getDataPerDimension()[i].getMax(); final double j1 = boxRangeData.getDataPerDimension()[i].getMin(); final double j2 = boxRangeData.getDataPerDimension()[i].getMax(); final boolean overlaps = ((i1 < j2) || DoubleMath.fuzzyEquals(i1, j2, DOUBLE_TOLERANCE)) && ((i2 > j1) || DoubleMath.fuzzyEquals(i2, j1, DOUBLE_TOLERANCE)); if (!overlaps) { return false; } } return true; }
@SuppressWarnings("unchecked") @Override public PersistentValue<Object>[] toNativeValues(final Time indexValue) { final NumericData value = indexValue.toNumericData(); final Class<?> startBindingClass = nativeStartTimeHandler.attrDesc.getType().getBinding(); final Object startObj = TimeUtils.getTimeValue(startBindingClass, (long) value.getMin()); final Class<?> endBindingClass = nativeEndTimeHandler.attrDesc.getType().getBinding(); final Object endObj = TimeUtils.getTimeValue(endBindingClass, (long) value.getMax()); return new PersistentValue[] { new PersistentValue<>(nativeStartTimeHandler.getFieldName(), startObj), new PersistentValue<>(nativeEndTimeHandler.getFieldName(), endObj),}; }