You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/09/29 19:14:36 UTC
[GitHub] [beam] pabloem opened a new pull request, #23425: Reolling forward property-based tests for coders
pabloem opened a new pull request, #23425:
URL: https://github.com/apache/beam/pull/23425
I've tested these several times, to make sure that the test will remain consistently passing.
r: @Abacn
------------------------
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
- [ ] [**Choose reviewer(s)**](https://beam.apache.org/contribute/#make-your-change) and mention them in a comment (`R: @username`).
- [ ] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
- [ ] Update `CHANGES.md` with noteworthy changes.
- [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://beam.apache.org/contribute/get-started-contributing/#make-the-reviewers-job-easier).
To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
GitHub Actions Tests Status (on master branch)
------------------------------------------------------------------------------------------------
[](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] Abacn commented on a diff in pull request #23425: Reolling forward property-based tests for coders
Posted by GitBox <gi...@apache.org>.
Abacn commented on code in PR #23425:
URL: https://github.com/apache/beam/pull/23425#discussion_r983998425
##########
sdks/python/apache_beam/coders/coders_property_based_test.py:
##########
@@ -0,0 +1,165 @@
+#
+# 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.
+#
+
+"""Property tests for coders in the Python SDK.
+
+The tests in this file utilize the hypothesis library to generate random test
+cases and run them against Beam's coder implementations.
+
+These tests are similar to fuzzing, except they test invariant properties
+of code.
+"""
+
+import math
+import typing
+import unittest
+# TODO(pabloem): Include other categories of characters
+from datetime import datetime
+from string import ascii_letters
+from string import digits
+
+import numpy as np
+from hypothesis import strategies as st
+from hypothesis import assume
+from hypothesis import given
+from hypothesis import settings
+from pytz import utc
+
+from apache_beam.coders import FloatCoder
+from apache_beam.coders import RowCoder
+from apache_beam.coders import StrUtf8Coder
+from apache_beam.coders.typecoders import registry as coders_registry
+from apache_beam.typehints.schemas import PRIMITIVE_TO_ATOMIC_TYPE
+from apache_beam.typehints.schemas import typing_to_runner_api
+from apache_beam.utils.timestamp import Timestamp
+
+SCHEMA_TYPES_TO_STRATEGY = {
+ str: st.text(),
+ bytes: st.binary(),
+ typing.ByteString: st.binary(),
+ # Maximum datetime on year 3000 to conform to Windows OS limits.
+ Timestamp: st.datetimes(
+ min_value=datetime(1970, 1, 1, 1, 1),
+ max_value=datetime(
+ 3000, 1, 1, 0,
+ 0)).map(lambda dt: Timestamp.from_utc_datetime(dt.astimezone(utc))),
+ int: st.integers(min_value=-(1 << 63 - 1), max_value=1 << 63 - 1),
+ # INT8/BYTE not yet supported by RowCoder.
+ # np.int8: st.binary(min_size=1, max_size=1),
+ # INT16 not yet supported by RowCoder.
+ # np.int16: st.integers(min_value=-(1 << 15 - 1), max_value=1 << 15 - 1),
+ np.int32: st.integers(min_value=-(1 << 31 - 1), max_value=1 << 31 - 1),
+ np.int64: st.integers(min_value=-(1 << 63 - 1), max_value=1 << 63 - 1),
+ np.uint32: st.integers(min_value=0, max_value=1 << 32 - 1),
+ np.uint64: st.integers(min_value=0, max_value=1 << 64 - 1),
+ np.float32: st.floats(width=32, allow_nan=False),
+ np.float64: st.floats(width=64, allow_nan=False),
+ float: st.floats(width=64, allow_nan=False),
+ bool: st.booleans()
+}
+
+# TODO(https://github.com/apache/beam/issues/23003): Support logical types.
+SCHEMA_TYPES = list(SCHEMA_TYPES_TO_STRATEGY.keys())
+
+# A hypothesis strategy that generates schemas.
+# A schema is a list containing tuples of strings (field names), types (field
+# types) and boolean (nullable or not).
+# This strategy currently generates rows with simple types (i.e. non-list, and
+# non-map fields).
+SCHEMA_GENERATOR_STRATEGY = st.lists(
+ st.tuples(
+ st.text(ascii_letters + digits + '_', min_size=1),
+ st.sampled_from(SCHEMA_TYPES),
+ st.booleans()))
+
+FORBIDDEN_FIELD_NAMES = {
+ 'as', 'for', 'in', 'with', 'or', 'is', 'not', 'if', 'elif', 'else'
Review Comment:
Thanks for the fix.
These are all python keywords but not all Python keywords. Is there any source why these names are fobidden, or there is a list of forbidden field names?
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] pabloem merged pull request #23425: Reolling forward property-based tests for coders
Posted by GitBox <gi...@apache.org>.
pabloem merged PR #23425:
URL: https://github.com/apache/beam/pull/23425
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] github-actions[bot] commented on pull request #23425: Reolling forward property-based tests for coders
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #23425:
URL: https://github.com/apache/beam/pull/23425#issuecomment-1270188652
Assigning reviewers. If you would like to opt out of this review, comment `assign to next reviewer`:
R: @yeandy for label python.
Available commands:
- `stop reviewer notifications` - opt out of the automated review tooling
- `remind me after tests pass` - tag the comment author after tests pass
- `waiting on author` - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
The PR bot will only process comments in the main thread (not review comments).
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] pabloem commented on pull request #23425: Reolling forward property-based tests for coders
Posted by GitBox <gi...@apache.org>.
pabloem commented on PR #23425:
URL: https://github.com/apache/beam/pull/23425#issuecomment-1263023563
I created https://github.com/apache/beam/issues/23436 to track switching over - could we move forward with this for now? : )
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] codecov[bot] commented on pull request #23425: Reolling forward property-based tests for coders
Posted by GitBox <gi...@apache.org>.
codecov[bot] commented on PR #23425:
URL: https://github.com/apache/beam/pull/23425#issuecomment-1262756921
# [Codecov](https://codecov.io/gh/apache/beam/pull/23425?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#23425](https://codecov.io/gh/apache/beam/pull/23425?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (3d7152b) into [master](https://codecov.io/gh/apache/beam/commit/577953c5ac9dd3d022b664c21da846307ac45191?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (577953c) will **not change** coverage.
> The diff coverage is `n/a`.
```diff
@@ Coverage Diff @@
## master #23425 +/- ##
=======================================
Coverage 73.43% 73.43%
=======================================
Files 718 718
Lines 95680 95680
=======================================
Hits 70262 70262
Misses 24107 24107
Partials 1311 1311
```
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] pabloem commented on a diff in pull request #23425: Reolling forward property-based tests for coders
Posted by GitBox <gi...@apache.org>.
pabloem commented on code in PR #23425:
URL: https://github.com/apache/beam/pull/23425#discussion_r984074229
##########
sdks/python/apache_beam/coders/coders_property_based_test.py:
##########
@@ -0,0 +1,165 @@
+#
+# 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.
+#
+
+"""Property tests for coders in the Python SDK.
+
+The tests in this file utilize the hypothesis library to generate random test
+cases and run them against Beam's coder implementations.
+
+These tests are similar to fuzzing, except they test invariant properties
+of code.
+"""
+
+import math
+import typing
+import unittest
+# TODO(pabloem): Include other categories of characters
+from datetime import datetime
+from string import ascii_letters
+from string import digits
+
+import numpy as np
+from hypothesis import strategies as st
+from hypothesis import assume
+from hypothesis import given
+from hypothesis import settings
+from pytz import utc
+
+from apache_beam.coders import FloatCoder
+from apache_beam.coders import RowCoder
+from apache_beam.coders import StrUtf8Coder
+from apache_beam.coders.typecoders import registry as coders_registry
+from apache_beam.typehints.schemas import PRIMITIVE_TO_ATOMIC_TYPE
+from apache_beam.typehints.schemas import typing_to_runner_api
+from apache_beam.utils.timestamp import Timestamp
+
+SCHEMA_TYPES_TO_STRATEGY = {
+ str: st.text(),
+ bytes: st.binary(),
+ typing.ByteString: st.binary(),
+ # Maximum datetime on year 3000 to conform to Windows OS limits.
+ Timestamp: st.datetimes(
+ min_value=datetime(1970, 1, 1, 1, 1),
+ max_value=datetime(
+ 3000, 1, 1, 0,
+ 0)).map(lambda dt: Timestamp.from_utc_datetime(dt.astimezone(utc))),
+ int: st.integers(min_value=-(1 << 63 - 1), max_value=1 << 63 - 1),
+ # INT8/BYTE not yet supported by RowCoder.
+ # np.int8: st.binary(min_size=1, max_size=1),
+ # INT16 not yet supported by RowCoder.
+ # np.int16: st.integers(min_value=-(1 << 15 - 1), max_value=1 << 15 - 1),
+ np.int32: st.integers(min_value=-(1 << 31 - 1), max_value=1 << 31 - 1),
+ np.int64: st.integers(min_value=-(1 << 63 - 1), max_value=1 << 63 - 1),
+ np.uint32: st.integers(min_value=0, max_value=1 << 32 - 1),
+ np.uint64: st.integers(min_value=0, max_value=1 << 64 - 1),
+ np.float32: st.floats(width=32, allow_nan=False),
+ np.float64: st.floats(width=64, allow_nan=False),
+ float: st.floats(width=64, allow_nan=False),
+ bool: st.booleans()
+}
+
+# TODO(https://github.com/apache/beam/issues/23003): Support logical types.
+SCHEMA_TYPES = list(SCHEMA_TYPES_TO_STRATEGY.keys())
+
+# A hypothesis strategy that generates schemas.
+# A schema is a list containing tuples of strings (field names), types (field
+# types) and boolean (nullable or not).
+# This strategy currently generates rows with simple types (i.e. non-list, and
+# non-map fields).
+SCHEMA_GENERATOR_STRATEGY = st.lists(
+ st.tuples(
+ st.text(ascii_letters + digits + '_', min_size=1),
+ st.sampled_from(SCHEMA_TYPES),
+ st.booleans()))
+
+FORBIDDEN_FIELD_NAMES = {
+ 'as', 'for', 'in', 'with', 'or', 'is', 'not', 'if', 'elif', 'else'
Review Comment:
thanks Yi! Great observation. I've added a keyword check instead, which is the same one used when building namedtuples, which is what row coders use underneath.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] TheNeuralBit commented on pull request #23425: Reolling forward property-based tests for coders
Posted by GitBox <gi...@apache.org>.
TheNeuralBit commented on PR #23425:
URL: https://github.com/apache/beam/pull/23425#issuecomment-1262924006
FYI as a plane ride project I started looking at using a recursive rule to generate Beam schemas: https://github.com/apache/beam/pull/23361
You may be interested in the `field_names` strategy I added there.
Also, it would be great to combine these two efforts (first generate a schema, then generate test data given a schema) down the road!
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] TheNeuralBit commented on pull request #23425: Reolling forward property-based tests for coders
Posted by GitBox <gi...@apache.org>.
TheNeuralBit commented on PR #23425:
URL: https://github.com/apache/beam/pull/23425#issuecomment-1263697929
> I created #23436 to track switching over - could we move forward with this for now? : )
Yep! Sorry I didn't mean to hold this up.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org