hudi-common/src/main/java/org/apache/hudi/avro/HoodieAvroUtils.java
/**
   * Generate a reader schema off the provided writeSchema, to just project out the provided columns.
   */
Generate a reader schema off the provided writeSchema, to just project out the provided columns.
Generate a reader schema off the provided writeSchema to just project out the provided columns .
public static Schema generateProjectionSchema(Schema originalSchema, List<String> fieldNames) {
    Map<String, Field> schemaFieldsMap = originalSchema.getFields().stream()
        .map(r -> Pair.of(r.name().toLowerCase(), r)).collect(Collectors.toMap(Pair::getLeft, Pair::getRight));
    List<Schema.Field> projectedFields = new ArrayList<>();
    for (String fn : fieldNames) {
      Schema.Field field = schemaFieldsMap.get(fn.toLowerCase());
      if (field == null) {
        throw new HoodieException("Field " + fn + " not found in log schema. Query cannot proceed! "
            + "Derived Schema Fields: " + new ArrayList<>(schemaFieldsMap.keySet()));
      } else {
        projectedFields.add(new Schema.Field(field.name(), field.schema(), field.doc(), field.defaultValue()));
      }
    }
    Schema projectedSchema = Schema.createRecord(originalSchema.getName(), originalSchema.getDoc(),
        originalSchema.getNamespace(), originalSchema.isError());
    projectedSchema.setFields(projectedFields);
    return projectedSchema;
  }
public static Schema generateProjectionSchema ( Schema originalSchema , List < String > fieldNames ) { Map < String , Field > schemaFieldsMap = originalSchema . getFields ( ) . stream ( ) . map ( r -> Pair . of ( r . name ( ) . toLowerCase ( ) , r ) ) . collect ( Collectors . toMap ( Pair :: getLeft , Pair :: getRight ) ) ; List < Schema . Field > projectedFields = new ArrayList < > ( ) ; for ( String fn : fieldNames ) { Schema . Field field = schemaFieldsMap . get ( fn . toLowerCase ( ) ) ; if ( field == null ) { throw new HoodieException ( "Field " + fn + " not found in log schema. Query cannot proceed! " + "Derived Schema Fields: " + new ArrayList < > ( schemaFieldsMap . keySet ( ) ) ) ; } else { projectedFields . add ( new Schema . Field ( field . name ( ) , field . schema ( ) , field . doc ( ) , field . defaultValue ( ) ) ) ; } } Schema projectedSchema = Schema . createRecord ( originalSchema . getName ( ) , originalSchema . getDoc ( ) , originalSchema . getNamespace ( ) , originalSchema . isError ( ) ) ; projectedSchema . setFields ( projectedFields ) ; return projectedSchema ; }
Generate a reader schema off the provided writeSchema, to just project out the provided columns.
Generate a reader schema off the provided writeSchema to just project out the provided columns .