Skip to content

[SPARK-23081][PYTHON]Add colRegex API to PySpark #20390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions python/pyspark/sql/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,29 @@ def columns(self):
"""
return [f.name for f in self.schema.fields]

@since(2.3)
def colRegex(self, colName):
"""
Selects column based on the column name specified as a regex and returns it
as :class:`Column`.

:param colName: string, column name specified as a regex.

>>> df = spark.createDataFrame([("a", 1), ("b", 2), ("c", 3)], ["Col1", "Col2"])
>>> df.select(df.colRegex("`(Col1)?+.+`")).show()
+----+
|Col2|
+----+
| 1|
| 2|
| 3|
+----+
"""
if not isinstance(colName, basestring):
raise ValueError("colName should be provided as string")
jc = self._jdf.colRegex(colName)
return Column(jc)

@ignore_unicode_prefix
@since(1.3)
def alias(self, alias):
Expand Down
8 changes: 4 additions & 4 deletions sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ class Dataset[T] private[sql](
def orderBy(sortExprs: Column*): Dataset[T] = sort(sortExprs : _*)

/**
* Selects column based on the column name and return it as a [[Column]].
* Selects column based on the column name and returns it as a [[Column]].
*
* @note The column name can also reference to a nested column like `a.b`.
*
Expand All @@ -1220,7 +1220,7 @@ class Dataset[T] private[sql](
}

/**
* Selects column based on the column name and return it as a [[Column]].
* Selects column based on the column name and returns it as a [[Column]].
*
* @note The column name can also reference to a nested column like `a.b`.
*
Expand All @@ -1240,7 +1240,7 @@ class Dataset[T] private[sql](
}

/**
* Selects column based on the column name specified as a regex and return it as [[Column]].
* Selects column based on the column name specified as a regex and returns it as [[Column]].
* @group untypedrel
* @since 2.3.0
*/
Expand Down Expand Up @@ -2729,7 +2729,7 @@ class Dataset[T] private[sql](
}

/**
* Return an iterator that contains all rows in this Dataset.
* Returns an iterator that contains all rows in this Dataset.
*
* The iterator will consume as much memory as the largest partition in this Dataset.
*
Expand Down