flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gna-phetsarath <...@git.apache.org>
Subject [GitHub] flink pull request: [Flink-3691] extend avroinputformat to support...
Date Tue, 03 May 2016 21:15:20 GMT
Github user gna-phetsarath commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1920#discussion_r61957444
  
    --- Diff: flink-batch-connectors/flink-avro/src/test/java/org/apache/flink/api/io/avro/AvroRecordInputFormatTest.java
---
    @@ -289,6 +290,119 @@ public void testDeserializeToSpecificType() throws IOException {
     		}
     	}
     
    +	/**
    +	 * Test if the AvroInputFormat is able to properly read data from an Avro
    +	 * file as a GenericRecord.
    +	 * 
    +	 * @throws IOException,
    +	 *             if there is an exception
    +	 */
    +	@SuppressWarnings("unchecked")
    +	@Test
    +	public void testDeserialisationGenericRecord() throws IOException {
    +		Configuration parameters = new Configuration();
    +
    +		AvroInputFormat<GenericRecord> format = new AvroInputFormat<GenericRecord>(new
Path(testFile.getAbsolutePath()),
    +				GenericRecord.class);
    +		try {
    +			format.configure(parameters);
    +			FileInputSplit[] splits = format.createInputSplits(1);
    +			assertEquals(splits.length, 1);
    +			format.open(splits[0]);
    +
    +			GenericRecord u = format.nextRecord(null);
    --- End diff --
    
    From ```GenericData.class```, if you pass a null, a new instance of the ```Record``` will
be created:
    ```
      /**
       * Called to create new record instances. Subclasses may override to use a
       * different record implementation. The returned instance must conform to the
       * schema provided. If the old object contains fields not present in the
       * schema, they should either be removed from the old object, or it should
       * create a new instance that conforms to the schema. By default, this returns
       * a {@link GenericData.Record}.
       */
      public Object newRecord(Object old, Schema schema) {
        if (old instanceof IndexedRecord) {
          IndexedRecord record = (IndexedRecord)old;
          if (record.getSchema() == schema)
            return record;
        }
        return new GenericData.Record(schema);
      }
    ```
    So, I think it's valid.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message