in server/pxf-hdfs/src/main/java/org/greenplum/pxf/plugins/hdfs/avro/AvroUtilities.java [107:173]
public Object decodeString(Schema schema, String value, boolean isTopLevel, boolean hasUserProvidedSchema) {
LOG.trace("schema={}, value={}, isTopLevel={}", schema, value, isTopLevel);
Schema.Type fieldType = schema.getType();
if (fieldType == Schema.Type.ARRAY) {
if (value == null) {
return null;
}
List<Object> list = new ArrayList<>();
String[] splits = pgUtilities.splitArray(value);
Schema elementType = schema.getElementType();
for (String split : splits) {
try {
list.add(decodeString(elementType, split, false, hasUserProvidedSchema));
} catch (NumberFormatException | PxfRuntimeException e) {
String hint = "";
if (StringUtils.startsWith(split, "{")) {
hint = hasUserProvidedSchema ?
"Value is a multi-dimensional array, please check that the provided AVRO schema has the correct dimensions." :
"Value is a multi-dimensional array, user is required to provide an AVRO schema with matching dimensions.";
} else {
hint = hasUserProvidedSchema ?
"Check that the AVRO and GPDB schemas are correct." :
"Unexpected state since PXF generated the AVRO schema.";
}
throw new PxfRuntimeException(String.format("Error parsing array element: %s was not of expected type %s", split, elementType), hint, e);
}
}
return list;
} else {
if (fieldType == Schema.Type.UNION) {
schema = firstNotNullSchema(schema.getTypes());
fieldType = schema.getType();
if (fieldType == Schema.Type.ARRAY) {
return decodeString(schema, value, isTopLevel, hasUserProvidedSchema);
}
}
if (value == null && !isTopLevel) {
return null;
}
switch (fieldType) {
case INT:
return Integer.parseInt(value);
case DOUBLE:
return Double.parseDouble(value);
case STRING:
case RECORD:
case ENUM:
case MAP:
return value;
case FLOAT:
return Float.parseFloat(value);
case LONG:
return Long.parseLong(value);
case BYTES:
return pgUtilities.parseByteaLiteral(value);
case BOOLEAN:
return pgUtilities.parseBoolLiteral(value);
default:
throw new PxfRuntimeException(String.format("type: %s is not supported", fieldType));
}
}
}