You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/05/15 07:08:32 UTC

[GitHub] [flink] JingsongLi opened a new pull request #12162: [FLINK-17718][avro] Integrate avro to file system connector

JingsongLi opened a new pull request #12162:
URL: https://github.com/apache/flink/pull/12162


   
   ## What is the purpose of the change
   
   Integrate avro to file system connector.
   Introduce `AvroFileSystemFormatFactory`.
   
   ## Brief change log
   
   - Introduce `AvroFileSystemFormatFactory`.
   - Introduce `RowDataAvroInputFormat`.
   - Introduce `RowDataAvroWriterFactory`.
   
   This based on https://github.com/apache/flink/pull/12133 and https://github.com/apache/flink/pull/11385
   
   ## Verifying this change
   
   `AvroFilesystemITCase`
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): no
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: no
     - The serializers: no
     - The runtime per-record code paths (performance sensitive): no
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn/Mesos, ZooKeeper: no
     - The S3 file system connector: no
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (yes)
     - If yes, how is the feature documented? JavaDocs
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot commented on pull request #12162: [FLINK-17718][avro] Integrate avro to file system connector

Posted by GitBox <gi...@apache.org>.
flinkbot commented on pull request #12162:
URL: https://github.com/apache/flink/pull/12162#issuecomment-629070797


   Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
   to review your pull request. We will use this comment to track the progress of the review.
   
   
   ## Automated Checks
   Last check on commit d19294c341e31db854dfa19436f8e9a990336e59 (Fri May 15 07:10:49 UTC 2020)
   
   **Warnings:**
    * **1 pom.xml files were touched**: Check for build and licensing issues.
    * No documentation files were touched! Remember to keep the Flink docs up to date!
   
   
   <sub>Mention the bot in a comment to re-run the automated checks.</sub>
   ## Review Progress
   
   * ❓ 1. The [description] looks good.
   * ❓ 2. There is [consensus] that the contribution should go into to Flink.
   * ❓ 3. Needs [attention] from.
   * ❓ 4. The change fits into the overall [architecture].
   * ❓ 5. Overall code [quality] is good.
   
   Please see the [Pull Request Review Guide](https://flink.apache.org/contributing/reviewing-prs.html) for a full explanation of the review process.<details>
    The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot approve description` to approve one or more aspects (aspects: `description`, `consensus`, `architecture` and `quality`)
    - `@flinkbot approve all` to approve all aspects
    - `@flinkbot approve-until architecture` to approve everything until `architecture`
    - `@flinkbot attention @username1 [@username2 ..]` to require somebody's attention
    - `@flinkbot disapprove architecture` to remove an approval you gave earlier
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #12162: [FLINK-17718][avro] Integrate avro to file system connector

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #12162:
URL: https://github.com/apache/flink/pull/12162#issuecomment-629070797


   Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
   to review your pull request. We will use this comment to track the progress of the review.
   
   
   ## Automated Checks
   Last check on commit 309a693e09bb710b19d23bc01d1273dd50708f45 (Fri Oct 16 10:32:23 UTC 2020)
   
   **Warnings:**
    * **1 pom.xml files were touched**: Check for build and licensing issues.
    * No documentation files were touched! Remember to keep the Flink docs up to date!
   
   
   <sub>Mention the bot in a comment to re-run the automated checks.</sub>
   ## Review Progress
   
   * ❓ 1. The [description] looks good.
   * ❓ 2. There is [consensus] that the contribution should go into to Flink.
   * ❓ 3. Needs [attention] from.
   * ❓ 4. The change fits into the overall [architecture].
   * ❓ 5. Overall code [quality] is good.
   
   Please see the [Pull Request Review Guide](https://flink.apache.org/contributing/reviewing-prs.html) for a full explanation of the review process.<details>
    The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot approve description` to approve one or more aspects (aspects: `description`, `consensus`, `architecture` and `quality`)
    - `@flinkbot approve all` to approve all aspects
    - `@flinkbot approve-until architecture` to approve everything until `architecture`
    - `@flinkbot attention @username1 [@username2 ..]` to require somebody's attention
    - `@flinkbot disapprove architecture` to remove an approval you gave earlier
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #12162: [FLINK-17718][avro] Integrate avro to file system connector

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #12162:
URL: https://github.com/apache/flink/pull/12162#issuecomment-629084825


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "d19294c341e31db854dfa19436f8e9a990336e59",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1394",
       "triggerID" : "d19294c341e31db854dfa19436f8e9a990336e59",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * d19294c341e31db854dfa19436f8e9a990336e59 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1394) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot commented on pull request #12162: [FLINK-17718][avro] Integrate avro to file system connector

