-
Notifications
You must be signed in to change notification settings - Fork 28.8k
[SPARK-52976][PYTHON] Fix Python UDF not accepting collated string as input param/return type #51688
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
[SPARK-52976][PYTHON] Fix Python UDF not accepting collated string as input param/return type #51688
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3490,6 +3490,41 @@ def eval(self): | |
udtf(TestUDTF, returnType=ret_type)().collect() | ||
|
||
|
||
def test_udtf_with_collated_string_types(self): | ||
@udtf( | ||
"out1 string, out2 string collate UTF8_BINARY, out3 string collate UTF8_LCASE," | ||
" out4 string collate UNICODE" | ||
) | ||
class MyUDTF: | ||
ilicmarkodb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def eval(self, v1, v2, v3, v4): | ||
yield (v1 + "1", v2 + "2", v3 + "3", v4 + "4") | ||
|
||
schema = StructType( | ||
[ | ||
StructField("col1", StringType(), True), | ||
StructField("col2", StringType("UTF8_BINARY"), True), | ||
StructField("col3", StringType("UTF8_LCASE"), True), | ||
StructField("col4", StringType("UNICODE"), True), | ||
] | ||
) | ||
df = self.spark.createDataFrame([("hello",) * 4], schema=schema) | ||
|
||
df_out = df.select(MyUDTF(df.col1, df.col2, df.col3, df.col4).alias("out")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this query work? I guess it should be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn’t. I just didn’t realize that, since the test wasn't executed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PTAL #51688 |
||
result_df = df_out.select("out.*") | ||
|
||
expected_row = ("hello1", "hello2", "hello3", "hello4") | ||
self.assertEqual(result_df.collect()[0], expected_row) | ||
|
||
expected_output_types = [ | ||
StringType(), | ||
StringType("UTF8_BINARY"), | ||
StringType("UTF8_LCASE"), | ||
StringType("UNICODE"), | ||
] | ||
for idx, field in enumerate(result_df.schema.fields): | ||
self.assertEqual(field.dataType, expected_output_types[idx]) | ||
|
||
|
||
class UDTFArrowTests(UDTFArrowTestsMixin, ReusedSQLTestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ilicmarkodb the indent here is wrong, this test is actually skipped. It should be put into a Mixin class like
BaseUDTFTestsMixin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#52001
I opened a PR to fix this. I’ll finish it and tag you for review once the CI is green.