Search in sources :

Example 6 with StructType

use of org.apache.parquet.thrift.struct.ThriftType.StructType in project parquet-mr by apache.

the class TestThriftRecordConverter method constructorDoesNotRequireStructOrUnionTypeMeta.

@Test
public void constructorDoesNotRequireStructOrUnionTypeMeta() throws Exception {
    String jsonWithNoStructOrUnionMeta = Strings.join(Files.readAllLines(new File("src/test/resources/org/apache/parquet/thrift/StructWithUnionV1NoStructOrUnionMeta.json"), Charset.forName("UTF-8")), "\n");
    StructType noStructOrUnionMeta = (StructType) ThriftType.fromJSON(jsonWithNoStructOrUnionMeta);
    // this used to throw, see PARQUET-346
    new ThriftRecordConverter<StructWithUnionV1>(new ThriftReader<StructWithUnionV1>() {

        @Override
        public StructWithUnionV1 readOneRecord(TProtocol protocol) throws TException {
            return null;
        }
    }, "name", new ThriftSchemaConverter().convert(StructWithUnionV1.class), noStructOrUnionMeta);
}
Also used : StructWithUnionV1(org.apache.parquet.thrift.test.compat.StructWithUnionV1) TException(org.apache.thrift.TException) StructType(org.apache.parquet.thrift.struct.ThriftType.StructType) TProtocol(org.apache.thrift.protocol.TProtocol) File(java.io.File) Test(org.junit.Test)

Example 7 with StructType

use of org.apache.parquet.thrift.struct.ThriftType.StructType in project parquet-mr by apache.

the class TestParquetWriteProtocol method validateThrift.

private void validateThrift(String[] expectations, TBase<?, ?> a) throws TException {
    final ThriftSchemaConverter thriftSchemaConverter = new ThriftSchemaConverter();
    // System.out.println(a);
    final Class<TBase<?, ?>> class1 = (Class<TBase<?, ?>>) a.getClass();
    final MessageType schema = thriftSchemaConverter.convert(class1);
    LOG.info("{}", schema);
    final StructType structType = thriftSchemaConverter.toStructType(class1);
    ExpectationValidatingRecordConsumer recordConsumer = new ExpectationValidatingRecordConsumer(new ArrayDeque<String>(Arrays.asList(expectations)));
    final MessageColumnIO columnIO = new ColumnIOFactory().getColumnIO(schema);
    ParquetWriteProtocol p = new ParquetWriteProtocol(new RecordConsumerLoggingWrapper(recordConsumer), columnIO, structType);
    a.write(p);
}
Also used : StructType(org.apache.parquet.thrift.struct.ThriftType.StructType) RecordConsumerLoggingWrapper(org.apache.parquet.io.RecordConsumerLoggingWrapper) ParquetWriteProtocol(org.apache.parquet.thrift.ParquetWriteProtocol) ExpectationValidatingRecordConsumer(org.apache.parquet.io.ExpectationValidatingRecordConsumer) MessageColumnIO(org.apache.parquet.io.MessageColumnIO) ColumnIOFactory(org.apache.parquet.io.ColumnIOFactory) ThriftSchemaConverter(org.apache.parquet.thrift.ThriftSchemaConverter) TBase(org.apache.thrift.TBase) MessageType(org.apache.parquet.schema.MessageType)

Example 8 with StructType

use of org.apache.parquet.thrift.struct.ThriftType.StructType in project parquet-mr by apache.

the class TestThriftMetaData method testToStringDoesNotThrow.

/**
 * Previously, ThriftMetaData.toString would try to instantiate thriftClassName,
 * but there is no guarantee that that class is on the classpath, and it is in fact
 * normal for that to be the case (for example, when a file was written with TBase objects
 * but is being read with scrooge objects).
 *
 * See PARQUET-345
 */
@Test
public void testToStringDoesNotThrow() {
    StructType descriptor = new StructType(new ArrayList<ThriftField>(), StructOrUnionType.STRUCT);
    ThriftMetaData tmd = new ThriftMetaData("non existent class!!!", descriptor);
    assertEquals("ThriftMetaData(thriftClassName: non existent class!!!, descriptor: {\n" + "  \"id\" : \"STRUCT\",\n" + "  \"children\" : [ ],\n" + "  \"structOrUnionType\" : \"STRUCT\"\n" + "})", tmd.toString());
    tmd = new ThriftMetaData("non existent class!!!", null);
    assertEquals("ThriftMetaData(thriftClassName: non existent class!!!, descriptor: null)", tmd.toString());
}
Also used : StructType(org.apache.parquet.thrift.struct.ThriftType.StructType) ThriftField(org.apache.parquet.thrift.struct.ThriftField) Test(org.junit.Test)

