Search in sources :

Example 51 with ArrayType

use of com.facebook.presto.common.type.ArrayType in project presto by prestodb.

the class TestTypeConversions method testConvertStringArrayField.

@Test
public void testConvertStringArrayField() {
    Field field = Field.newBuilder("test", STRING).setMode(REPEATED).build();
    ColumnMetadata metadata = Conversions.toColumnMetadata(field);
    assertThat(metadata.getType()).isEqualTo(new ArrayType(VarcharType.VARCHAR));
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) Field(com.google.cloud.bigquery.Field) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) Test(org.testng.annotations.Test)

Example 52 with ArrayType

use of com.facebook.presto.common.type.ArrayType in project presto by prestodb.

the class TestGeoFunctions method testSTGeometries.

@Test
public void testSTGeometries() {
    assertFunction("ST_Geometries(ST_GeometryFromText('POINT EMPTY'))", new ArrayType(GEOMETRY), null);
    assertSTGeometries("POINT (1 5)", "POINT (1 5)");
    assertSTGeometries("LINESTRING (77.29 29.07, 77.42 29.26, 77.27 29.31, 77.29 29.07)", "LINESTRING (77.29 29.07, 77.42 29.26, 77.27 29.31, 77.29 29.07)");
    assertSTGeometries("POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))", "POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))");
    assertSTGeometries("MULTIPOINT (1 2, 4 8, 16 32)", "POINT (1 2)", "POINT (4 8)", "POINT (16 32)");
    assertSTGeometries("MULTILINESTRING ((1 1, 2 2))", "LINESTRING (1 1, 2 2)");
    assertSTGeometries("MULTIPOLYGON (((0 0, 0 1, 1 1, 1 0, 0 0)), ((1 1, 3 1, 3 3, 1 3, 1 1)))", "POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))", "POLYGON ((1 1, 1 3, 3 3, 3 1, 1 1))");
    assertSTGeometries("GEOMETRYCOLLECTION (POINT (2 3), LINESTRING (2 3, 3 4))", "POINT (2 3)", "LINESTRING (2 3, 3 4)");
    assertSTGeometries("GEOMETRYCOLLECTION(MULTIPOINT(0 0, 1 1), GEOMETRYCOLLECTION(MULTILINESTRING((2 2, 3 3))))", "MULTIPOINT ((0 0), (1 1))", "GEOMETRYCOLLECTION (MULTILINESTRING ((2 2, 3 3)))");
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) Test(org.testng.annotations.Test)

Example 53 with ArrayType

use of com.facebook.presto.common.type.ArrayType in project presto by prestodb.

the class TestGeoFunctions method testSTPoints.

