use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class BingTileFunctions method geometryToDissolvedBingTiles.
@Description("Given a geometry and a maximum zoom level, returns the minimum set of dissolved Bing tiles that fully covers that geometry")
@ScalarFunction("geometry_to_dissolved_bing_tiles")
@SqlType("array(" + BingTileType.NAME + ")")
public static Block geometryToDissolvedBingTiles(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(StandardTypes.INTEGER) long maxZoomLevel) {
OGCGeometry ogcGeometry = deserialize(input);
if (ogcGeometry.isEmpty()) {
return EMPTY_TILE_ARRAY;
}
List<BingTile> covering = findDissolvedTileCovering(ogcGeometry, toIntExact(maxZoomLevel));
BlockBuilder blockBuilder = BIGINT.createBlockBuilder(null, covering.size());
for (BingTile tile : covering) {
BIGINT.writeLong(blockBuilder, tile.encode());
}
return blockBuilder.build();
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class BingTileFunctions method bingTilesAround.
@Description("Given a (longitude, latitude) point, returns the surrounding Bing tiles at the specified zoom level")
@ScalarFunction("bing_tiles_around")
@SqlType("array(" + BingTileType.NAME + ")")
public static Block bingTilesAround(@SqlType(StandardTypes.DOUBLE) double latitude, @SqlType(StandardTypes.DOUBLE) double longitude, @SqlType(StandardTypes.INTEGER) long zoomLevel) {
checkLatitude(latitude, LATITUDE_OUT_OF_RANGE);
checkLongitude(longitude, LONGITUDE_OUT_OF_RANGE);
checkZoomLevel(zoomLevel);
long mapSize = mapSize(toIntExact(zoomLevel));
long maxTileIndex = (mapSize / TILE_PIXELS) - 1;
int tileX = longitudeToTileX(longitude, mapSize);
int tileY = latitudeToTileY(latitude, mapSize);
BlockBuilder blockBuilder = BIGINT.createBlockBuilder(null, 9);
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
int x = tileX + i;
int y = tileY + j;
if (x >= 0 && x <= maxTileIndex && y >= 0 && y <= maxTileIndex) {
BIGINT.writeLong(blockBuilder, BingTile.fromCoordinates(x, y, toIntExact(zoomLevel)).encode());
}
}
}
return blockBuilder.build();
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class GeoFunctions method geometryNearestPoints.
@SqlNullable
@Description("Return the closest points on the two geometries")
@ScalarFunction("geometry_nearest_points")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block geometryNearestPoints(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
Geometry leftGeometry = deserialize(left);
Geometry rightGeometry = deserialize(right);
if (leftGeometry.isEmpty() || rightGeometry.isEmpty()) {
return null;
}
try {
Coordinate[] nearestCoordinates = DistanceOp.nearestPoints(leftGeometry, rightGeometry);
BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, 2);
GEOMETRY.writeSlice(blockBuilder, serialize(createJtsPoint(nearestCoordinates[0])));
GEOMETRY.writeSlice(blockBuilder, serialize(createJtsPoint(nearestCoordinates[1])));
return blockBuilder.build();
} catch (TopologyException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);
}
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class GeoFunctions method stPoints.
@SqlNullable
@Description("Returns an array of points in a geometry")
@ScalarFunction("ST_Points")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block stPoints(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
Geometry geometry = deserialize(input);
if (geometry.isEmpty()) {
return null;
}
BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, geometry.getNumPoints());
buildPointsBlock(geometry, blockBuilder);
return blockBuilder.build();
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class TestHashAggregationOperator method testHashBuilderResize.
@Test(dataProvider = "hashEnabledAndMemoryLimitForMergeValues")
public void testHashBuilderResize(boolean hashEnabled, boolean spillEnabled, boolean revokeMemoryWhenAddingPages, long memoryLimitForMerge, long memoryLimitForMergeWithMemory) {
BlockBuilder builder = VARCHAR.createBlockBuilder(null, 1, MAX_BLOCK_SIZE_IN_BYTES);
// this must be larger than MAX_BLOCK_SIZE_IN_BYTES, 64K
VARCHAR.writeSlice(builder, Slices.allocate(200_000));
builder.build();
List<Integer> hashChannels = Ints.asList(0);
RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, hashChannels, VARCHAR);
List<Page> input = rowPagesBuilder.addSequencePage(10, 100).addBlocksPage(builder.build()).addSequencePage(10, 100).build();
DriverContext driverContext = createDriverContext(memoryLimitForMerge);
HashAggregationOperatorFactory operatorFactory = new HashAggregationOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(VARCHAR), hashChannels, ImmutableList.of(), Step.SINGLE, false, ImmutableList.of(COUNT.bind(ImmutableList.of(0), Optional.empty())), rowPagesBuilder.getHashChannel(), Optional.empty(), 100_000, Optional.of(new DataSize(16, MEGABYTE)), spillEnabled, succinctBytes(memoryLimitForMerge), succinctBytes(memoryLimitForMergeWithMemory), spillerFactory, joinCompiler, false);
toPages(operatorFactory, driverContext, input, revokeMemoryWhenAddingPages);
}
Aggregations