xinrong-meng commented on code in PR #49055:
URL: https://github.com/apache/spark/pull/49055#discussion_r1900590578
##########
python/pyspark/sql/tests/test_udtf.py:
##########
@@ -1064,6 +1074,73 @@ def eval(self, row: Row):
func = udtf(TestUDTF, returnType="a: int")
return func
+ def test_df_asTable_chaining_methods(self):
+ class TestUDTF:
+ def eval(self, row: Row):
+ yield row["key"], row["value"]
+
+ def terminate(self):
+ if False:
+ yield
+
+ func = udtf(TestUDTF, returnType="key: int, value: string")
+ df = self.spark.createDataFrame([(1, "a"), (1, "b"), (2, "c"), (2,
"d")], ["key", "value"])
+ assertDataFrameEqual(
+ func(df.asTable().partitionBy(df.key).orderBy(df.value)),
+ [
+ Row(key=1, value="a"),
+ Row(key=1, value="b"),
+ Row(key=2, value="c"),
+ Row(key=2, value="d"),
+ ],
+ checkRowOrder=True,
+ )
+
+ assertDataFrameEqual(
+ func(df.asTable().partitionBy(df.key).orderBy(df.value.desc())),
+ [
+ Row(key=1, value="b"),
+ Row(key=1, value="a"),
+ Row(key=2, value="d"),
+ Row(key=2, value="c"),
+ ],
+ checkRowOrder=True,
+ )
+
+ assertDataFrameEqual(
+ func(df.asTable().withSinglePartition()),
+ [
+ Row(key=1, value="a"),
+ Row(key=1, value="b"),
+ Row(key=2, value="c"),
+ Row(key=2, value="d"),
+ ],
+ )
+
+ with self.assertRaisesRegex(
+ IllegalArgumentException,
+ r"Cannot call withSinglePartition\(\) after partitionBy\(\) has
been called",
+ ):
+ df.asTable().partitionBy(df.key).withSinglePartition()
+
+ with self.assertRaisesRegex(
+ IllegalArgumentException,
+ r"Cannot call partitionBy\(\) after withSinglePartition\(\) has
been called",
+ ):
+ df.asTable().withSinglePartition().partitionBy(df.key)
+
+ with self.assertRaisesRegex(
+ IllegalArgumentException,
+ r"Please call partitionBy\(\) before orderBy\(\)",
+ ):
+ df.asTable().orderBy(df.key)
+
+ with self.assertRaisesRegex(
+ IllegalArgumentException,
+ r"partitionBy\(\) can only be specified once.",
+ ):
+ df.asTable().partitionBy(df.key).partitionBy()
+
Review Comment:
`def partitionBy(self, *cols: "ColumnOrName") -> "TableArg":`
does not accept keyword arguments, would you clarify what we are expecting
here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]