pig/src/main/java/com/twitter/elephantbird/pig/util/ThriftToPig.java
public static void stringifySchema(StringBuilder sb,
                                     Schema schema,
                                     byte type,
                                     StringBuilder prefix)
                                          throws FrontendException{
      // this is a modified version of {@link Schema#stringifySchema(StringBuilder, Schema, byte)}
      if (type == DataType.TUPLE) {
          sb.append("(") ;
      }
      else if (type == DataType.BAG) {
          sb.append("{") ;
      }

      prefix.append("  ");
      sb.append("\n").append(prefix);

      if (schema == null) {
          sb.append("null") ;
      }
      else {
          boolean isFirst = true ;
          for (int i=0; i< schema.size() ;i++) {

              if (!isFirst) {
                  sb.append(",\n").append(prefix);
              }
              else {
                  isFirst = false ;
              }

              FieldSchema fs = schema.getField(i) ;

              if(fs == null) {
                  sb.append("null");
                  continue;
              }

              if (fs.alias != null) {
                  sb.append(fs.alias);
                  sb.append(": ");
              }

              if (DataType.isAtomic(fs.type)) {
                  sb.append(DataType.findTypeName(fs.type)) ;
              }
              else if ( (fs.type == DataType.TUPLE) ||
                        (fs.type == DataType.BAG) ) {
                  // safety net
                  if (schema != fs.schema) {
                      stringifySchema(sb, fs.schema, fs.type, prefix) ;
                  }
                  else {
                      throw new AssertionError("Schema refers to itself "
                                               + "as inner schema") ;
                  }
              } else if (fs.type == DataType.MAP) {
                sb.append(DataType.findTypeName(fs.type) + "[");
                if (fs.schema!=null)
                    stringifySchema(sb, fs.schema, fs.type, prefix);
                sb.append("]");
              } else {
                  sb.append(DataType.findTypeName(fs.type)) ;
              }
          }
      }

      prefix.setLength(prefix.length()-2);
      sb.append("\n").append(prefix);

      if (type == DataType.TUPLE) {
          sb.append(")") ;
      }
      else if (type == DataType.BAG) {
          sb.append("}") ;
      }
  }
public static void stringifySchema(StringBuilder sb,
                                     Schema schema,
                                     byte type,
                                     StringBuilder prefix)
                                          throws FrontendException{
      // this is a modified version of {@link Schema#stringifySchema(StringBuilder, Schema, byte)}
      if (type == DataType.TUPLE) {
          sb.append("(") ;
      }
      else if (type == DataType.BAG) {
          sb.append("{") ;
      }

      prefix.append("  ");
      sb.append("\n").append(prefix);

      if (schema == null) {
          sb.append("null") ;
      }
      else {
          boolean isFirst = true ;
          for (int i=0; i< schema.size() ;i++) {

              if (!isFirst) {
                  sb.append(",\n").append(prefix);
              }
              else {
                  isFirst = false ;
              }

              FieldSchema fs = schema.getField(i) ;

              if(fs == null) {
                  sb.append("null");
                  continue;
              }

              if (fs.alias != null) {
                  sb.append(fs.alias);
                  sb.append(": ");
              }

              if (DataType.isAtomic(fs.type)) {
                  sb.append(DataType.findTypeName(fs.type)) ;
              }
              else if ( (fs.type == DataType.TUPLE) ||
                        (fs.type == DataType.BAG) ) {
                  // safety net
                  if (schema != fs.schema) {
                      stringifySchema(sb, fs.schema, fs.type, prefix) ;
                  }
                  else {
                      throw new AssertionError("Schema refers to itself "
                                               + "as inner schema") ;
                  }
              } else if (fs.type == DataType.MAP) {
                sb.append(DataType.findTypeName(fs.type) + "[");
                if (fs.schema!=null)
                    stringifySchema(sb, fs.schema, fs.type, prefix);
                sb.append("]");
              } else {
                  sb.append(DataType.findTypeName(fs.type)) ;
              }
          }
      }

      prefix.setLength(prefix.length()-2);
      sb.append("\n").append(prefix);

      if (type == DataType.TUPLE) {
          sb.append(")") ;
      }
      else if (type == DataType.BAG) {
          sb.append("}") ;
      }
  }
public static void stringifySchema ( StringBuilder sb , Schema schema , byte type , StringBuilder prefix ) throws FrontendException { // this is a modified version of {@link Schema#stringifySchema(StringBuilder, Schema, byte)} if ( type == DataType . TUPLE ) { sb . append ( "(" ) ; } else if ( type == DataType . BAG ) { sb . append ( "{" ) ; } prefix . append ( "  " ) ; sb . append ( "\n" ) . append ( prefix ) ; if ( schema == null ) { sb . append ( "null" ) ; } else { boolean isFirst = true ; for ( int i = 0 ; i < schema . size ( ) ; i ++ ) { if ( ! isFirst ) { sb . append ( ",\n" ) . append ( prefix ) ; } else { isFirst = false ; } FieldSchema fs = schema . getField ( i ) ; if ( fs == null ) { sb . append ( "null" ) ; continue ; } if ( fs . alias != null ) { sb . append ( fs . alias ) ; sb . append ( ": " ) ; } if ( DataType . isAtomic ( fs . type ) ) { sb . append ( DataType . findTypeName ( fs . type ) ) ; } else if ( ( fs . type == DataType . TUPLE ) || ( fs . type == DataType . BAG ) ) { // safety net if ( schema != fs . schema ) { stringifySchema ( sb , fs . schema , fs . type , prefix ) ; } else { throw new AssertionError ( "Schema refers to itself " + "as inner schema" ) ; } } else if ( fs . type == DataType . MAP ) { sb . append ( DataType . findTypeName ( fs . type ) + "[" ) ; if ( fs . schema != null ) stringifySchema ( sb , fs . schema , fs . type , prefix ) ; sb . append ( "]" ) ; } else { sb . append ( DataType . findTypeName ( fs . type ) ) ; } } } prefix . setLength ( prefix . length ( ) - 2 ) ; sb . append ( "\n" ) . append ( prefix ) ; if ( type == DataType . TUPLE ) { sb . append ( ")" ) ; } else if ( type == DataType . BAG ) { sb . append ( "}" ) ; } }
type can only be BAG or TUPLE
type can only be BAG or TUPLE