You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ru...@apache.org on 2022/11/30 11:16:31 UTC
[spark] branch master updated: [SPARK-41328][CONNECT][PYTHON][FOLLOW-UP] Simplify startsWith and endsWith
This is an automated email from the ASF dual-hosted git repository.
ruifengz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 32b863866a5 [SPARK-41328][CONNECT][PYTHON][FOLLOW-UP] Simplify startsWith and endsWith
32b863866a5 is described below
commit 32b863866a5e4ff88ba3b111cdaefaf9f984039f
Author: Rui Wang <ru...@databricks.com>
AuthorDate: Wed Nov 30 19:15:29 2022 +0800
[SPARK-41328][CONNECT][PYTHON][FOLLOW-UP] Simplify startsWith and endsWith
### What changes were proposed in this pull request?
1. `startsWith` and `endsWith` can be implemented by simplify invoking `_bin_op` with additional documentation.
2. Remove not working examples in the documentation.
### Why are the changes needed?
Codebase simplification.
### Does this PR introduce _any_ user-facing change?
NO
### How was this patch tested?
Existing UT.
Closes #38849 from amaliujia/simplify_strings.
Authored-by: Rui Wang <ru...@databricks.com>
Signed-off-by: Ruifeng Zheng <ru...@apache.org>
---
python/pyspark/sql/connect/column.py | 53 +++++++++++-------------------------
1 file changed, 16 insertions(+), 37 deletions(-)
diff --git a/python/pyspark/sql/connect/column.py b/python/pyspark/sql/connect/column.py
index f9241b0bd58..e02508d6114 100644
--- a/python/pyspark/sql/connect/column.py
+++ b/python/pyspark/sql/connect/column.py
@@ -520,45 +520,24 @@ class Column(object):
"""
return _bin_op("contains")(self, other)
- def startswith(self, other: Union[PrimitiveType, "Column"]) -> "Column":
- """
- String starts with. Returns a boolean :class:`Column` based on a string match.
-
- Parameters
- ----------
- other : :class:`Column` or str
- string at start of line (do not use a regex `^`)
-
- Examples
- --------
- >>> df = spark.createDataFrame(
- ... [(2, "Alice"), (5, "Bob")], ["age", "name"])
- >>> df.filter(df.name.startswith('Al')).collect()
- [Row(age=2, name='Alice')]
- >>> df.filter(df.name.startswith('^Al')).collect()
- []
- """
- return _bin_op("startsWith")(self, other)
+ _startswith_doc = """
+ String starts with. Returns a boolean :class:`Column` based on a string match.
- def endswith(self, other: Union[PrimitiveType, "Column"]) -> "Column":
- """
- String ends with. Returns a boolean :class:`Column` based on a string match.
-
- Parameters
- ----------
- other : :class:`Column` or str
- string at end of line (do not use a regex `$`)
+ Parameters
+ ----------
+ other : :class:`Column` or str
+ string at start of line (do not use a regex `^`)
+ """
+ _endswith_doc = """
+ String ends with. Returns a boolean :class:`Column` based on a string match.
- Examples
- --------
- >>> df = spark.createDataFrame(
- ... [(2, "Alice"), (5, "Bob")], ["age", "name"])
- >>> df.filter(df.name.endswith('ice')).collect()
- [Row(age=2, name='Alice')]
- >>> df.filter(df.name.endswith('ice$')).collect()
- []
- """
- return _bin_op("endsWith")(self, other)
+ Parameters
+ ----------
+ other : :class:`Column` or str
+ string at end of line (do not use a regex `$`)
+ """
+ startswith = _bin_op("startsWith", _startswith_doc)
+ endswith = _bin_op("endsWith", _endswith_doc)
def like(self: "Column", other: str) -> "Column":
"""
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org