Search in sources :

Example 16 with ArrayType

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

the class AbstractTestParquetReader method testStructOfMaps.

@Test
public void testStructOfMaps() throws Exception {
    Iterable<Integer> mapKeys = Stream.generate(() -> ThreadLocalRandom.current().nextInt(10_000)).limit(10_000).collect(Collectors.toList());
    Iterable<Integer> intPrimitives = limit(cycle(asList(1, null, 3, null, 5, null, 7, null, null, null, 11, null, 13)), 10_000);
    Iterable<String> stringPrimitives = limit(cycle(asList(null, "value2", "value3", null, null, "value6", "value7")), 10_000);
    Iterable<Map<Integer, String>> maps = createNullableTestMaps(mapKeys, stringPrimitives);
    Iterable<List<String>> stringArrayField = createNullableTestArrays(stringPrimitives);
    List<List> values = createTestStructs(maps, stringArrayField, intPrimitives);
    List<String> structFieldNames = asList("mapIntStringField", "stringArrayField", "intField");
    Type structType = RowType.from(asList(field("mapIntStringField", mapType(INTEGER, VARCHAR)), field("stringArrayField", new ArrayType(VARCHAR)), field("intField", INTEGER)));
    tester.testRoundTrip(getStandardStructObjectInspector(structFieldNames, asList(getStandardMapObjectInspector(javaIntObjectInspector, javaStringObjectInspector), getStandardListObjectInspector(javaStringObjectInspector), javaIntObjectInspector)), values, values, structType);
}
Also used : BigInteger(java.math.BigInteger) ArrayType(com.facebook.presto.common.type.ArrayType) VarcharType.createUnboundedVarcharType(com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType) StructuralTestUtil.mapType(com.facebook.presto.tests.StructuralTestUtil.mapType) ArrayType(com.facebook.presto.common.type.ArrayType) RowType(com.facebook.presto.common.type.RowType) PrimitiveType(org.apache.parquet.schema.PrimitiveType) MessageType(org.apache.parquet.schema.MessageType) Type(com.facebook.presto.common.type.Type) MessageTypeParser.parseMessageType(org.apache.parquet.schema.MessageTypeParser.parseMessageType) DecimalType.createDecimalType(com.facebook.presto.common.type.DecimalType.createDecimalType) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 17 with ArrayType

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

the class AbstractTestParquetReader method testSchemaWithRepeatedOptionalRequiredFields.

@Test
public void testSchemaWithRepeatedOptionalRequiredFields() throws Exception {
    MessageType parquetSchema = parseMessageType("message hive_schema {" + "  optional group address_book {" + "    required binary owner (UTF8);" + "    optional group owner_phone_numbers (LIST) {" + "      repeated group bag {" + "        optional binary array_element (UTF8);" + "      }" + "    }" + "    optional group contacts (LIST) {" + "      repeated group bag {" + "        optional group array_element {" + "          required binary name (UTF8);" + "          optional binary phone_number (UTF8);" + "        }" + "      }" + "    }" + "  }" + "} ");
    Iterable<String> owner = limit(cycle(asList("owner1", "owner2", "owner3")), 50_000);
    Iterable<List<String>> ownerPhoneNumbers = limit(cycle(asList(null, asList("phoneNumber2", "phoneNumber3", null), asList(null, "phoneNumber6", "phoneNumber7"))), 50_000);
    Iterable<String> name = asList("name1", "name2", "name3", "name4", "name5", "name6", "name7");
    Iterable<String> phoneNumber = asList(null, "phoneNumber2", "phoneNumber3", null, null, "phoneNumber6", "phoneNumber7");
    Iterable<List> contact = createNullableTestStructs(name, phoneNumber);
    Iterable<List<List>> contacts = createNullableTestArrays(limit(cycle(contact), 50_000));
    List<List> values = createTestStructs(owner, ownerPhoneNumbers, contacts);
    List<String> addressBookFieldNames = asList("owner", "owner_phone_numbers", "contacts");
    List<String> contactsFieldNames = asList("name", "phone_number");
    Type contactsType = new ArrayType(RowType.from(asList(field("name", VARCHAR), field("phone_number", VARCHAR))));
    Type addressBookType = RowType.from(asList(field("owner", VARCHAR), field("owner_phone_numbers", new ArrayType(VARCHAR)), field("contacts", contactsType)));
    tester.testRoundTrip(getStandardStructObjectInspector(addressBookFieldNames, asList(javaStringObjectInspector, getStandardListObjectInspector(javaStringObjectInspector), getStandardListObjectInspector(getStandardStructObjectInspector(contactsFieldNames, asList(javaStringObjectInspector, javaStringObjectInspector))))), values, values, "address_book", addressBookType, Optional.of(parquetSchema));
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) VarcharType.createUnboundedVarcharType(com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType) StructuralTestUtil.mapType(com.facebook.presto.tests.StructuralTestUtil.mapType) ArrayType(com.facebook.presto.common.type.ArrayType) RowType(com.facebook.presto.common.type.RowType) PrimitiveType(org.apache.parquet.schema.PrimitiveType) MessageType(org.apache.parquet.schema.MessageType) Type(com.facebook.presto.common.type.Type) MessageTypeParser.parseMessageType(org.apache.parquet.schema.MessageTypeParser.parseMessageType) DecimalType.createDecimalType(com.facebook.presto.common.type.DecimalType.createDecimalType) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) MessageType(org.apache.parquet.schema.MessageType) MessageTypeParser.parseMessageType(org.apache.parquet.schema.MessageTypeParser.parseMessageType) Test(org.testng.annotations.Test)

