Search in sources :

Example 31 with ArrayType

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

the class JsonToArrayCast method toArray.

@UsedByGeneratedCode
public static Block toArray(Type arrayType, ConnectorSession connectorSession, Slice json) {
    try {
        List<?> array = (List<?>) stackRepresentationToObject(connectorSession, json, arrayType);
        if (array == null) {
            return null;
        }
        Type elementType = ((ArrayType) arrayType).getElementType();
        BlockBuilder blockBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), array.size());
        for (Object element : array) {
            appendToBlockBuilder(elementType, element, blockBuilder);
        }
        return blockBuilder.build();
    } catch (RuntimeException e) {
        throw new PrestoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to " + arrayType, e);
    }
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) ArrayType(com.facebook.presto.type.ArrayType) Type(com.facebook.presto.spi.type.Type) OperatorType(com.facebook.presto.spi.function.OperatorType) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) TypeJsonUtils.stackRepresentationToObject(com.facebook.presto.type.TypeJsonUtils.stackRepresentationToObject) PrestoException(com.facebook.presto.spi.PrestoException) TypeJsonUtils.appendToBlockBuilder(com.facebook.presto.type.TypeJsonUtils.appendToBlockBuilder) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) UsedByGeneratedCode(com.facebook.presto.annotation.UsedByGeneratedCode)

Example 32 with ArrayType

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

the class TestOrcFileRewriter method testRewrite.