Posted by GitBox <gi...@apache.org>.
flinkbot commented on pull request #12162:
URL: https://github.com/apache/flink/pull/12162#issuecomment-629084825


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "d19294c341e31db854dfa19436f8e9a990336e59",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "d19294c341e31db854dfa19436f8e9a990336e59",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * d19294c341e31db854dfa19436f8e9a990336e59 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #12162: [FLINK-17718][avro] Integrate avro to file system connector

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #12162:
URL: https://github.com/apache/flink/pull/12162#issuecomment-629084825


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "d19294c341e31db854dfa19436f8e9a990336e59",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1394",
       "triggerID" : "d19294c341e31db854dfa19436f8e9a990336e59",
       "triggerType" : "PUSH"
     }, {
       "hash" : "309a693e09bb710b19d23bc01d1273dd50708f45",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "309a693e09bb710b19d23bc01d1273dd50708f45",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * d19294c341e31db854dfa19436f8e9a990336e59 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1394) 
   * 309a693e09bb710b19d23bc01d1273dd50708f45 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] leonardBang commented on a change in pull request #12162: [FLINK-17718][avro] Integrate avro to file system connector

Posted by GitBox <gi...@apache.org>.
leonardBang commented on a change in pull request #12162:
URL: https://github.com/apache/flink/pull/12162#discussion_r426111526



