You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "autophagy (via GitHub)" <gi...@apache.org> on 2025/04/07 13:04:24 UTC
[PR] [FLINK-37625][python] Don't skip type validation for Rows made with positional arguments [flink]
autophagy opened a new pull request, #26414:
URL: https://github.com/apache/flink/pull/26414
## What is the purpose of the change
When creating a table using `TableEnvironment.from_elements`, the Table API skips type validation on any Row elements that were created using positional arguments, rather than keyword arguments.
For example, take a table with a single column, whose type is an array of Rows. These rows have 2 columns, `a VARCHAR` and `b BOOLEAN`. If we create a table with elements where one of these rows has columns with incorrect datatypes:
```python
schema = DataTypes.ROW(
[
DataTypes.FIELD(
"col",
DataTypes.ARRAY(
DataTypes.ROW(
[
DataTypes.FIELD("a", DataTypes.STRING()),
DataTypes.FIELD("b", DataTypes.BOOLEAN()),
]
)
),
),
]
)
elements = [(
[("pyflink", True), ("pyflink", False), (True, "pyflink")],
)]
table = self.t_env.from_elements(elements, schema)
table_result = list(table.execute().collect())
```
This results in a type validation error:
```
TypeError: field a in element in array field col: VARCHAR can not accept object True in type <class 'bool'>
```
In an example where we use Row instead of tuples, but with column arguments:
```
elements = [(
[Row(a="pyflink", b=True), Row(a="pyflink", b=False), Row(a=True, b="pyflink")],
)]
```
We also get the same type validation error. However, when we use Row with positional arguments:
```
elements = [(
[Row("pyflink", True), Row("pyflink", False), Row(True, "pyflink")],
)]
```
the type validation is skipped, leading to an unpickling error when collecting:
```
> data = pickle.loads(data)
E EOFError: Ran out of input
```
The type validator skips this by stating that [the order in the row could be different to the order of the datatype fields](https://github.com/apache/flink/blob/master/flink-python/pyflink/table/types.py#L2156), but I don't think this is true. Both rows made from tuples and lists are type verified positionally with the positions of the Datatype fields, and in the case of the `Row` class the order the row's internal values are preserved. Similarly, `Row` class equality in cases where both of the rows are created with positional arguments
## Brief change log
- *Change the type validation logic used by `TableEnvironment.from_elements` so that `Row`s constructed with positional arguments are not skipped.*
## Verifying this change
This change added tests and can be verified as follows:
- *Added a test to ensure consistent type validation behaviour with rows constructed from tuples, lists, `Row`s with keyword arguments and `Row`s with positional arguments*
-
## 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, ZooKeeper: (no)
- The S3 file system connector: (no)
## Documentation
- Does this pull request introduce a new feature? (no)
- If yes, how is the feature documented? (not applicable)
--
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
Re: [PR] [FLINK-37625][python] Don't skip type validation for Rows made with positional arguments [flink]
Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #26414:
URL: https://github.com/apache/flink/pull/26414#issuecomment-2783296378
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "92e7cc3e8e13c1c011ae107921c0b43b31cbc1d7",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "92e7cc3e8e13c1c011ae107921c0b43b31cbc1d7",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 92e7cc3e8e13c1c011ae107921c0b43b31cbc1d7 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
Re: [PR] [FLINK-37625][python] Don't skip type validation for Rows made with positional arguments [flink]
Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #26414:
URL: https://github.com/apache/flink/pull/26414#discussion_r2033103863
##########
flink-python/pyflink/common/types.py:
##########
@@ -108,6 +108,7 @@ def __init__(self, *args, **kwargs):
self._from_dict = True
else:
self._values = list(args)
+ self._from_dict = False
Review Comment:
nit: can we do this outside the if with self._from_dict = kwargs;
--
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
Re: [PR] [FLINK-37625][python] Don't skip type validation for Rows made with positional arguments [flink]
Posted by "dawidwys (via GitHub)" <gi...@apache.org>.
dawidwys merged PR #26414:
URL: https://github.com/apache/flink/pull/26414
--
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
Re: [PR] [FLINK-37625][python] Don't skip type validation for Rows made with positional arguments [flink]
Posted by "autophagy (via GitHub)" <gi...@apache.org>.
autophagy commented on code in PR #26414:
URL: https://github.com/apache/flink/pull/26414#discussion_r2033173033
##########
flink-python/pyflink/common/types.py:
##########
@@ -108,6 +108,7 @@ def __init__(self, *args, **kwargs):
self._from_dict = True
else:
self._values = list(args)
+ self._from_dict = False
Review Comment:
This would set `self._from_dict` to `{'a': 'pyflink', 'b': True}` rather than a boolean which feels a little unintuitive
--
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