@Test
public void testRewrite() throws Exception {
    ArrayType arrayType = new ArrayType(BIGINT);
    ArrayType arrayOfArrayType = new ArrayType(arrayType);
    MapType mapType = new MapType(createVarcharType(5), BOOLEAN);
    List<Long> columnIds = ImmutableList.of(3L, 7L, 9L, 10L, 11L);
    List<Type> columnTypes = ImmutableList.of(BIGINT, createVarcharType(20), arrayType, mapType, arrayOfArrayType);
    File file = new File(temporary, randomUUID().toString());
    try (OrcFileWriter writer = new OrcFileWriter(columnIds, columnTypes, file)) {
        List<Page> pages = rowPagesBuilder(columnTypes).row(123L, "hello", arrayBlockOf(BIGINT, 1, 2), mapBlockOf(createVarcharType(5), BOOLEAN, "k1", true), arrayBlockOf(arrayType, arrayBlockOf(BIGINT, 5))).row(777L, "sky", arrayBlockOf(BIGINT, 3, 4), mapBlockOf(createVarcharType(5), BOOLEAN, "k2", false), arrayBlockOf(arrayType, arrayBlockOf(BIGINT, 6))).row(456L, "bye", arrayBlockOf(BIGINT, 5, 6), mapBlockOf(createVarcharType(5), BOOLEAN, "k3", true), arrayBlockOf(arrayType, arrayBlockOf(BIGINT, 7))).row(888L, "world", arrayBlockOf(BIGINT, 7, 8), mapBlockOf(createVarcharType(5), BOOLEAN, "k4", true), arrayBlockOf(arrayType, null, arrayBlockOf(BIGINT, 8), null)).row(999L, "done", arrayBlockOf(BIGINT, 9, 10), mapBlockOf(createVarcharType(5), BOOLEAN, "k5", true), arrayBlockOf(arrayType, arrayBlockOf(BIGINT, 9, 10))).build();
        writer.appendPages(pages);
    }
    try (OrcDataSource dataSource = fileOrcDataSource(file)) {
        OrcRecordReader reader = createReader(dataSource, columnIds, columnTypes);
        assertEquals(reader.getReaderRowCount(), 5);
        assertEquals(reader.getFileRowCount(), 5);
        assertEquals(reader.getSplitLength(), file.length());
        assertEquals(reader.nextBatch(), 5);
        Block column0 = reader.readBlock(BIGINT, 0);
        assertEquals(column0.getPositionCount(), 5);
        for (int i = 0; i < 5; i++) {
            assertEquals(column0.isNull(i), false);
        }
        assertEquals(BIGINT.getLong(column0, 0), 123L);
        assertEquals(BIGINT.getLong(column0, 1), 777L);
        assertEquals(BIGINT.getLong(column0, 2), 456L);
        assertEquals(BIGINT.getLong(column0, 3), 888L);
        assertEquals(BIGINT.getLong(column0, 4), 999L);
        Block column1 = reader.readBlock(createVarcharType(20), 1);
        assertEquals(column1.getPositionCount(), 5);
        for (int i = 0; i < 5; i++) {
            assertEquals(column1.isNull(i), false);
        }
        assertEquals(createVarcharType(20).getSlice(column1, 0), utf8Slice("hello"));
        assertEquals(createVarcharType(20).getSlice(column1, 1), utf8Slice("sky"));
        assertEquals(createVarcharType(20).getSlice(column1, 2), utf8Slice("bye"));
        assertEquals(createVarcharType(20).getSlice(column1, 3), utf8Slice("world"));
        assertEquals(createVarcharType(20).getSlice(column1, 4), utf8Slice("done"));
        Block column2 = reader.readBlock(arrayType, 2);
        assertEquals(column2.getPositionCount(), 5);
        for (int i = 0; i < 5; i++) {
            assertEquals(column2.isNull(i), false);
        }
        assertTrue(arrayBlocksEqual(BIGINT, arrayType.getObject(column2, 0), arrayBlockOf(BIGINT, 1, 2)));
        assertTrue(arrayBlocksEqual(BIGINT, arrayType.getObject(column2, 1), arrayBlockOf(BIGINT, 3, 4)));
        assertTrue(arrayBlocksEqual(BIGINT, arrayType.getObject(column2, 2), arrayBlockOf(BIGINT, 5, 6)));
        assertTrue(arrayBlocksEqual(BIGINT, arrayType.getObject(column2, 3), arrayBlockOf(BIGINT, 7, 8)));
        assertTrue(arrayBlocksEqual(BIGINT, arrayType.getObject(column2, 4), arrayBlockOf(BIGINT, 9, 10)));
        Block column3 = reader.readBlock(mapType, 3);
        assertEquals(column3.getPositionCount(), 5);
        for (int i = 0; i < 5; i++) {
            assertEquals(column3.isNull(i), false);
        }
        assertTrue(mapBlocksEqual(createVarcharType(5), BOOLEAN, arrayType.getObject(column3, 0), mapBlockOf(createVarcharType(5), BOOLEAN, "k1", true)));
        assertTrue(mapBlocksEqual(createVarcharType(5), BOOLEAN, arrayType.getObject(column3, 1), mapBlockOf(createVarcharType(5), BOOLEAN, "k2", false)));
        assertTrue(mapBlocksEqual(createVarcharType(5), BOOLEAN, arrayType.getObject(column3, 2), mapBlockOf(createVarcharType(5), BOOLEAN, "k3", true)));
        assertTrue(mapBlocksEqual(createVarcharType(5), BOOLEAN, arrayType.getObject(column3, 3), mapBlockOf(createVarcharType(5), BOOLEAN, "k4", true)));
        assertTrue(mapBlocksEqual(createVarcharType(5), BOOLEAN, arrayType.getObject(column3, 4), mapBlockOf(createVarcharType(5), BOOLEAN, "k5", true)));
        Block column4 = reader.readBlock(arrayOfArrayType, 4);
        assertEquals(column4.getPositionCount(), 5);
        for (int i = 0; i < 5; i++) {
            assertEquals(column4.isNull(i), false);
        }
        assertTrue(arrayBlocksEqual(arrayType, arrayOfArrayType.getObject(column4, 0), arrayBlockOf(arrayType, arrayBlockOf(BIGINT, 5))));
        assertTrue(arrayBlocksEqual(arrayType, arrayOfArrayType.getObject(column4, 1), arrayBlockOf(arrayType, arrayBlockOf(BIGINT, 6))));
        assertTrue(arrayBlocksEqual(arrayType, arrayOfArrayType.getObject(column4, 2), arrayBlockOf(arrayType, arrayBlockOf(BIGINT, 7))));
        assertTrue(arrayBlocksEqual(arrayType, arrayOfArrayType.getObject(column4, 3), arrayBlockOf(arrayType, null, arrayBlockOf(BIGINT, 8), null)));
        assertTrue(arrayBlocksEqual(arrayType, arrayOfArrayType.getObject(column4, 4), arrayBlockOf(arrayType, arrayBlockOf(BIGINT, 9, 10))));
        assertEquals(reader.nextBatch(), -1);
        OrcFileMetadata orcFileMetadata = METADATA_CODEC.fromJson(reader.getUserMetadata().get(OrcFileMetadata.KEY).getBytes());
        assertEquals(orcFileMetadata, new OrcFileMetadata(ImmutableMap.<Long, TypeSignature>builder().put(3L, BIGINT.getTypeSignature()).put(7L, createVarcharType(20).getTypeSignature()).put(9L, arrayType.getTypeSignature()).put(10L, mapType.getTypeSignature()).put(11L, arrayOfArrayType.getTypeSignature()).build()));
    }
    BitSet rowsToDelete = new BitSet(5);
    rowsToDelete.set(1);
    rowsToDelete.set(3);
    rowsToDelete.set(4);
    File newFile = new File(temporary, randomUUID().toString());
    OrcFileInfo info = OrcFileRewriter.rewrite(file, newFile, rowsToDelete);
    assertEquals(info.getRowCount(), 2);
    assertEquals(info.getUncompressedSize(), 78);
    try (OrcDataSource dataSource = fileOrcDataSource(newFile)) {
        OrcRecordReader reader = createReader(dataSource, columnIds, columnTypes);
        assertEquals(reader.getReaderRowCount(), 2);
        assertEquals(reader.getFileRowCount(), 2);
        assertEquals(reader.getSplitLength(), newFile.length());
        assertEquals(reader.nextBatch(), 2);
        Block column0 = reader.readBlock(BIGINT, 0);
        assertEquals(column0.getPositionCount(), 2);
        for (int i = 0; i < 2; i++) {
            assertEquals(column0.isNull(i), false);
        }
        assertEquals(BIGINT.getLong(column0, 0), 123L);
        assertEquals(BIGINT.getLong(column0, 1), 456L);
        Block column1 = reader.readBlock(createVarcharType(20), 1);
        assertEquals(column1.getPositionCount(), 2);
        for (int i = 0; i < 2; i++) {
            assertEquals(column1.isNull(i), false);
        }
        assertEquals(createVarcharType(20).getSlice(column1, 0), utf8Slice("hello"));
        assertEquals(createVarcharType(20).getSlice(column1, 1), utf8Slice("bye"));
        Block column2 = reader.readBlock(arrayType, 2);
        assertEquals(column2.getPositionCount(), 2);
        for (int i = 0; i < 2; i++) {
            assertEquals(column2.isNull(i), false);
        }
        assertTrue(arrayBlocksEqual(BIGINT, arrayType.getObject(column2, 0), arrayBlockOf(BIGINT, 1, 2)));
        assertTrue(arrayBlocksEqual(BIGINT, arrayType.getObject(column2, 1), arrayBlockOf(BIGINT, 5, 6)));
        Block column3 = reader.readBlock(mapType, 3);
        assertEquals(column3.getPositionCount(), 2);
        for (int i = 0; i < 2; i++) {
            assertEquals(column3.isNull(i), false);
        }
        assertTrue(mapBlocksEqual(createVarcharType(5), BOOLEAN, arrayType.getObject(column3, 0), mapBlockOf(createVarcharType(5), BOOLEAN, "k1", true)));
        assertTrue(mapBlocksEqual(createVarcharType(5), BOOLEAN, arrayType.getObject(column3, 1), mapBlockOf(createVarcharType(5), BOOLEAN, "k3", true)));
        Block column4 = reader.readBlock(arrayOfArrayType, 4);
        assertEquals(column4.getPositionCount(), 2);
        for (int i = 0; i < 2; i++) {
            assertEquals(column4.isNull(i), false);
        }
        assertTrue(arrayBlocksEqual(arrayType, arrayOfArrayType.getObject(column4, 0), arrayBlockOf(arrayType, arrayBlockOf(BIGINT, 5))));
        assertTrue(arrayBlocksEqual(arrayType, arrayOfArrayType.getObject(column4, 1), arrayBlockOf(arrayType, arrayBlockOf(BIGINT, 7))));
        assertEquals(reader.nextBatch(), -1);
        OrcFileMetadata orcFileMetadata = METADATA_CODEC.fromJson(reader.getUserMetadata().get(OrcFileMetadata.KEY).getBytes());
        assertEquals(orcFileMetadata, new OrcFileMetadata(ImmutableMap.<Long, TypeSignature>builder().put(3L, BIGINT.getTypeSignature()).put(7L, createVarcharType(20).getTypeSignature()).put(9L, arrayType.getTypeSignature()).put(10L, mapType.getTypeSignature()).put(11L, arrayOfArrayType.getTypeSignature()).build()));
    }
}
Also used : OrcDataSource(com.facebook.presto.orc.OrcDataSource) OrcTestingUtil.fileOrcDataSource(com.facebook.presto.raptor.storage.OrcTestingUtil.fileOrcDataSource) BitSet(java.util.BitSet) Page(com.facebook.presto.spi.Page) OrcRecordReader(com.facebook.presto.orc.OrcRecordReader) MapType(com.facebook.presto.type.MapType) ArrayType(com.facebook.presto.type.ArrayType) ArrayType(com.facebook.presto.type.ArrayType) MapType(com.facebook.presto.type.MapType) Type(com.facebook.presto.spi.type.Type) VarcharType.createVarcharType(com.facebook.presto.spi.type.VarcharType.createVarcharType) TypeSignature(com.facebook.presto.spi.type.TypeSignature) OrcFileInfo(com.facebook.presto.raptor.storage.OrcFileRewriter.OrcFileInfo) Block(com.facebook.presto.spi.block.Block) File(java.io.File) Test(org.testng.annotations.Test)