Example 9 with StructType

use of org.apache.parquet.thrift.struct.ThriftType.StructType in project parquet-mr by apache.

the class TestFieldsPath method testFieldsPath.

@Test
public void testFieldsPath() {
    StructType person = ThriftSchemaConverter.toStructType(Person.class);
    List<String> paths = PrimitivePathVisitor.visit(person, ".");
    assertEquals(Arrays.asList("name.first_name", "name.last_name", "id", "email", "phones.number", "phones.type"), paths);
    paths = PrimitivePathVisitor.visit(person, "/");
    assertEquals(Arrays.asList("name/first_name", "name/last_name", "id", "email", "phones/number", "phones/type"), paths);
    StructType structInMap = ThriftSchemaConverter.toStructType(TestStructInMap.class);
    paths = PrimitivePathVisitor.visit(structInMap, ".");
    assertEquals(Arrays.asList("name", "names.key", "names.value.name.first_name", "names.value.name.last_name", "names.value.phones.key", "names.value.phones.value", "name_to_id.key", "name_to_id.value"), paths);
    paths = PrimitivePathVisitor.visit(structInMap, "/");
    assertEquals(Arrays.asList("name", "names/key", "names/value/name/first_name", "names/value/name/last_name", "names/value/phones/key", "names/value/phones/value", "name_to_id/key", "name_to_id/value"), paths);
}
Also used : StructType(org.apache.parquet.thrift.struct.ThriftType.StructType) Test(org.junit.Test)

Example 10 with StructType

use of org.apache.parquet.thrift.struct.ThriftType.StructType in project parquet-mr by apache.

the class TestThriftType method testWriteUnionInfo.

@Test
public void testWriteUnionInfo() throws Exception {
    StructType st = new StructType(new LinkedList<ThriftField>(), null);
    assertEquals("{\n" + "  \"id\" : \"STRUCT\",\n" + "  \"children\" : [ ],\n" + "  \"structOrUnionType\" : \"UNKNOWN\"\n" + "}", st.toJSON());
    st = new StructType(new LinkedList<ThriftField>(), StructOrUnionType.UNION);
    assertEquals("{\n" + "  \"id\" : \"STRUCT\",\n" + "  \"children\" : [ ],\n" + "  \"structOrUnionType\" : \"UNION\"\n" + "}", st.toJSON());
    st = new StructType(new LinkedList<ThriftField>(), StructOrUnionType.STRUCT);
    assertEquals("{\n" + "  \"id\" : \"STRUCT\",\n" + "  \"children\" : [ ],\n" + "  \"structOrUnionType\" : \"STRUCT\"\n" + "}", st.toJSON());
}
Also used : StructType(org.apache.parquet.thrift.struct.ThriftType.StructType) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

StructType (org.apache.parquet.thrift.struct.ThriftType.StructType)14 Test (org.junit.Test)6 MessageType (org.apache.parquet.schema.MessageType)4 ColumnIOFactory (org.apache.parquet.io.ColumnIOFactory)3 MessageColumnIO (org.apache.parquet.io.MessageColumnIO)3 ThriftType (org.apache.parquet.thrift.struct.ThriftType)3 ListType (org.apache.parquet.thrift.struct.ThriftType.ListType)3 MapType (org.apache.parquet.thrift.struct.ThriftType.MapType)3 SetType (org.apache.parquet.thrift.struct.ThriftType.SetType)3 RecordConsumerLoggingWrapper (org.apache.parquet.io.RecordConsumerLoggingWrapper)2 RecordConsumer (org.apache.parquet.io.api.RecordConsumer)2 ThriftField (org.apache.parquet.thrift.struct.ThriftField)2 EnumType (org.apache.parquet.thrift.struct.ThriftType.EnumType)2 TBase (org.apache.thrift.TBase)2 TException (org.apache.thrift.TException)2 TProtocol (org.apache.thrift.protocol.TProtocol)2 ThriftToPig (com.twitter.elephantbird.pig.util.ThriftToPig)1 File (java.io.File)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1