-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pyspark): builtin udf support (#9191)
Co-authored-by: 祖弼 <ning.ln@alipay.com> Co-authored-by: Phillip Cloud <417981+cpcloud@users.noreply.github.com>
- Loading branch information
1 parent
49ecf8d
commit 142c105
Showing
3 changed files
with
58 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from __future__ import annotations | ||
|
||
import pandas.testing as tm | ||
import pytest | ||
|
||
import ibis | ||
|
||
pytest.importorskip("pyspark") | ||
|
||
|
||
@pytest.fixture | ||
def t(con): | ||
return con.table("basic_table") | ||
|
||
|
||
@pytest.fixture | ||
def df(con): | ||
return con._session.table("basic_table").toPandas() | ||
|
||
|
||
@ibis.udf.scalar.builtin | ||
def repeat(x, n) -> str: ... | ||
|
||
|
||
def test_builtin_udf(t, df): | ||
result = t.mutate(repeated=repeat(t.str_col, 2)).execute() | ||
expected = df.assign(repeated=df.str_col * 2) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
def test_illegal_udf_type(t): | ||
@ibis.udf.scalar.pyarrow | ||
def my_add_one(x) -> str: | ||
import pyarrow.compute as pac | ||
|
||
return pac.add(pac.binary_length(x), 1) | ||
|
||
expr = t.select(repeated=my_add_one(t.str_col)) | ||
|
||
with pytest.raises( | ||
NotImplementedError, | ||
match="Only Builtin UDFs and Pandas UDFs are supported in the PySpark backend", | ||
): | ||
expr.execute() |