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();
}
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);
}
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);
}
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());
}
}
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());
}
Aggregations