Skip to content

Commit ee0f692

Browse files
uros-dbHyukjinKwon
authored andcommitted
[SPARK-54151][GEO][PYTHON][FOLLOWUP] Update examples for ST functions in PySpark
### What changes were proposed in this pull request? Make a few updates to ST functions in PySpark: - Remove alias `result`. - Separate examples. ### Why are the changes needed? Improve clarity. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Existing tests suffice. ``` python/run-tests --testnames pyspark.sql.functions.builtin ``` ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#53125 from uros-db/geo-pyspark-st-examples. Authored-by: Uros Bojanic <[email protected]> Signed-off-by: Hyukjin Kwon <[email protected]>
1 parent 61668ad commit ee0f692

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

python/pyspark/sql/functions/builtin.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26085,14 +26085,18 @@ def st_asbinary(geo: "ColumnOrName") -> Column:
2608526085

2608626086
Examples
2608726087
--------
26088+
26089+
Example 1: Getting WKB from GEOGRAPHY.
2608826090
>>> from pyspark.sql import functions as sf
2608926091
>>> df = spark.createDataFrame([(bytes.fromhex('0101000000000000000000F03F0000000000000040'),)], ['wkb']) # noqa
26090-
>>> df.select(sf.hex(sf.st_asbinary(sf.st_geogfromwkb('wkb'))).alias('result')).collect()
26091-
[Row(result='0101000000000000000000F03F0000000000000040')]
26092+
>>> df.select(sf.hex(sf.st_asbinary(sf.st_geogfromwkb('wkb')))).collect()
26093+
[Row(hex(st_asbinary(st_geogfromwkb(wkb)))='0101000000000000000000F03F0000000000000040')]
26094+
26095+
Example 2: Getting WKB from GEOMETRY.
2609226096
>>> from pyspark.sql import functions as sf
2609326097
>>> df = spark.createDataFrame([(bytes.fromhex('0101000000000000000000F03F0000000000000040'),)], ['wkb']) # noqa
26094-
>>> df.select(sf.hex(sf.st_asbinary(sf.st_geomfromwkb('wkb'))).alias('result')).collect()
26095-
[Row(result='0101000000000000000000F03F0000000000000040')]
26098+
>>> df.select(sf.hex(sf.st_asbinary(sf.st_geomfromwkb('wkb')))).collect()
26099+
[Row(hex(st_asbinary(st_geomfromwkb(wkb)))='0101000000000000000000F03F0000000000000040')]
2609626100
"""
2609726101
return _invoke_function_over_columns("st_asbinary", geo)
2609826102

@@ -26112,8 +26116,8 @@ def st_geogfromwkb(wkb: "ColumnOrName") -> Column:
2611226116
--------
2611326117
>>> from pyspark.sql import functions as sf
2611426118
>>> df = spark.createDataFrame([(bytes.fromhex('0101000000000000000000F03F0000000000000040'),)], ['wkb']) # noqa
26115-
>>> df.select(sf.hex(sf.st_asbinary(sf.st_geogfromwkb('wkb'))).alias('result')).collect()
26116-
[Row(result='0101000000000000000000F03F0000000000000040')]
26119+
>>> df.select(sf.hex(sf.st_asbinary(sf.st_geogfromwkb('wkb')))).collect()
26120+
[Row(hex(st_asbinary(st_geogfromwkb(wkb)))='0101000000000000000000F03F0000000000000040')]
2611726121
"""
2611826122
return _invoke_function_over_columns("st_geogfromwkb", wkb)
2611926123

@@ -26133,8 +26137,8 @@ def st_geomfromwkb(wkb: "ColumnOrName") -> Column:
2613326137
--------
2613426138
>>> from pyspark.sql import functions as sf
2613526139
>>> df = spark.createDataFrame([(bytes.fromhex('0101000000000000000000F03F0000000000000040'),)], ['wkb']) # noqa
26136-
>>> df.select(sf.hex(sf.st_asbinary(sf.st_geomfromwkb('wkb'))).alias('result')).collect()
26137-
[Row(result='0101000000000000000000F03F0000000000000040')]
26140+
>>> df.select(sf.hex(sf.st_asbinary(sf.st_geomfromwkb('wkb')))).collect()
26141+
[Row(hex(st_asbinary(st_geomfromwkb(wkb)))='0101000000000000000000F03F0000000000000040')]
2613826142
"""
2613926143
return _invoke_function_over_columns("st_geomfromwkb", wkb)
2614026144

@@ -26152,14 +26156,18 @@ def st_srid(geo: "ColumnOrName") -> Column:
2615226156

2615326157
Examples
2615426158
--------
26159+
26160+
Example 1: Getting the SRID of GEOGRAPHY.
2615526161
>>> from pyspark.sql import functions as sf
2615626162
>>> df = spark.createDataFrame([(bytes.fromhex('0101000000000000000000F03F0000000000000040'),)], ['wkb']) # noqa
26157-
>>> df.select(sf.st_srid(sf.st_geogfromwkb('wkb')).alias('result')).collect()
26158-
[Row(result=4326)]
26163+
>>> df.select(sf.st_srid(sf.st_geogfromwkb('wkb'))).collect()
26164+
[Row(st_srid(st_geogfromwkb(wkb))=4326)]
26165+
26166+
Example 2: Getting the SRID of GEOMETRY.
2615926167
>>> from pyspark.sql import functions as sf
2616026168
>>> df = spark.createDataFrame([(bytes.fromhex('0101000000000000000000F03F0000000000000040'),)], ['wkb']) # noqa
26161-
>>> df.select(sf.st_srid(sf.st_geomfromwkb('wkb')).alias('result')).collect()
26162-
[Row(result=0)]
26169+
>>> df.select(sf.st_srid(sf.st_geomfromwkb('wkb'))).collect()
26170+
[Row(st_srid(st_geomfromwkb(wkb))=0)]
2616326171
"""
2616426172
return _invoke_function_over_columns("st_srid", geo)
2616526173

0 commit comments

Comments
 (0)