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 2022/07/01 03:55:08 UTC
[GitHub] [flink] Vancior opened a new pull request, #20124: [FLINK-28336][python][format] Support parquet-avro format DataStream API
Vancior opened a new pull request, #20124:
URL: https://github.com/apache/flink/pull/20124
## What is the purpose of the change
This PR supports parquet-avro format for FileSource in PyFlink DataStream API.
## Brief change log
- shade optional dependency parquet-avro into flink-sql-parquet
- add avro Schema and AvroParquetReaders class
## Verifying this change
This change added tests and can be verified as follows:
- intergration tests in pyflink/datastream/connectors/tests/test_file_system.py#FileSourceParquetAvroFormatTests
## 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)`: (yes)
- 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, 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? (docs & Python Sphinx Doc)
--
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.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] flinkbot commented on pull request #20124: [FLINK-28336][python][format] Support parquet-avro format DataStream API
Posted by GitBox <gi...@apache.org>.
flinkbot commented on PR #20124:
URL: https://github.com/apache/flink/pull/20124#issuecomment-1171906046
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "54d29e93242f5488b28382e0bd1a91976456ea81",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "54d29e93242f5488b28382e0bd1a91976456ea81",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 54d29e93242f5488b28382e0bd1a91976456ea81 UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@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.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] Vancior commented on pull request #20124: [FLINK-28336][python][format] Support parquet-avro format DataStream API
Posted by GitBox <gi...@apache.org>.
Vancior commented on PR #20124:
URL: https://github.com/apache/flink/pull/20124#issuecomment-1173252406
@flinkbot run azure
--
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.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] dianfu closed pull request #20124: [FLINK-28336][python][format] Support parquet-avro format DataStream API
Posted by GitBox <gi...@apache.org>.
dianfu closed pull request #20124: [FLINK-28336][python][format] Support parquet-avro format DataStream API
URL: https://github.com/apache/flink/pull/20124
--
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.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] dianfu commented on a diff in pull request #20124: [FLINK-28336][python][format] Support parquet-avro format DataStream API
Posted by GitBox <gi...@apache.org>.
dianfu commented on code in PR #20124:
URL: https://github.com/apache/flink/pull/20124#discussion_r911711605
##########
flink-python/pyflink/datastream/connectors/tests/test_file_system.py:
##########
@@ -0,0 +1,308 @@
+################################################################################
+# 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.
+################################################################################
+import os
+import tempfile
+
+from py4j.java_gateway import java_import
+
+from pyflink.common.watermark_strategy import WatermarkStrategy
+from pyflink.datastream import StreamExecutionEnvironment
+from pyflink.datastream.functions import MapFunction
+from pyflink.datastream.connectors.file_system import FileSource
+from pyflink.datastream.formats.avro import Schema as AvroSchema
+from pyflink.datastream.formats.parquet import AvroParquetReaders
+from pyflink.datastream.tests.test_util import DataStreamTestSinkFunction
+from pyflink.java_gateway import get_gateway
+from pyflink.testing.test_case_utils import PyFlinkTestCase
+
+
+class FileSourceParquetAvroFormatTests(PyFlinkTestCase):
+
+ def setUp(self):
+ assert os.environ.get('HADOOP_CLASSPATH') is not None, 'Hadoop is needed for this test'
+ super().setUp()
+ self.env = StreamExecutionEnvironment.get_execution_environment()
Review Comment:
Extending PyFlinkStreamingTestCase and then we could reuse the env defined in PyFlinkStreamingTestCase
##########
flink-python/pyflink/datastream/connectors/tests/test_file_system.py:
##########
@@ -0,0 +1,308 @@
+################################################################################
+# 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.
+################################################################################
+import os
+import tempfile
+
+from py4j.java_gateway import java_import
+
+from pyflink.common.watermark_strategy import WatermarkStrategy
+from pyflink.datastream import StreamExecutionEnvironment
+from pyflink.datastream.functions import MapFunction
+from pyflink.datastream.connectors.file_system import FileSource
+from pyflink.datastream.formats.avro import Schema as AvroSchema
+from pyflink.datastream.formats.parquet import AvroParquetReaders
+from pyflink.datastream.tests.test_util import DataStreamTestSinkFunction
+from pyflink.java_gateway import get_gateway
+from pyflink.testing.test_case_utils import PyFlinkTestCase
+
+
+class FileSourceParquetAvroFormatTests(PyFlinkTestCase):
+
+ def setUp(self):
+ assert os.environ.get('HADOOP_CLASSPATH') is not None, 'Hadoop is needed for this test'
+ super().setUp()
+ self.env = StreamExecutionEnvironment.get_execution_environment()
+ self.env.set_parallelism(2)
+ self.test_sink = DataStreamTestSinkFunction()
+ self._import_avro_classes()
+
+ def test_avro_parquet_basic(self):
+ parquet_file_name = tempfile.mktemp(suffix='.parquet', dir=self.tempdir)
+ record_schema = """
+ {
+ "type": "record",
+ "name": "test",
+ "fields": [
+ { "name": "null", "type": "null" },
+ { "name": "boolean", "type": "boolean" },
+ { "name": "int", "type": "int" },
+ { "name": "long", "type": "long" },
+ { "name": "float", "type": "float" },
+ { "name": "double", "type": "double" },
+ { "name": "string", "type": "string" }
+ ]
+ }
+ """
+ schema = AvroSchema.parse_string(record_schema)
+ records = [self._create_basic_avro_record(schema, True, 0, 1, 2, 3, 's1'),
+ self._create_basic_avro_record(schema, False, 4, 5, 6, 7, 's2')]
+ self._create_avro_parquet_file(parquet_file_name, schema, records)
+
+ self._build_avro_parquet_job(schema, parquet_file_name)
+ self.env.execute("test_avro_parquet_basic")
+ results = self.test_sink.get_results(True, False)
+ result1 = results[0]
+ result2 = results[1]
+ self.assertEqual(result1['null'], None)
+ self.assertEqual(result1['boolean'], True)
+ self.assertEqual(result1['int'], 0)
+ self.assertEqual(result1['long'], 1)
+ self.assertAlmostEqual(result1['float'], 2, delta=1e-3)
+ self.assertAlmostEqual(result1['double'], 3, delta=1e-3)
+ self.assertEqual(result1['string'], 's1')
+ self.assertEqual(result2['null'], None)
+ self.assertEqual(result2['boolean'], False)
+ self.assertEqual(result2['int'], 4)
+ self.assertEqual(result2['long'], 5)
+ self.assertAlmostEqual(result2['float'], 6, delta=1e-3)
+ self.assertAlmostEqual(result2['double'], 7, delta=1e-3)
+ self.assertEqual(result2['string'], 's2')
+
+ def test_avro_parquet_enum(self):
+ parquet_file_name = tempfile.mktemp(suffix='.parquet', dir=self.tempdir)
+ record_schema = """
+ {
+ "type": "record",
+ "name": "test",
+ "fields": [
+ {
+ "name": "suit",
+ "type": {
+ "type": "enum",
+ "name": "Suit",
+ "symbols" : ["SPADES", "HEARTS", "DIAMONDS", "CLUBS"]
+ }
+ }
+ ]
+ }
+ """
+ schema = AvroSchema.parse_string(record_schema)
+ records = [self._create_enum_avro_record(schema, 'SPADES'),
+ self._create_enum_avro_record(schema, 'DIAMONDS')]
+ self._create_avro_parquet_file(parquet_file_name, schema, records)
+
+ self._build_avro_parquet_job(schema, parquet_file_name)
+ self.env.execute("test_avro_record_enum")
+ results = self.test_sink.get_results(True, False)
+ self.assertEqual(results[0]['suit'], 'SPADES')
+ self.assertEqual(results[1]['suit'], 'DIAMONDS')
+
+ def test_avro_parquet_union(self):
+ parquet_file_name = tempfile.mktemp(suffix='.parquet', dir=self.tempdir)
+ record_schema = """
+ {
+ "type": "record",
+ "name": "test",
+ "fields": [
+ {
+ "name": "union",
+ "type": [ "int", "double", "null" ]
+ }
+ ]
+ }
+ """
+ schema = AvroSchema.parse_string(record_schema)
+ records = [self._create_union_avro_record(schema, 1),
+ self._create_union_avro_record(schema, 2.),
+ self._create_union_avro_record(schema, None)]
+ self._create_avro_parquet_file(parquet_file_name, schema, records)
+
+ self._build_avro_parquet_job(schema, parquet_file_name)
+ self.env.execute("test_avro_record_union")
+ results = self.test_sink.get_results(True, False)
+ self.assertEqual(results[0]['union'], 1)
+ self.assertAlmostEqual(results[1]['union'], 2.0, delta=1e-3)
+ self.assertEqual(results[2]['union'], None)
+
+ def test_avro_parquet_array(self):
+ parquet_file_name = tempfile.mktemp(suffix='.parquet', dir=self.tempdir)
+ # It seems there's bug when array item record contains only one field, which throws
+ # java.lang.ClassCastException: required ... is not a group when reading
+ record_schema = """
+ {
+ "type": "record",
+ "name": "test",
+ "fields": [
+ {
+ "name": "array",
+ "type": {
+ "type": "array",
+ "items": {
+ "type": "record",
+ "name": "item",
+ "fields": [
+ { "name": "int", "type": "int" },
+ { "name": "double", "type": "double" }
+ ]
+ }
+ }
+ }
+ ]
+ }
+ """
+ schema = AvroSchema.parse_string(record_schema)
+ records = [self._create_array_avro_record(schema, [(1, 2.), (3, 4.)]),
+ self._create_array_avro_record(schema, [(5, 6.), (7, 8.)])]
+ self._create_avro_parquet_file(parquet_file_name, schema, records)
+
+ self._build_avro_parquet_job(schema, parquet_file_name)
+ self.env.execute("test_avro_record_array")
+ results = self.test_sink.get_results(True, False)
+ result1 = results[0]
+ result2 = results[1]
+ self.assertEqual(result1['array'][0]['int'], 1)
+ self.assertAlmostEqual(result1['array'][0]['double'], 2., delta=1e-3)
+ self.assertEqual(result1['array'][1]['int'], 3)
+ self.assertAlmostEqual(result1['array'][1]['double'], 4., delta=1e-3)
+ self.assertEqual(result2['array'][0]['int'], 5)
+ self.assertAlmostEqual(result2['array'][0]['double'], 6., delta=1e-3)
+ self.assertEqual(result2['array'][1]['int'], 7)
+ self.assertAlmostEqual(result2['array'][1]['double'], 8., delta=1e-3)
+
+ def test_avro_parquet_map(self):
+ parquet_file_name = tempfile.mktemp(suffix='.parquet', dir=self.tempdir)
+ record_schema = """
+ {
+ "type": "record",
+ "name": "test",
+ "fields": [
+ {
+ "name": "map",
+ "type": {
+ "type": "map",
+ "values": "long"
+ }
+ }
+ ]
+ }
+ """
+ schema = AvroSchema.parse_string(record_schema)
+ records = [self._create_map_avro_record(schema, {'a': 1, 'b': 2}),
+ self._create_map_avro_record(schema, {'c': 3, 'd': 4})]
+ self._create_avro_parquet_file(parquet_file_name, schema, records)
+
+ self._build_avro_parquet_job(schema, parquet_file_name)
+ self.env.execute("test_avro_record_map")
+ results = self.test_sink.get_results(True, False)
+ result1 = results[0]
+ result2 = results[1]
+ self.assertEqual(result1['map']['a'], 1)
+ self.assertEqual(result1['map']['b'], 2)
+ self.assertEqual(result2['map']['c'], 3)
+ self.assertEqual(result2['map']['d'], 4)
+
+ def _build_avro_parquet_job(self, record_schema, parquet_file_name):
+ ds = self.env.from_source(
+ FileSource.for_record_stream_format(
+ AvroParquetReaders.for_generic_record(record_schema),
+ parquet_file_name
+ ).build(),
+ WatermarkStrategy.for_monotonous_timestamps(),
+ "parquet-source"
+ )
+ ds.map(self.PassThroughMapFunction()).add_sink(self.test_sink)
+
+ class PassThroughMapFunction(MapFunction):
+
+ def map(self, value):
+ return value
+
+ @staticmethod
+ def _import_avro_classes():
+ jvm = get_gateway().jvm
+ classes = ['org.apache.avro.generic.GenericData']
+ prefix = 'org.apache.flink.avro.shaded.'
Review Comment:
Add the import into import_flink_view?
##########
flink-python/pyflink/datastream/connectors/tests/test_file_system.py:
##########
@@ -0,0 +1,308 @@
+################################################################################
+# 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.
+################################################################################
+import os
+import tempfile
+
+from py4j.java_gateway import java_import
+
+from pyflink.common.watermark_strategy import WatermarkStrategy
+from pyflink.datastream import StreamExecutionEnvironment
+from pyflink.datastream.functions import MapFunction
+from pyflink.datastream.connectors.file_system import FileSource
+from pyflink.datastream.formats.avro import Schema as AvroSchema
+from pyflink.datastream.formats.parquet import AvroParquetReaders
+from pyflink.datastream.tests.test_util import DataStreamTestSinkFunction
+from pyflink.java_gateway import get_gateway
+from pyflink.testing.test_case_utils import PyFlinkTestCase
+
+
+class FileSourceParquetAvroFormatTests(PyFlinkTestCase):
+
Review Comment:
Could use `@unittest.skipIf` to skip the test cases in certain cases.
--
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.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org