hive-protolib/src/main/java/com/streamsets/pipeline/stage/lib/hive/AvroHiveSchemaGenerator.java
@Override
  public String inferSchema(Map<String, HiveTypeInfo> record)
      throws StageException
  {
    Map<String, Schema> fields = new LinkedHashMap<>();
    for(Map.Entry<String, HiveTypeInfo> pair:  record.entrySet()) {
      if(!HiveMetastoreUtil.validateObjectName(pair.getKey())) {
        throw new HiveStageCheckedException(Errors.HIVE_30, pair.getKey());
      }
      Schema columnSchema = Schema.createUnion(ImmutableList.of(Schema.create(Schema.Type.NULL), traverse(pair)));
      // We always set default value to null
      columnSchema.addProp("default", NullNode.getInstance());
      fields.put(pair.getKey(), columnSchema);
    }
    Schema schema =  buildSchema(fields);
    return schema.toString();
  }
@Override
  public String inferSchema(Map<String, HiveTypeInfo> record)
      throws StageException
  {
    Map<String, Schema> fields = new LinkedHashMap<>();
    for(Map.Entry<String, HiveTypeInfo> pair:  record.entrySet()) {
      if(!HiveMetastoreUtil.validateObjectName(pair.getKey())) {
        throw new HiveStageCheckedException(Errors.HIVE_30, pair.getKey());
      }
      Schema columnSchema = Schema.createUnion(ImmutableList.of(Schema.create(Schema.Type.NULL), traverse(pair)));
      // We always set default value to null
      columnSchema.addProp("default", NullNode.getInstance());
      fields.put(pair.getKey(), columnSchema);
    }
    Schema schema =  buildSchema(fields);
    return schema.toString();
  }
@ Override public String inferSchema ( Map < String , HiveTypeInfo > record ) throws StageException { Map < String , Schema > fields = new LinkedHashMap <> ( ) ; for ( Map . Entry < String , HiveTypeInfo > pair : record . entrySet ( ) ) { if ( ! HiveMetastoreUtil . validateObjectName ( pair . getKey ( ) ) ) { throw new HiveStageCheckedException ( Errors . HIVE_30 , pair . getKey ( ) ) ; } Schema columnSchema = Schema . createUnion ( ImmutableList . of ( Schema . create ( Schema . Type . NULL ) , traverse ( pair ) ) ) ; // We always set default value to null columnSchema . addProp ( "default" , NullNode . getInstance ( ) ) ; fields . put ( pair . getKey ( ) , columnSchema ) ; } Schema schema = buildSchema ( fields ) ; return schema . toString ( ) ; }
It takes a record structure in <String, HiveTypeInfo> format.
Generate a schema and return in String.
@param record : record structure
@return String representation of Avro schema.
@throws StageException: If record contains unsupported type
It takes a record structure in <String HiveTypeInfo > format . Generate a schema and return in String .