Search in sources :

Example 71 with BlockBuilder

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();
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 72 with BlockBuilder

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();
}
Also used : GeometryUtils.disjoint(com.facebook.presto.geospatial.GeometryUtils.disjoint) Point(com.esri.core.geometry.Point) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 73 with BlockBuilder

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);
    }
}
Also used : GeometryUtils.wktFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCGeometry.createFromEsriGeometry(com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry) Geometry(org.locationtech.jts.geom.Geometry) GeometryUtils.jsonFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry) Coordinate(org.locationtech.jts.geom.Coordinate) PrestoException(com.facebook.presto.spi.PrestoException) TopologyException(org.locationtech.jts.geom.TopologyException) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 74 with BlockBuilder

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();
}
Also used : GeometryUtils.wktFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCGeometry.createFromEsriGeometry(com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry) Geometry(org.locationtech.jts.geom.Geometry) GeometryUtils.jsonFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 75 with BlockBuilder

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);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) RowPagesBuilder(com.facebook.presto.RowPagesBuilder) DataSize(io.airlift.units.DataSize) Page(com.facebook.presto.common.Page) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) HashAggregationOperatorFactory(com.facebook.presto.operator.HashAggregationOperator.HashAggregationOperatorFactory) Test(org.testng.annotations.Test)

Aggregations

BlockBuilder (com.facebook.presto.common.block.BlockBuilder)493 Block (com.facebook.presto.common.block.Block)124 Test (org.testng.annotations.Test)106 Slice (io.airlift.slice.Slice)85 Type (com.facebook.presto.common.type.Type)76 Page (com.facebook.presto.common.Page)49 SqlType (com.facebook.presto.spi.function.SqlType)46 ArrayType (com.facebook.presto.common.type.ArrayType)44 MapType (com.facebook.presto.common.type.MapType)32 RowType (com.facebook.presto.common.type.RowType)28 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)26 RowBlockBuilder (com.facebook.presto.common.block.RowBlockBuilder)22 PrestoException (com.facebook.presto.spi.PrestoException)22 PageBuilder (com.facebook.presto.common.PageBuilder)21 StructuralTestUtil.appendToBlockBuilder (com.facebook.presto.util.StructuralTestUtil.appendToBlockBuilder)21 Map (java.util.Map)21 UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)20 BlockAssertions.createLongsBlock (com.facebook.presto.block.BlockAssertions.createLongsBlock)19 DictionaryBlock (com.facebook.presto.common.block.DictionaryBlock)18 MapBlockBuilder (com.facebook.presto.common.block.MapBlockBuilder)18