##########
File path: flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/AvroFileSystemFormatFactory.java
##########
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.formats.avro;
+
+import org.apache.flink.api.common.io.InputFormat;
+import org.apache.flink.api.common.serialization.BulkWriter;
+import org.apache.flink.api.common.serialization.Encoder;
+import org.apache.flink.core.fs.FSDataOutputStream;
+import org.apache.flink.core.fs.FileInputSplit;
+import org.apache.flink.core.fs.Path;
+import org.apache.flink.formats.avro.typeutils.AvroSchemaConverter;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.descriptors.DescriptorProperties;
+import org.apache.flink.table.factories.FileSystemFormatFactory;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.utils.PartitionPathUtils;
+
+import org.apache.avro.Schema;
+import org.apache.avro.file.CodecFactory;
+import org.apache.avro.file.DataFileConstants;
+import org.apache.avro.file.DataFileWriter;
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.generic.GenericDatumWriter;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.generic.IndexedRecord;
+import org.apache.avro.io.DatumWriter;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.table.descriptors.FormatDescriptorValidator.FORMAT;
+
+/**
+ * Avro format factory for file system.
+ */
+public class AvroFileSystemFormatFactory implements FileSystemFormatFactory {
+
+	public static final String AVRO_OUTPUT_CODEC = "format." + DataFileConstants.CODEC;
+
+	@Override
+	public boolean supportsSchemaDerivation() {
+		return true;
+	}
+
+	@Override
+	public List<String> supportedProperties() {
+		List<String> options = new ArrayList<>();
+		options.add(AVRO_OUTPUT_CODEC);
+		return options;
+	}
+
+	@Override
+	public Map<String, String> requiredContext() {
+		Map<String, String> context = new HashMap<>();
+		context.put(FORMAT, "avro");
+		return context;
+	}
+
+	@Override
+	public InputFormat<RowData, ?> createReader(ReaderContext context) {
+		DescriptorProperties properties = new DescriptorProperties();
+		properties.putProperties(context.getFormatProperties());
+
+		String[] fieldNames = context.getSchema().getFieldNames();
+		List<String> projectFields = Arrays.stream(context.getProjectFields())
+			.mapToObj(idx -> fieldNames[idx])
+			.collect(Collectors.toList());
+		List<String> csvFields = Arrays.stream(fieldNames)
+			.filter(field -> !context.getPartitionKeys().contains(field))
+			.collect(Collectors.toList());
+
+		int[] selectFieldToProjectField = context.getFormatProjectFields().stream()
+			.mapToInt(projectFields::indexOf)
+			.toArray();
+		int[] selectFieldToFormatField = context.getFormatProjectFields().stream()
+			.mapToInt(csvFields::indexOf)
+			.toArray();
+
+		//noinspection unchecked
+		return new RowDataAvroInputFormat(
+				context.getPaths(),
+				context.getFormatRowType(),
+				context.getSchema().getFieldDataTypes(),
+				context.getSchema().getFieldNames(),
+				context.getProjectFields(),
+				context.getPartitionKeys(),
+				context.getDefaultPartName(),
+				context.getPushedDownLimit(),
+				selectFieldToProjectField,
+				selectFieldToFormatField);
+	}
+
+	@Override
+	public Optional<Encoder<RowData>> createEncoder(WriterContext context) {
+		return Optional.empty();
+	}
+
+	@Override
+	public Optional<BulkWriter.Factory<RowData>> createBulkWriterFactory(WriterContext context) {
+		return Optional.of(new RowDataAvroWriterFactory(
+				context.getFormatRowType(),
+				context.getFormatProperties().get(AVRO_OUTPUT_CODEC)));
+	}
+
+	/**
+	 * InputFormat that reads avro record into {@link RowData}.
+	 *
+	 * <p>This extends {@link AvroInputFormat}, but {@link RowData} is not a avro record,
+	 * so now we remove generic information.
+	 * TODO {@link AvroInputFormat} support type conversion.
+	 */
+	private static class RowDataAvroInputFormat extends AvroInputFormat {
+
+		private static final long serialVersionUID = 1L;
+
+		private final DataType[] fieldTypes;
+		private final String[] fieldNames;
+		private final int[] selectFields;
+		private final List<String> partitionKeys;
+		private final String defaultPartValue;
+		private final long limit;
+		private final int[] selectFieldToProjectField;
+		private final int[] selectFieldToFormatField;
+		private final RowType formatRowType;
+
+		private transient long emitted;
+		// reuse object for per record
+		private transient GenericRowData rowData;
+		private transient Schema schema;
+		private transient IndexedRecord record;
+
+		public RowDataAvroInputFormat(
+				Path[] filePaths,
+				RowType formatRowType,
+				DataType[] fieldTypes,
+				String[] fieldNames,
+				int[] selectFields,
+				List<String> partitionKeys,
+				String defaultPartValue,
+				long limit,
+				int[] selectFieldToProjectField,
+				int[] selectFieldToFormatField) {
+			super(filePaths[0], GenericRecord.class);
+			super.setFilePaths(filePaths);
+			this.formatRowType = formatRowType;
+			this.fieldTypes = fieldTypes;
+			this.fieldNames = fieldNames;
+			this.partitionKeys = partitionKeys;
+			this.defaultPartValue = defaultPartValue;
+			this.selectFields = selectFields;
+			this.limit = limit;
+			this.emitted = 0;
+			this.selectFieldToProjectField = selectFieldToProjectField;
+			this.selectFieldToFormatField = selectFieldToFormatField;
+		}
+
+		@Override
+		public void open(FileInputSplit split) throws IOException {
+			super.open(split);
+			schema = AvroSchemaConverter.convertToSchema(formatRowType);
+			record = new GenericData.Record(schema);
+			rowData = PartitionPathUtils.fillPartitionValueForRecord(
+					fieldNames,
+					fieldTypes,
+					selectFields,
+					partitionKeys,
+					currentSplit.getPath(),
+					defaultPartValue);
+		}
+
+		@Override
+		public boolean reachedEnd() throws IOException {
+			return emitted >= limit || super.reachedEnd();
+		}
+
+		@Override
+		public Object nextRecord(Object reuse) throws IOException {
+			@SuppressWarnings("unchecked")
+			IndexedRecord r = (IndexedRecord) super.nextRecord(record);

Review comment:
       We need deal the null here:
   ```
   if (r == null) {
    return null;
   }
   ```

##########
File path: flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/AvroRowDataDeserializationSchema.java
##########
@@ -168,7 +168,7 @@ public int hashCode() {
 
 	// --------------------------------------------------------------------------------------------
 
-	private RowData convertAvroRecordToRowData(Schema schema, RowType rowType, IndexedRecord record) {
+	public static GenericRowData convertAvroRecordToRowData(Schema schema, RowType rowType, IndexedRecord record) {

Review comment:
       package privilege is enough here
   ```suggestion
   	static GenericRowData convertAvroRecordToRowData(Schema schema, RowType rowType, IndexedRecord record) {
   ```

##########
File path: flink-formats/flink-avro/src/test/java/org/apache/flink/formats/avro/AvroFilesystemITCase.java
##########
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.formats.avro;
+
+import org.apache.flink.table.planner.runtime.batch.sql.BatchFileSystemITCaseBase;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * ITCase to test csv format for {@link AvroFileSystemFormatFactory} in batch mode.

Review comment:
       please also add a ITCase `AvroFsStreamingSinkITCase` for stream 

##########
File path: flink-formats/flink-avro/src/test/java/org/apache/flink/formats/avro/AvroFilesystemITCase.java
##########
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.formats.avro;
+
+import org.apache.flink.table.planner.runtime.batch.sql.BatchFileSystemITCaseBase;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * ITCase to test csv format for {@link AvroFileSystemFormatFactory} in batch mode.

Review comment:
       ```suggestion
    * ITCase to test avro format for {@link AvroFileSystemFormatFactory} in batch mode.
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #12162: [FLINK-17718][avro] Integrate avro to file system connector

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #12162:
URL: https://github.com/apache/flink/pull/12162#issuecomment-629084825


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "d19294c341e31db854dfa19436f8e9a990336e59",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1394",
       "triggerID" : "d19294c341e31db854dfa19436f8e9a990336e59",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * d19294c341e31db854dfa19436f8e9a990336e59 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=1394) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] JingsongLi closed pull request #12162: [FLINK-17718][avro] Integrate avro to file system connector

Posted by GitBox <gi...@apache.org>.
JingsongLi closed pull request #12162:
URL: https://github.com/apache/flink/pull/12162


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org