public Schema getOutputSchema()

in datafu-pig/src/main/java/datafu/pig/util/Coalesce.java [126:182]


  public Schema getOutputSchema(Schema input)
  {
    if (input.getFields().size() == 0)
    {
      throw new RuntimeException("Expected at least one parameter");
    }
        
    Byte outputType = null;
    int pos = 0;
    for (FieldSchema field : input.getFields())
    {
      if (DataType.isSchemaType(field.type))
      {
        throw new RuntimeException(String.format("Not supported on schema types.  Found %s in position %d.",DataType.findTypeName(field.type),pos));
      }
      
      if (DataType.isComplex(field.type))
      {
        throw new RuntimeException(String.format("Not supported on complex types.  Found %s in position %d.",DataType.findTypeName(field.type),pos));
      }
      
      if (!DataType.isUsableType(field.type))
      {
        throw new RuntimeException(String.format("Not a usable type.  Found %s in position %d.",DataType.findTypeName(field.type),pos));
      }
      
      if (outputType == null)
      {
        outputType = field.type;
      }
      else if (!outputType.equals(field.type))
      {        
        if (strict)
        {
          throw new RuntimeException(String.format("Expected all types to be equal, but found '%s' in position %d.  First element has type '%s'.  "
                                                   + "If you'd like to attempt merging types, use the '%s' option, as '%s' is the default.",
                                                   DataType.findTypeName(field.type),pos,DataType.findTypeName((byte)outputType),LAZY_OPTION,STRICT_OPTION));
        }
        else
        {
          byte merged = DataType.mergeType(outputType, field.type);
          if (merged == DataType.ERROR)
          {
            throw new RuntimeException(String.format("Expected all types to be equal, but found '%s' in position %d, where output type is '%s', and types could not be merged.",
                                                     DataType.findTypeName(field.type),pos,DataType.findTypeName((byte)outputType)));
          }
          outputType = merged;
        }
      }
      
      pos++;
    }
    
    getInstanceProperties().put("type", outputType);
        
    return new Schema(new Schema.FieldSchema("item",outputType));
  }