[PR] [FLINK-35112][Python] Fix membership for Row class PyFlink [flink]

2024-05-05 Thread via GitHub


wzorgdrager opened a new pull request, #24756:
URL: https://github.com/apache/flink/pull/24756

   
   
   ## What is the purpose of the change
   This pull request adds support for a membership check for field names in a 
Row in PyFlink. If field names are not defined, it will check membership in the 
values. For example:
   ```
   user_row = Row(name="Alice", age=22)
   print("name" in user_row)
   # Evaluates to True
   
   user_row = Row("Alice", 22)
   print("Alice" in user_row)
   # Evaluates to True
   ```
   
   This change is more in line with how dictionaries behave in Python. 
   
   
   ## Brief change log
   - Change `in` behaviour for `Row` class.
  - If field names are defined, `KEY in row` will check if  `KEY` exists in 
field names.
  - If field names do not exist, `KEY in row` will check if `KEY` exists in 
field values (current behaviour).
   
   
   ## Verifying this change
   This change is a trivial rework / code cleanup without any test coverage.
   
   ## 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-unsubscr...@flink.apache.org

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



Re: [PR] [FLINK-35112][python] Fix membership for Row class PyFlink [flink]

2024-05-05 Thread via GitHub


flinkbot commented on PR #24756:
URL: https://github.com/apache/flink/pull/24756#issuecomment-2094773254

   
   ## CI report:
   
   * ebca67d26c29e755aef515140ad2aacc6a6e6835 UNKNOWN
   
   
   Bot commands
 The @flinkbot bot supports the following commands:
   
- `@flinkbot run azure` re-run the last Azure build
   


-- 
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-unsubscr...@flink.apache.org

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



Re: [PR] [FLINK-35112][python] Fix membership for Row class PyFlink [flink]

2024-05-06 Thread via GitHub


jectpro7 commented on code in PR #24756:
URL: https://github.com/apache/flink/pull/24756#discussion_r1590740738


##
flink-python/pyflink/common/types.py:
##
@@ -177,7 +177,10 @@ def of_kind(row_kind: RowKind, *args, **kwargs):
 return row
 
 def __contains__(self, item):
-return item in self._values
+if hasattr(self, "_fields"):
+return item in self._fields

Review Comment:
   The enhancement is great. I have one comment, the `_fields` could be a None 
by invoking `set_field_names`. So it should return `False` in this case.



-- 
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-unsubscr...@flink.apache.org

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



Re: [PR] [FLINK-35112][python] Fix membership for Row class PyFlink [flink]

2024-05-07 Thread via GitHub


wzorgdrager commented on code in PR #24756:
URL: https://github.com/apache/flink/pull/24756#discussion_r1592097458


##
flink-python/pyflink/common/types.py:
##
@@ -177,7 +177,10 @@ def of_kind(row_kind: RowKind, *args, **kwargs):
 return row
 
 def __contains__(self, item):
-return item in self._values
+if hasattr(self, "_fields"):
+return item in self._fields

Review Comment:
   so then the question is, if `_fields` is None do we want to fallback and do 
a membership check for the values or always just return False?



-- 
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-unsubscr...@flink.apache.org

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



Re: [PR] [FLINK-35112][python] Fix membership for Row class PyFlink [flink]

2024-05-07 Thread via GitHub


dianfu commented on code in PR #24756:
URL: https://github.com/apache/flink/pull/24756#discussion_r1593302200


##
flink-python/pyflink/common/types.py:
##
@@ -177,7 +177,10 @@ def of_kind(row_kind: RowKind, *args, **kwargs):
 return row
 
 def __contains__(self, item):
-return item in self._values
+if hasattr(self, "_fields"):
+return item in self._fields

Review Comment:
   @wzorgdrager Thanks a lot for the PR. Personally I prefer to fallback to 
check for the values if `_fields` is None.



-- 
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-unsubscr...@flink.apache.org

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



Re: [PR] [FLINK-35112][python] Fix membership for Row class PyFlink [flink]

2024-05-08 Thread via GitHub


wzorgdrager commented on code in PR #24756:
URL: https://github.com/apache/flink/pull/24756#discussion_r1593928221


##
flink-python/pyflink/common/types.py:
##
@@ -177,7 +177,10 @@ def of_kind(row_kind: RowKind, *args, **kwargs):
 return row
 
 def __contains__(self, item):
-return item in self._values
+if hasattr(self, "_fields"):
+return item in self._fields

Review Comment:
   @dianfu I agree. I added the change 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: issues-unsubscr...@flink.apache.org

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



Re: [PR] [FLINK-35112][python] Fix membership for Row class PyFlink [flink]

2024-05-10 Thread via GitHub


dianfu merged PR #24756:
URL: https://github.com/apache/flink/pull/24756


-- 
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-unsubscr...@flink.apache.org

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