Example 33 with ArrayType

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

the class TestSerDeUtils method testStructBlock.

@Test
public void testStructBlock() {
    // test simple structs
    InnerStruct innerStruct = new InnerStruct(13, 14L);
    com.facebook.presto.spi.type.Type rowType = new RowType(ImmutableList.of(INTEGER, BIGINT), Optional.empty());
    Block actual = toBinaryBlock(rowType, innerStruct, getInspector(InnerStruct.class));
    Block expected = rowBlockOf(ImmutableList.of(INTEGER, BIGINT), 13, 14L);
    assertBlockEquals(actual, expected);
    // test complex structs
    OuterStruct outerStruct = new OuterStruct();
    outerStruct.byteVal = (byte) 1;
    outerStruct.shortVal = (short) 2;
    outerStruct.intVal = 3;
    outerStruct.longVal = 4L;
    outerStruct.floatVal = 5.01f;
    outerStruct.doubleVal = 6.001d;
    outerStruct.stringVal = "seven";
    outerStruct.byteArray = new byte[] { '2' };
    InnerStruct is1 = new InnerStruct(2, -5L);
    InnerStruct is2 = new InnerStruct(-10, 0L);
    outerStruct.structArray = new ArrayList<>(2);
    outerStruct.structArray.add(is1);
    outerStruct.structArray.add(is2);
    outerStruct.map = new TreeMap<>();
    outerStruct.map.put("twelve", new InnerStruct(0, 5L));
    outerStruct.map.put("fifteen", new InnerStruct(-5, -10L));
    outerStruct.innerStruct = new InnerStruct(18, 19L);
    com.facebook.presto.spi.type.Type innerRowType = new RowType(ImmutableList.of(INTEGER, BIGINT), Optional.empty());
    com.facebook.presto.spi.type.Type arrayOfInnerRowType = new ArrayType(innerRowType);
    com.facebook.presto.spi.type.Type mapOfInnerRowType = new MapType(createUnboundedVarcharType(), innerRowType);
    List<com.facebook.presto.spi.type.Type> outerRowParameterTypes = ImmutableList.of(TINYINT, SMALLINT, INTEGER, BIGINT, REAL, DOUBLE, createUnboundedVarcharType(), createUnboundedVarcharType(), arrayOfInnerRowType, mapOfInnerRowType, innerRowType);
    com.facebook.presto.spi.type.Type outerRowType = new RowType(outerRowParameterTypes, Optional.empty());
    actual = toBinaryBlock(outerRowType, outerStruct, getInspector(OuterStruct.class));
    ImmutableList.Builder<Object> outerRowValues = ImmutableList.builder();
    outerRowValues.add((byte) 1);
    outerRowValues.add((short) 2);
    outerRowValues.add(3);
    outerRowValues.add(4L);
    outerRowValues.add(5.01f);
    outerRowValues.add(6.001d);
    outerRowValues.add("seven");
    outerRowValues.add(new byte[] { '2' });
    outerRowValues.add(arrayBlockOf(innerRowType, rowBlockOf(ImmutableList.of(INTEGER, BIGINT), 2, -5L), rowBlockOf(ImmutableList.of(INTEGER, BIGINT), -10, 0L)));
    BlockBuilder blockBuilder = new InterleavedBlockBuilder(ImmutableList.of(createUnboundedVarcharType(), innerRowType), new BlockBuilderStatus(), 1024);
    createUnboundedVarcharType().writeString(blockBuilder, "fifteen");
    innerRowType.writeObject(blockBuilder, rowBlockOf(ImmutableList.of(INTEGER, BIGINT), -5, -10L));
    createUnboundedVarcharType().writeString(blockBuilder, "twelve");
    innerRowType.writeObject(blockBuilder, rowBlockOf(ImmutableList.of(INTEGER, BIGINT), 0, 5L));
    outerRowValues.add(blockBuilder.build());
    outerRowValues.add(rowBlockOf(ImmutableList.of(INTEGER, BIGINT), 18, 19L));
    assertBlockEquals(actual, rowBlockOf(outerRowParameterTypes, outerRowValues.build().toArray()));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) RowType(com.facebook.presto.type.RowType) InterleavedBlockBuilder(com.facebook.presto.spi.block.InterleavedBlockBuilder) MapType(com.facebook.presto.type.MapType) ArrayType(com.facebook.presto.type.ArrayType) ArrayType(com.facebook.presto.type.ArrayType) MapType(com.facebook.presto.type.MapType) RowType(com.facebook.presto.type.RowType) VarcharType.createUnboundedVarcharType(com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType) Type(java.lang.reflect.Type) Block(com.facebook.presto.spi.block.Block) SerDeUtils.getBlockObject(com.facebook.presto.hive.util.SerDeUtils.getBlockObject) SerDeUtils.serializeObject(com.facebook.presto.hive.util.SerDeUtils.serializeObject) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) InterleavedBlockBuilder(com.facebook.presto.spi.block.InterleavedBlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) Test(org.testng.annotations.Test)

