Skip to content
Browse files

Move logic around

  • Loading branch information...
1 parent 7445a0d commit 4488a228f7d832a7d7c8459adbbcea0f6eba0b0a Jonathan Coveney committed Nov 16, 2011
Showing with 11 additions and 19 deletions.
  1. +11 −19 src/java/com/twitter/elephantbird/pig/util/ThriftToPig.java
View
30 src/java/com/twitter/elephantbird/pig/util/ThriftToPig.java
@@ -240,23 +240,11 @@ public static Schema toSchema(TStructDescriptor tDesc ) {
private static FieldSchema singleFieldToFieldSchema(String fieldName, Field field) throws FrontendException {
switch (field.getType()) {
case TType.LIST:
- if (PigUtil.Pig9orNewer && field.getListElemField().getType()==TType.STRUCT) {
- //In pig9, if the field is a struct, then we need to wrap it in a Tuple
- Schema internalSchema=singleFieldToTupleSchema(fieldName, field.getListElemField());
- return new FieldSchema(fieldName, new Schema(new FieldSchema("t",internalSchema,DataType.TUPLE)), DataType.BAG);
- } else {
- Schema internalSchema=singleFieldToTupleSchema(fieldName + "_tuple", field.getListElemField());
- return new FieldSchema(fieldName, internalSchema, DataType.BAG);
- }
+ Schema internalSchema=singleFieldToTupleSchema(fieldName, field.getListElemField());
+ return new FieldSchema(fieldName, internalSchema, DataType.BAG);
case TType.SET:
- if (PigUtil.Pig9orNewer && field.getSetElemField().getType()==TType.STRUCT) {
- //In pig9, if the field is a struct, then we need to wrap it in a Tuple
- Schema internalSchema=singleFieldToTupleSchema(fieldName, field.getSetElemField());
- return new FieldSchema(fieldName, new Schema(new FieldSchema("t",internalSchema,DataType.TUPLE)), DataType.BAG);
- } else {
- Schema internalSchema=singleFieldToTupleSchema(fieldName + "_tuple", field.getSetElemField());
- return new FieldSchema(fieldName, internalSchema, DataType.BAG);
- }
+ Schema internalSchema2=singleFieldToTupleSchema(fieldName, field.getSetElemField());
+ return new FieldSchema(fieldName, internalSchema2, DataType.BAG);
case TType.MAP:
// can not specify types for maps in Pig.
if (field.getMapKeyField().getType() != TType.STRING
@@ -280,9 +268,13 @@ private static Schema singleFieldToTupleSchema(String fieldName, Field field) th
switch (field.getType()) {
case TType.STRUCT:
- // wrapping STRUCT in a FieldSchema makes it impossible to
- // access fields in PIG script (causes runtime error).
- return toSchema(field.gettStructDescriptor());
+ Schema internalSchema=toSchema(field.gettStructDescriptor());
+ //In pig9, if the field is a struct, then we need to wrap it in a Tuple
+ if (PigUtil.Pig9orNewer) {
+ return new Schema(new FieldSchema("t",internalSchema,DataType.TUPLE));
+ } else {
+ return internalSchema;
+ }
case TType.LIST:
fieldSchema = singleFieldToFieldSchema(fieldName, field.getListElemField());
break;

0 comments on commit 4488a22

Please sign in to comment.
Something went wrong with that request. Please try again.