use of org.apache.pig.newplan.logical.relational.LogicalSchema in project metacat by Netflix.
the class PigTypeConverter method fromCanonicalTypeToPigSchema.
private LogicalSchema.LogicalFieldSchema fromCanonicalTypeToPigSchema(final String alias, final Type canonicalType) {
if (PigTypeMapping.getCANONICAL_TO_PIG().containsKey(canonicalType)) {
return new LogicalSchema.LogicalFieldSchema(alias, null, PigTypeMapping.getCANONICAL_TO_PIG().get(canonicalType));
} else if (canonicalType instanceof DecimalType) {
return new LogicalSchema.LogicalFieldSchema(alias, null, DataType.DOUBLE);
} else if (canonicalType instanceof VarcharType || canonicalType instanceof CharType) {
return new LogicalSchema.LogicalFieldSchema(alias, null, DataType.CHARARRAY);
} else if (canonicalType instanceof MapType) {
final MapType mapType = (MapType) canonicalType;
LogicalSchema schema = null;
if (((MapType) canonicalType).getValueType() != null && !BaseType.UNKNOWN.equals(mapType.getValueType())) {
schema = new LogicalSchema();
schema.addField(fromCanonicalTypeToPigSchema(null, mapType.getValueType()));
}
return new LogicalSchema.LogicalFieldSchema(alias, schema, DataType.MAP);
} else if (canonicalType instanceof ArrayType) {
final ArrayType arrayType = (ArrayType) canonicalType;
final LogicalSchema schema = new LogicalSchema();
Type elementType = arrayType.getElementType();
if (elementType != null) {
if (!(elementType instanceof RowType)) {
elementType = RowType.createRowType(Lists.newArrayList(elementType), ImmutableList.of(NAME_ARRAY_ELEMENT));
}
schema.addField(fromCanonicalTypeToPigSchema(null, elementType));
}
return new LogicalSchema.LogicalFieldSchema(alias, schema, DataType.BAG);
} else if (canonicalType instanceof RowType) {
final LogicalSchema schema = new LogicalSchema();
for (RowType.RowField rowField : ((RowType) canonicalType).getFields()) {
schema.addField(fromCanonicalTypeToPigSchema(rowField.getName() != null ? rowField.getName() : alias, rowField.getType()));
}
return new LogicalSchema.LogicalFieldSchema(alias, schema, DataType.TUPLE);
}
throw new IllegalArgumentException(String.format("Invalid for Pig converter: '%s'", canonicalType));
}
use of org.apache.pig.newplan.logical.relational.LogicalSchema in project metacat by Netflix.
the class PigTypeConverter method toMetacatType.
/**
* {@inheritDoc}.
*/
@Override
public Type toMetacatType(@Nonnull @NonNull final String pigType) {
try {
final LogicalSchema schema = Utils.parseSchema(pigType);
final LogicalSchema.LogicalFieldSchema field = schema.getField(0);
return toCanonicalType(field);
} catch (Exception e) {
throw new IllegalArgumentException(String.format("Invalid type signature: '%s'", pigType));
}
}
Aggregations