use of com.facebook.presto.geospatial.Rectangle in project presto by prestodb.
the class SphericalGeoFunctions method spatialPartitions.
@ScalarFunction
@SqlNullable
@Description("Returns an array of spatial partition IDs for a geometry representing a set of points within specified distance from the input geometry")
@SqlType("array(int)")
public static Block spatialPartitions(@SqlType(KdbTreeType.NAME) Object kdbTree, @SqlType(SPHERICAL_GEOGRAPHY_TYPE_NAME) Slice geometry, @SqlType(DOUBLE) double distance) {
if (isNaN(distance)) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is NaN");
}
if (isInfinite(distance)) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is infinite");
}
if (distance < 0) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "distance is negative");
}
Envelope envelope = deserializeEnvelope(geometry);
if (envelope.isEmpty()) {
return null;
}
Rectangle expandedEnvelope2D = new Rectangle(envelope.getXMin() - distance, envelope.getYMin() - distance, envelope.getXMax() + distance, envelope.getYMax() + distance);
return GeoFunctions.spatialPartitions((KdbTree) kdbTree, expandedEnvelope2D);
}
use of com.facebook.presto.geospatial.Rectangle in project presto by prestodb.
the class TestHilbertIndex method testDegenerateVerticalRectangle.
@Test
public void testDegenerateVerticalRectangle() {
HilbertIndex hilbert = new HilbertIndex(new Rectangle(0, 0, 0, 4));
assertEquals(hilbert.indexOf(0., 0.), 0);
assertTrue(hilbert.indexOf(0., 1.) < hilbert.indexOf(0., 2.));
assertEquals(hilbert.indexOf(2., 0.), Long.MAX_VALUE);
assertEquals(hilbert.indexOf(2., 2.), Long.MAX_VALUE);
}
use of com.facebook.presto.geospatial.Rectangle in project presto by prestodb.
the class TestHilbertIndex method testOutOfBounds.
@Test
public void testOutOfBounds() {
HilbertIndex hilbert = new HilbertIndex(new Rectangle(0, 0, 1, 1));
assertEquals(hilbert.indexOf(2., 2.), Long.MAX_VALUE);
}
use of com.facebook.presto.geospatial.Rectangle in project presto by prestodb.
the class TestHilbertIndex method testOrder.
@Test
public void testOrder() {
HilbertIndex hilbert = new HilbertIndex(new Rectangle(0, 0, 4, 4));
long h0 = hilbert.indexOf(0., 0.);
long h1 = hilbert.indexOf(1., 1.);
long h2 = hilbert.indexOf(1., 3.);
long h3 = hilbert.indexOf(3., 3.);
long h4 = hilbert.indexOf(3., 1.);
assertTrue(h0 < h1);
assertTrue(h1 < h2);
assertTrue(h2 < h3);
assertTrue(h3 < h4);
}
use of com.facebook.presto.geospatial.Rectangle in project presto by prestodb.
the class SpatialPartitioningInternalAggregateFunction method input.
@InputFunction
public static void input(SpatialPartitioningState state, @SqlType(GEOMETRY_TYPE_NAME) Slice slice, @SqlType(INTEGER) long partitionCount) {
Envelope envelope = deserializeEnvelope(slice);
if (envelope.isEmpty()) {
return;
}
if (state.getCount() == 0) {
state.setPartitionCount(toIntExact(partitionCount));
state.setSamples(new ArrayList<>());
}
// use reservoir sampling
Rectangle extent = new Rectangle(envelope.getXMin(), envelope.getYMin(), envelope.getXMax(), envelope.getYMax());
List<Rectangle> samples = state.getSamples();
if (samples.size() <= MAX_SAMPLE_COUNT) {
samples.add(extent);
} else {
long sampleIndex = ThreadLocalRandom.current().nextLong(state.getCount());
if (sampleIndex < MAX_SAMPLE_COUNT) {
samples.set(toIntExact(sampleIndex), extent);
}
}
state.setCount(state.getCount() + 1);
}
Aggregations