@Test
public void testSTPoints() {
    assertFunction("ST_Points(ST_GeometryFromText('LINESTRING EMPTY'))", new ArrayType(GEOMETRY), null);
    assertSTPoints("LINESTRING (0 0, 0 0)", "0 0", "0 0");
    assertSTPoints("LINESTRING (8 4, 3 9, 8 4)", "8 4", "3 9", "8 4");
    assertSTPoints("LINESTRING (8 4, 3 9, 5 6)", "8 4", "3 9", "5 6");
    assertSTPoints("LINESTRING (8 4, 3 9, 5 6, 3 9, 8 4)", "8 4", "3 9", "5 6", "3 9", "8 4");
    assertFunction("ST_Points(ST_GeometryFromText('POLYGON EMPTY'))", new ArrayType(GEOMETRY), null);
    assertSTPoints("POLYGON ((8 4, 3 9, 5 6, 8 4))", "8 4", "5 6", "3 9", "8 4");
    assertSTPoints("POLYGON ((8 4, 3 9, 5 6, 7 2, 8 4))", "8 4", "7 2", "5 6", "3 9", "8 4");
    assertFunction("ST_Points(ST_GeometryFromText('POINT EMPTY'))", new ArrayType(GEOMETRY), null);
    assertSTPoints("POINT (0 0)", "0 0");
    assertSTPoints("POINT (0 1)", "0 1");
    assertFunction("ST_Points(ST_GeometryFromText('MULTIPOINT EMPTY'))", new ArrayType(GEOMETRY), null);
    assertSTPoints("MULTIPOINT (0 0)", "0 0");
    assertSTPoints("MULTIPOINT (0 0, 1 2)", "0 0", "1 2");
    assertFunction("ST_Points(ST_GeometryFromText('MULTILINESTRING EMPTY'))", new ArrayType(GEOMETRY), null);
    assertSTPoints("MULTILINESTRING ((0 0, 1 1), (2 3, 3 2))", "0 0", "1 1", "2 3", "3 2");
    assertSTPoints("MULTILINESTRING ((0 0, 1 1, 1 2), (2 3, 3 2, 5 4))", "0 0", "1 1", "1 2", "2 3", "3 2", "5 4");
    assertSTPoints("MULTILINESTRING ((0 0, 1 1, 1 2), (1 2, 3 2, 5 4))", "0 0", "1 1", "1 2", "1 2", "3 2", "5 4");
    assertFunction("ST_Points(ST_GeometryFromText('MULTIPOLYGON EMPTY'))", new ArrayType(GEOMETRY), null);
    assertSTPoints("MULTIPOLYGON (((0 0, 4 0, 4 4, 0 4, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1)), ((-1 -1, -1 -2, -2 -2, -2 -1, -1 -1)))", "0 0", "0 4", "4 4", "4 0", "0 0", "1 1", "2 1", "2 2", "1 2", "1 1", "-1 -1", "-1 -2", "-2 -2", "-2 -1", "-1 -1");
    assertFunction("ST_Points(ST_GeometryFromText('GEOMETRYCOLLECTION EMPTY'))", new ArrayType(GEOMETRY), null);
    String geometryCollection = String.join("", "GEOMETRYCOLLECTION(", "          POINT ( 0 1 ),", "          LINESTRING ( 0 3, 3 4 ),", "          POLYGON (( 2 0, 2 3, 0 2, 2 0 )),", "          POLYGON (( 3 0, 3 3, 6 3, 6 0, 3 0 ),", "                   ( 5 1, 4 2, 5 2, 5 1 )),", "          MULTIPOLYGON (", "                  (( 0 5, 0 8, 4 8, 4 5, 0 5 ),", "                   ( 1 6, 3 6, 2 7, 1 6 )),", "                  (( 5 4, 5 8, 6 7, 5 4 ))", "           )", ")");
    assertSTPoints(geometryCollection, "0 1", "0 3", "3 4", "2 0", "0 2", "2 3", "2 0", "3 0", "3 3", "6 3", "6 0", "3 0", "5 1", "5 2", "4 2", "5 1", "0 5", "0 8", "4 8", "4 5", "0 5", "1 6", "3 6", "2 7", "1 6", "5 4", "5 8", "6 7", "5 4");
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) Test(org.testng.annotations.Test)

Example 54 with ArrayType

use of com.facebook.presto.common.type.ArrayType in project presto by prestodb.

the class TestGeoFunctions method testSTGeometryFromBinary.

@Test
public void testSTGeometryFromBinary() {
    assertFunction("ST_GeomFromBinary(null)", GEOMETRY, null);
    // empty geometries
    assertGeomFromBinary("POINT EMPTY");
    assertGeomFromBinary("MULTIPOINT EMPTY");
    assertGeomFromBinary("LINESTRING EMPTY");
    assertGeomFromBinary("MULTILINESTRING EMPTY");
    assertGeomFromBinary("POLYGON EMPTY");
    assertGeomFromBinary("MULTIPOLYGON EMPTY");
    assertGeomFromBinary("GEOMETRYCOLLECTION EMPTY");
    // valid nonempty geometries
    assertGeomFromBinary("POINT (1 2)");
    assertGeomFromBinary("MULTIPOINT ((1 2), (3 4))");
    assertGeomFromBinary("LINESTRING (0 0, 1 2, 3 4)");
    assertGeomFromBinary("MULTILINESTRING ((1 1, 5 1), (2 4, 4 4))");
    assertGeomFromBinary("POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))");
    assertGeomFromBinary("POLYGON ((0 0, 0 3, 3 3, 3 0, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1))");
    assertGeomFromBinary("MULTIPOLYGON (((1 1, 1 3, 3 3, 3 1, 1 1)), ((2 4, 2 6, 6 6, 6 4, 2 4)))");
    assertGeomFromBinary("GEOMETRYCOLLECTION (POINT (1 2), LINESTRING (0 0, 1 2, 3 4), POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0)))");
    // array of geometries
    assertFunction("transform(array[ST_AsBinary(ST_Point(1, 2)), ST_AsBinary(ST_Point(3, 4))], wkb -> ST_AsText(ST_GeomFromBinary(wkb)))", new ArrayType(VARCHAR), ImmutableList.of("POINT (1 2)", "POINT (3 4)"));
    // invalid geometries
    assertGeomFromBinary("MULTIPOINT ((0 0), (0 1), (1 1), (0 1))");
    assertGeomFromBinary("LINESTRING (0 0, 0 1, 0 1, 1 1, 1 0, 0 0)");
    // invalid binary
    assertInvalidFunction("ST_GeomFromBinary(from_hex('deadbeef'))", "Invalid WKB");
    assertInvalidFunction("ST_AsBinary(ST_GeometryFromText('POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))'))", INVALID_FUNCTION_ARGUMENT, "Invalid geometry: corrupted geometry");
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) Test(org.testng.annotations.Test)