Example 18 with ArrayType

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

the class AbstractTestParquetReader method testStructOfPrimitiveAndArray.

@Test
public void testStructOfPrimitiveAndArray() throws Exception {
    Iterable<List<String>> stringArrayField = createNullableTestArrays(transform(intsBetween(0, 31_234), Object::toString));
    Iterable<Integer> intField = limit(cycle(ImmutableList.of(1, 3, 5, 7, 11, 13, 17)), 31_234);
    List<List> values = createTestStructs(intField, stringArrayField);
    List<String> structFieldNames = asList("intField", "stringArrayField");
    Type structType = RowType.from(asList(field("intField", INTEGER), field("stringArrayField", new ArrayType(VARCHAR))));
    tester.testRoundTrip(getStandardStructObjectInspector(structFieldNames, asList(javaIntObjectInspector, getStandardListObjectInspector(javaStringObjectInspector))), values, values, structType);
}
Also used : BigInteger(java.math.BigInteger) ArrayType(com.facebook.presto.common.type.ArrayType) VarcharType.createUnboundedVarcharType(com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType) StructuralTestUtil.mapType(com.facebook.presto.tests.StructuralTestUtil.mapType) ArrayType(com.facebook.presto.common.type.ArrayType) RowType(com.facebook.presto.common.type.RowType) PrimitiveType(org.apache.parquet.schema.PrimitiveType) MessageType(org.apache.parquet.schema.MessageType) Type(com.facebook.presto.common.type.Type) MessageTypeParser.parseMessageType(org.apache.parquet.schema.MessageTypeParser.parseMessageType) DecimalType.createDecimalType(com.facebook.presto.common.type.DecimalType.createDecimalType) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.testng.annotations.Test)

Example 19 with ArrayType

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

the class AbstractTestParquetReader method testArrayOfMapOfStruct.

@Test
public void testArrayOfMapOfStruct() throws Exception {
    Iterable<Integer> keys = intsBetween(0, 10_000);
    Iterable<List> structs = createNullableTestStructs(transform(intsBetween(0, 10_000), Object::toString), longsBetween(0, 10_000));
    List<String> structFieldNames = asList("stringField", "longField");
    Type structType = RowType.from(asList(field("stringField", VARCHAR), field("longField", BIGINT)));
    Iterable<Map<Integer, List>> maps = createNullableTestMaps(keys, structs);
    List<List<Map<Integer, List>>> values = createTestArrays(maps);
    tester.testRoundTrip(getStandardListObjectInspector(getStandardMapObjectInspector(javaIntObjectInspector, getStandardStructObjectInspector(structFieldNames, asList(javaStringObjectInspector, javaLongObjectInspector)))), values, values, new ArrayType(mapType(INTEGER, structType)));
}
Also used : BigInteger(java.math.BigInteger) ArrayType(com.facebook.presto.common.type.ArrayType) VarcharType.createUnboundedVarcharType(com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType) StructuralTestUtil.mapType(com.facebook.presto.tests.StructuralTestUtil.mapType) ArrayType(com.facebook.presto.common.type.ArrayType) RowType(com.facebook.presto.common.type.RowType) PrimitiveType(org.apache.parquet.schema.PrimitiveType) MessageType(org.apache.parquet.schema.MessageType) Type(com.facebook.presto.common.type.Type) MessageTypeParser.parseMessageType(org.apache.parquet.schema.MessageTypeParser.parseMessageType) DecimalType.createDecimalType(com.facebook.presto.common.type.DecimalType.createDecimalType) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 20 with ArrayType

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

the class AbstractTestParquetReader method testSingleLevelArrayOfMapOfStruct.

@Test
public void testSingleLevelArrayOfMapOfStruct() throws Exception {
    Iterable<Integer> keys = intsBetween(0, 10_000);
    Iterable<List> structs = createNullableTestStructs(transform(intsBetween(0, 10_000), Object::toString), longsBetween(0, 10_000));
    List<String> structFieldNames = asList("stringField", "longField");
    Type structType = RowType.from(asList(field("stringField", VARCHAR), field("longField", BIGINT)));
    Iterable<Map<Integer, List>> maps = createTestMaps(keys, structs);
    List<List<Map<Integer, List>>> values = createTestArrays(maps);
    tester.testSingleLevelArraySchemaRoundTrip(getStandardListObjectInspector(getStandardMapObjectInspector(javaIntObjectInspector, getStandardStructObjectInspector(structFieldNames, asList(javaStringObjectInspector, javaLongObjectInspector)))), values, values, new ArrayType(mapType(INTEGER, structType)));
}
Also used : BigInteger(java.math.BigInteger) ArrayType(com.facebook.presto.common.type.ArrayType) VarcharType.createUnboundedVarcharType(com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType) StructuralTestUtil.mapType(com.facebook.presto.tests.StructuralTestUtil.mapType) ArrayType(com.facebook.presto.common.type.ArrayType) RowType(com.facebook.presto.common.type.RowType) PrimitiveType(org.apache.parquet.schema.PrimitiveType) MessageType(org.apache.parquet.schema.MessageType) Type(com.facebook.presto.common.type.Type) MessageTypeParser.parseMessageType(org.apache.parquet.schema.MessageTypeParser.parseMessageType) DecimalType.createDecimalType(com.facebook.presto.common.type.DecimalType.createDecimalType) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) HashMap(java.util.HashMap) 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