@ Override public Schema convertSchema ( Schema inputSchema , WorkUnitState workUnit ) throws SchemaConversionException { LOG . info ( "Converting schema " + inputSchema ) ; String fieldsStr = workUnit . getProp ( ConfigurationKeys . CONVERTER_AVRO_FIELD_PICK_FIELDS ) ; Preconditions . checkNotNull ( fieldsStr , ConfigurationKeys . CONVERTER_AVRO_FIELD_PICK_FIELDS + " is required for converter " + this . getClass ( ) . getSimpleName ( ) ) ; LOG . info ( "Converting schema to selected fields: " + fieldsStr ) ; try { return createSchema ( inputSchema , fieldsStr ) ; } catch ( Exception e ) { throw new SchemaConversionException ( e ) ; } }
Convert the schema to contain only specified field . This will reuse AvroSchemaFieldRemover by listing fields not specified and remove it from the schema 1 . Retrieve list of fields from property 2 . Traverse schema and get list of fields to be removed 3 . While traversing also confirm specified fields from property also exist 4 . Convert schema by using AvroSchemaFieldRemover