Search in sources :

Example 6 with ThriftField

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

the class ProtocolEventsAmender method checkSet.

/**
 * check each element of the Set, make sure all the element contain required fields
 *
 * @param eventIter
 * @param setFieldDefinition
 * @throws TException
 */
private void checkSet(Iterator<TProtocol> eventIter, ThriftField setFieldDefinition) throws TException {
    TSet thriftSet = acceptProtocol(eventIter.next()).readSetBegin();
    ThriftField elementFieldDefinition = ((ThriftType.SetType) setFieldDefinition.getType()).getValues();
    int setSize = thriftSet.size;
    for (int i = 0; i < setSize; i++) {
        checkField(thriftSet.elemType, eventIter, elementFieldDefinition);
    }
    acceptProtocol(eventIter.next()).readSetEnd();
}
Also used : ThriftField(org.apache.parquet.thrift.struct.ThriftField)

Example 7 with ThriftField

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

the class ScroogeStructConverter method convertMapTypeField.

private ThriftType convertMapTypeField(String fieldName, Manifest<?> keyManifest, Manifest<?> valueManifest, Requirement requirement) {
    String keyName = mapKeyName(fieldName);
    String valueName = mapValueName(fieldName);
    ThriftType keyType = convertClassToThriftType(keyName, requirement, keyManifest);
    ThriftField keyField = generateFieldWithoutId(keyName, requirement, keyType);
    ThriftType valueType = convertClassToThriftType(valueName, requirement, valueManifest);
    ThriftField valueField = generateFieldWithoutId(valueName, requirement, valueType);
    return new ThriftType.MapType(keyField, valueField);
}
Also used : ThriftType(org.apache.parquet.thrift.struct.ThriftType) ThriftField(org.apache.parquet.thrift.struct.ThriftField)

Example 8 with ThriftField

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

the class ScroogeStructConverter method convertSetTypeField.

private ThriftType convertSetTypeField(String fieldName, Manifest<?> valueManifest, Requirement requirement) {
    String elemName = setElemName(fieldName);
    ThriftType elementType = convertClassToThriftType(elemName, requirement, valueManifest);
    // Set only has one sub-field as element field, therefore using hard-coded 1 as fieldId,
    // it's the same as the solution used in ElephantBird
    ThriftField elementField = generateFieldWithoutId(elemName, requirement, elementType);
    return new ThriftType.SetType(elementField);
}
Also used : ThriftType(org.apache.parquet.thrift.struct.ThriftType) ThriftField(org.apache.parquet.thrift.struct.ThriftField)

Example 9 with ThriftField

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

the class TestThriftRecordConverter method testUnknownEnumThrowsGoodException.

@Test
public void testUnknownEnumThrowsGoodException() throws Exception {
    EnumType et = new EnumType(Arrays.asList(new EnumValue(77, "hello")));
    ThriftField field = new ThriftField("name", (short) 1, Requirement.REQUIRED, et);
    ArrayList<TProtocol> events = new ArrayList<TProtocol>();
    FieldEnumConverter conv = new FieldEnumConverter(events, field);
    conv.addBinary(Binary.fromString("hello"));
    assertEquals(1, events.size());
    assertEquals(77, events.get(0).readI32());
    try {
        conv.addBinary(Binary.fromString("FAKE_ENUM_VALUE"));
        fail("this should throw");
    } catch (ParquetDecodingException e) {
        assertEquals("Unrecognized enum value: FAKE_ENUM_VALUE known values: {Binary{\"hello\"}=77} in {\n" + "  \"name\" : \"name\",\n" + "  \"fieldId\" : 1,\n" + "  \"requirement\" : \"REQUIRED\",\n" + "  \"type\" : {\n" + "    \"id\" : \"ENUM\",\n" + "    \"values\" : [ {\n" + "      \"id\" : 77,\n" + "      \"name\" : \"hello\"\n" + "    } ]\n" + "  }\n" + "}", e.getMessage());
    }
}
Also used : ParquetDecodingException(org.apache.parquet.io.ParquetDecodingException) TProtocol(org.apache.thrift.protocol.TProtocol) EnumType(org.apache.parquet.thrift.struct.ThriftType.EnumType) EnumValue(org.apache.parquet.thrift.struct.ThriftType.EnumValue) ArrayList(java.util.ArrayList) ThriftField(org.apache.parquet.thrift.struct.ThriftField) FieldEnumConverter(org.apache.parquet.thrift.ThriftRecordConverter.FieldEnumConverter) Test(org.junit.Test)

Example 10 with ThriftField

use of org.apache.parquet.thrift.struct.ThriftField 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)

Aggregations

ThriftField (org.apache.parquet.thrift.struct.ThriftField)18 ThriftType (org.apache.parquet.thrift.struct.ThriftType)7 ArrayList (java.util.ArrayList)4 EnumType (org.apache.parquet.thrift.struct.ThriftType.EnumType)3 StructType (org.apache.parquet.thrift.struct.ThriftType.StructType)3 StructOrUnionType (org.apache.parquet.thrift.struct.ThriftType.StructType.StructOrUnionType)3 Field (com.twitter.elephantbird.thrift.TStructDescriptor.Field)2 ConversionPatterns.listType (org.apache.parquet.schema.ConversionPatterns.listType)2 ConversionPatterns.mapType (org.apache.parquet.schema.ConversionPatterns.mapType)2 GroupType (org.apache.parquet.schema.GroupType)2 MessageType (org.apache.parquet.schema.MessageType)2 OriginalType (org.apache.parquet.schema.OriginalType)2 PrimitiveType (org.apache.parquet.schema.PrimitiveType)2 Type (org.apache.parquet.schema.Type)2 Drop (org.apache.parquet.thrift.ConvertedField.Drop)2 Keep (org.apache.parquet.thrift.ConvertedField.Keep)2 Requirement (org.apache.parquet.thrift.struct.ThriftField.Requirement)2 BoolType (org.apache.parquet.thrift.struct.ThriftType.BoolType)2 ByteType (org.apache.parquet.thrift.struct.ThriftType.ByteType)2 DoubleType (org.apache.parquet.thrift.struct.ThriftType.DoubleType)2