Example 55 with ArrayType

use of com.facebook.presto.common.type.ArrayType in project presto by prestodb.

the class TestBingTileFunctions method testBingTilesAroundEdge.

@Test
public void testBingTilesAroundEdge() {
    // Different zoom Level
    assertFunction("transform(bing_tiles_around(-85.05112878, 0, 1), x -> bing_tile_quadkey(x))", new ArrayType(VARCHAR), ImmutableList.of("0", "2", "1", "3"));
    assertFunction("transform(bing_tiles_around(-85.05112878, 0, 3), x -> bing_tile_quadkey(x))", new ArrayType(VARCHAR), ImmutableList.of("231", "233", "320", "322", "321", "323"));
    assertFunction("transform(bing_tiles_around(-85.05112878, 0, 15), x -> bing_tile_quadkey(x))", new ArrayType(VARCHAR), ImmutableList.of("233333333333331", "233333333333333", "322222222222220", "322222222222222", "322222222222221", "322222222222223"));
    // Different Edges
    // Starting Edge 2,3
    assertFunction("transform(bing_tiles_around(-85.05112878, 0, 2), x -> bing_tile_quadkey(x))", new ArrayType(VARCHAR), ImmutableList.of("21", "23", "30", "32", "31", "33"));
    assertFunction("transform(bing_tiles_around(85.05112878, 0, 2), x -> bing_tile_quadkey(x))", new ArrayType(VARCHAR), ImmutableList.of("01", "03", "10", "12", "11", "13"));
    assertFunction("transform(bing_tiles_around(0, 180, 2), x -> bing_tile_quadkey(x))", new ArrayType(VARCHAR), ImmutableList.of("12", "30", "32", "13", "31", "33"));
    assertFunction("transform(bing_tiles_around(0, -180, 2), x -> bing_tile_quadkey(x))", new ArrayType(VARCHAR), ImmutableList.of("02", "20", "22", "03", "21", "23"));
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) Test(org.testng.annotations.Test)

Aggregations

ArrayType (com.facebook.presto.common.type.ArrayType)287 Test (org.testng.annotations.Test)219 Type (com.facebook.presto.common.type.Type)99 RowType (com.facebook.presto.common.type.RowType)79 ArrayList (java.util.ArrayList)58 ImmutableList (com.google.common.collect.ImmutableList)54 List (java.util.List)51 MapType (com.facebook.presto.common.type.MapType)39 DecimalType.createDecimalType (com.facebook.presto.common.type.DecimalType.createDecimalType)36 Arrays.asList (java.util.Arrays.asList)34 Collections.singletonList (java.util.Collections.singletonList)33 MessageType (org.apache.parquet.schema.MessageType)30 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)28 VarcharType.createUnboundedVarcharType (com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType)27 MessageTypeParser.parseMessageType (org.apache.parquet.schema.MessageTypeParser.parseMessageType)27 InternalAggregationFunction (com.facebook.presto.operator.aggregation.InternalAggregationFunction)26 PrimitiveType (org.apache.parquet.schema.PrimitiveType)26 StructuralTestUtil.mapType (com.facebook.presto.tests.StructuralTestUtil.mapType)24 Block (com.facebook.presto.common.block.Block)23 DecimalType (com.facebook.presto.common.type.DecimalType)17