Search in sources :

Example 1 with EnumType

use of org.apache.parquet.thrift.struct.ThriftType.EnumType 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 2 with EnumType

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

the class ParquetWriteProtocol method getProtocol.

private TProtocol getProtocol(ThriftField field, ColumnIO columnIO, Events returnClause) {
    TProtocol p;
    final ThriftType type = field.getType();
    switch(type.getType()) {
        case STOP:
        case VOID:
        default:
            throw new UnsupportedOperationException("can't convert type of " + field);
        case BOOL:
        case BYTE:
        case DOUBLE:
        case I16:
        case I32:
        case I64:
        case STRING:
            p = new PrimitiveWriteProtocol((PrimitiveColumnIO) columnIO, returnClause);
            break;
        case STRUCT:
            p = new StructWriteProtocol((GroupColumnIO) columnIO, (StructType) type, returnClause);
            break;
        case MAP:
            p = new MapWriteProtocol((GroupColumnIO) columnIO, (MapType) type, returnClause);
            break;
        case SET:
            p = new ListWriteProtocol((GroupColumnIO) columnIO, ((SetType) type).getValues(), returnClause);
            break;
        case LIST:
            p = new ListWriteProtocol((GroupColumnIO) columnIO, ((ListType) type).getValues(), returnClause);
            break;
        case ENUM:
            p = new EnumWriteProtocol((PrimitiveColumnIO) columnIO, (EnumType) type, returnClause);
            break;
    }
    return p;
}
Also used : ThriftType(org.apache.parquet.thrift.struct.ThriftType) StructType(org.apache.parquet.thrift.struct.ThriftType.StructType) PrimitiveColumnIO(org.apache.parquet.io.PrimitiveColumnIO) MapType(org.apache.parquet.thrift.struct.ThriftType.MapType) TProtocol(org.apache.thrift.protocol.TProtocol) GroupColumnIO(org.apache.parquet.io.GroupColumnIO) SetType(org.apache.parquet.thrift.struct.ThriftType.SetType) EnumType(org.apache.parquet.thrift.struct.ThriftType.EnumType) ListType(org.apache.parquet.thrift.struct.ThriftType.ListType)

Aggregations

EnumType (org.apache.parquet.thrift.struct.ThriftType.EnumType)2 TProtocol (org.apache.thrift.protocol.TProtocol)2 ArrayList (java.util.ArrayList)1 GroupColumnIO (org.apache.parquet.io.GroupColumnIO)1 ParquetDecodingException (org.apache.parquet.io.ParquetDecodingException)1 PrimitiveColumnIO (org.apache.parquet.io.PrimitiveColumnIO)1 FieldEnumConverter (org.apache.parquet.thrift.ThriftRecordConverter.FieldEnumConverter)1 ThriftField (org.apache.parquet.thrift.struct.ThriftField)1 ThriftType (org.apache.parquet.thrift.struct.ThriftType)1 EnumValue (org.apache.parquet.thrift.struct.ThriftType.EnumValue)1 ListType (org.apache.parquet.thrift.struct.ThriftType.ListType)1 MapType (org.apache.parquet.thrift.struct.ThriftType.MapType)1 SetType (org.apache.parquet.thrift.struct.ThriftType.SetType)1 StructType (org.apache.parquet.thrift.struct.ThriftType.StructType)1 Test (org.junit.Test)1