当您点击源按钮时
the 3.1.2 doc
您可以找到的源代码
regexp_replace
:
def regexp_replace(str, pattern, replacement):
r"""Replace all substrings of the specified string value that match regexp with rep.
.. versionadded:: 1.5.0
Examples
--------
>>> df = spark.createDataFrame([('100-200',)], ['str'])
>>> df.select(regexp_replace('str', r'(\d+)', '--').alias('d')).collect()
[Row(d='-----')]
"""
sc = SparkContext._active_spark_context
jc = sc._jvm.functions.regexp_replace(_to_java_column(str), pattern, replacement)
return Column(jc)
你看
str
参数不是直接使用的,而是包含在
_to_java_column
功能。这个
source code of
_to_java_column
清楚地表明,它既适用于列名(字符串),也适用于列对象:
def _to_java_column(col: "ColumnOrName") -> "JavaObject":
if isinstance(col, Column):
jcol = col._jc
elif isinstance(col, str):
jcol = _create_column_from_name(col)
else:
raise PySparkTypeError(
errorClass="NOT_COLUMN_OR_STR",
messageParameters={"arg_name": "col", "arg_type": type(col).__name__},
)
return jcol
浏览源页面时
functions
你看
_to_java_column
是无所不在的,这意味着对于大多数函数(甚至所有函数,但我没有检查),列对象的两个列名都可以使用。