Example 34 with ArrayType

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

the class TestPrestoDriver method testGetColumns.

@Test
public void testGetColumns() throws Exception {
    try (Connection connection = createConnection()) {
        try (ResultSet rs = connection.getMetaData().getColumns(null, null, "tables", "table_name")) {
            assertColumnMetadata(rs);
            assertTrue(rs.next());
            assertEquals(rs.getString("TABLE_CAT"), "blackhole");
            assertEquals(rs.getString("TABLE_SCHEM"), "information_schema");
            assertEquals(rs.getString("TABLE_NAME"), "tables");
            assertEquals(rs.getString("COLUMN_NAME"), "table_name");
            assertEquals(rs.getInt("DATA_TYPE"), Types.LONGNVARCHAR);
            assertTrue(rs.next());
            assertEquals(rs.getString("TABLE_CAT"), "system");
            assertEquals(rs.getString("TABLE_SCHEM"), "information_schema");
            assertTrue(rs.next());
            assertEquals(rs.getString("TABLE_CAT"), "system");
            assertEquals(rs.getString("TABLE_SCHEM"), "jdbc");
            assertTrue(rs.next());
            assertEquals(rs.getString("TABLE_CAT"), TEST_CATALOG);
            assertEquals(rs.getString("TABLE_SCHEM"), "information_schema");
            assertFalse(rs.next());
        }
    }
    try (Connection connection = createConnection()) {
        try (ResultSet rs = connection.getMetaData().getColumns(TEST_CATALOG, null, "tables", "table_name")) {
            assertColumnMetadata(rs);
            assertEquals(readRows(rs).size(), 1);
        }
    }
    try (Connection connection = createConnection()) {
        try (ResultSet rs = connection.getMetaData().getColumns(null, "information_schema", "tables", "table_name")) {
            assertColumnMetadata(rs);
            assertEquals(readRows(rs).size(), 3);
        }
    }
    try (Connection connection = createConnection()) {
        try (ResultSet rs = connection.getMetaData().getColumns(TEST_CATALOG, "information_schema", "tables", "table_name")) {
            assertColumnMetadata(rs);
            assertEquals(readRows(rs).size(), 1);
        }
    }
    try (Connection connection = createConnection()) {
        try (ResultSet rs = connection.getMetaData().getColumns(TEST_CATALOG, "inf%", "tables", "table_name")) {
            assertColumnMetadata(rs);
            assertEquals(readRows(rs).size(), 1);
        }
    }
    try (Connection connection = createConnection()) {
        try (ResultSet rs = connection.getMetaData().getColumns(TEST_CATALOG, "information_schema", "tab%", "table_name")) {
            assertColumnMetadata(rs);
            assertEquals(readRows(rs).size(), 1);
        }
    }
    try (Connection connection = createConnection()) {
        try (ResultSet rs = connection.getMetaData().getColumns(TEST_CATALOG, "information_schema", "tables", "%m%")) {
            assertColumnMetadata(rs);
            assertTrue(rs.next());
            assertEquals(rs.getString("COLUMN_NAME"), "table_schema");
            assertTrue(rs.next());
            assertEquals(rs.getString("COLUMN_NAME"), "table_name");
            assertFalse(rs.next());
        }
    }
    try (Connection connection = createConnection("blackhole", "blackhole");
        Statement statement = connection.createStatement()) {
        assertEquals(statement.executeUpdate("CREATE TABLE test_get_columns_table (" + "c_boolean boolean, " + "c_bigint bigint, " + "c_integer integer, " + "c_smallint smallint, " + "c_tinyint tinyint, " + "c_real real, " + "c_double double, " + "c_varchar_1234 varchar(1234), " + "c_varchar varchar, " + "c_char_345 char(345), " + "c_varbinary varbinary, " + "c_time time, " + "c_time_with_time_zone \"time with time zone\", " + "c_timestamp timestamp, " + "c_timestamp_with_time_zone \"timestamp with time zone\", " + "c_date date, " + "c_decimal_8_2 decimal(8,2), " + "c_decimal_38_0 decimal(38,0), " + "c_array array<bigint>, " + "c_color color" + ")"), 0);
        try (ResultSet rs = connection.getMetaData().getColumns("blackhole", "blackhole", "test_get_columns_table", null)) {
            assertColumnMetadata(rs);
            assertColumnSpec(rs, Types.BOOLEAN, null, null, null, null, BooleanType.BOOLEAN);
            assertColumnSpec(rs, Types.BIGINT, 19L, 10L, null, null, BigintType.BIGINT);
            assertColumnSpec(rs, Types.INTEGER, 10L, 10L, null, null, IntegerType.INTEGER);
            assertColumnSpec(rs, Types.SMALLINT, 5L, 10L, null, null, SmallintType.SMALLINT);
            assertColumnSpec(rs, Types.TINYINT, 3L, 10L, null, null, TinyintType.TINYINT);
            assertColumnSpec(rs, Types.REAL, 24L, 2L, null, null, RealType.REAL);
            assertColumnSpec(rs, Types.DOUBLE, 53L, 2L, null, null, DoubleType.DOUBLE);
            assertColumnSpec(rs, Types.LONGNVARCHAR, 1234L, null, null, 1234L, createVarcharType(1234));
            assertColumnSpec(rs, Types.LONGNVARCHAR, (long) Integer.MAX_VALUE, null, null, (long) Integer.MAX_VALUE, createUnboundedVarcharType());
            assertColumnSpec(rs, Types.CHAR, 345L, null, null, 345L, createCharType(345));
            assertColumnSpec(rs, Types.LONGVARBINARY, (long) Integer.MAX_VALUE, null, null, (long) Integer.MAX_VALUE, VarbinaryType.VARBINARY);
            assertColumnSpec(rs, Types.TIME, 8L, null, null, null, TimeType.TIME);
            assertColumnSpec(rs, Types.TIME_WITH_TIMEZONE, 14L, null, null, null, TimeWithTimeZoneType.TIME_WITH_TIME_ZONE);
            assertColumnSpec(rs, Types.TIMESTAMP, 23L, null, null, null, TimestampType.TIMESTAMP);
            assertColumnSpec(rs, Types.TIMESTAMP_WITH_TIMEZONE, 29L, null, null, null, TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE);
            assertColumnSpec(rs, Types.DATE, 14L, null, null, null, DateType.DATE);
            assertColumnSpec(rs, Types.DECIMAL, 8L, 10L, 2L, null, createDecimalType(8, 2));
            assertColumnSpec(rs, Types.DECIMAL, 38L, 10L, 0L, null, createDecimalType(38, 0));
            assertColumnSpec(rs, Types.ARRAY, null, null, null, null, new ArrayType(BigintType.BIGINT));
            assertColumnSpec(rs, Types.JAVA_OBJECT, null, null, null, null, ColorType.COLOR);
            assertFalse(rs.next());
        }
    }
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Test(org.testng.annotations.Test)

Example 35 with ArrayType

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

the class TestArrayFilterFunction method testNull.

@Test
public void testNull() throws Exception {
    assertFunction("filter(ARRAY [NULL], x -> x IS NULL)", new ArrayType(UNKNOWN), singletonList(null));
    assertFunction("filter(ARRAY [NULL], x -> x IS NOT NULL)", new ArrayType(UNKNOWN), ImmutableList.of());
    assertFunction("filter(ARRAY [CAST (NULL AS INTEGER)], x -> x IS NULL)", new ArrayType(INTEGER), singletonList(null));
    assertFunction("filter(ARRAY [NULL, NULL, NULL], x -> x IS NULL)", new ArrayType(UNKNOWN), asList(null, null, null));
    assertFunction("filter(ARRAY [NULL, NULL, NULL], x -> x IS NOT NULL)", new ArrayType(UNKNOWN), ImmutableList.of());
    assertFunction("filter(ARRAY [25, 26, NULL], x -> x % 2 = 1 OR x IS NULL)", new ArrayType(INTEGER), asList(25, null));
    assertFunction("filter(ARRAY [25.6, 37.3, NULL], x -> x < 30.0 OR x IS NULL)", new ArrayType(DOUBLE), asList(25.6, null));
    assertFunction("filter(ARRAY [true, false, NULL], x -> not x OR x IS NULL)", new ArrayType(BOOLEAN), asList(false, null));
    assertFunction("filter(ARRAY ['abc', 'def', NULL], x -> substr(x, 1, 1) = 'a' OR x IS NULL)", new ArrayType(createVarcharType(3)), asList("abc", null));
    assertFunction("filter(ARRAY [ARRAY ['abc', null, '123'], NULL], x -> x[2] IS NULL OR x IS NULL)", new ArrayType(new ArrayType(createVarcharType(3))), asList(asList("abc", null, "123"), null));
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) Test(org.testng.annotations.Test)

Aggregations

ArrayType (com.facebook.presto.type.ArrayType)71 Test (org.testng.annotations.Test)45 MapType (com.facebook.presto.type.MapType)27 Type (com.facebook.presto.spi.type.Type)26 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)15 Block (com.facebook.presto.spi.block.Block)13 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)13 RowType (com.facebook.presto.type.RowType)12 ImmutableList (com.google.common.collect.ImmutableList)11 Signature (com.facebook.presto.metadata.Signature)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)6 MetadataManager (com.facebook.presto.metadata.MetadataManager)6 MetadataManager.createTestMetadataManager (com.facebook.presto.metadata.MetadataManager.createTestMetadataManager)5 Page (com.facebook.presto.spi.Page)5 InterleavedBlockBuilder (com.facebook.presto.spi.block.InterleavedBlockBuilder)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)4 MaterializedResult (com.facebook.presto.testing.MaterializedResult)4