Github user zero323 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17077#discussion_r110692936
  
    --- Diff: python/pyspark/sql/tests.py ---
    @@ -2167,6 +2167,61 @@ def test_BinaryType_serialization(self):
             df = self.spark.createDataFrame(data, schema=schema)
             df.collect()
     
    +    def test_bucketed_write(self):
    +        data = [
    +            (1, "foo", 3.0), (2, "foo", 5.0),
    +            (3, "bar", -1.0), (4, "bar", 6.0),
    +        ]
    +        df = self.spark.createDataFrame(data, ["x", "y", "z"])
    +
    +        # Test write with one bucketing column
    +        df.write.bucketBy(3, 
"x").mode("overwrite").saveAsTable("pyspark_bucket")
    +        self.assertEqual(
    +            len([c for c in 
self.spark.catalog.listColumns("pyspark_bucket")
    +                 if c.name == "x" and c.isBucket]),
    +            1
    +        )
    +        self.assertSetEqual(set(data), 
set(self.spark.table("pyspark_bucket").collect()))
    +
    +        # Test write two bucketing columns
    +        df.write.bucketBy(3, "x", 
"y").mode("overwrite").saveAsTable("pyspark_bucket")
    +        self.assertEqual(
    +            len([c for c in 
self.spark.catalog.listColumns("pyspark_bucket")
    +                 if c.name in ("x", "y") and c.isBucket]),
    +            2
    +        )
    +        self.assertSetEqual(set(data), 
set(self.spark.table("pyspark_bucket").collect()))
    +
    +        # Test write with bucket and sort
    +        df.write.bucketBy(2, 
"x").sortBy("z").mode("overwrite").saveAsTable("pyspark_bucket")
    +        self.assertEqual(
    +            len([c for c in 
self.spark.catalog.listColumns("pyspark_bucket")
    +                 if c.name == "x" and c.isBucket]),
    +            1
    +        )
    +        self.assertSetEqual(set(data), 
set(self.spark.table("pyspark_bucket").collect()))
    +
    +        # Test write with a list of columns
    +        df.write.bucketBy(3, ["x", 
"y"]).mode("overwrite").saveAsTable("pyspark_bucket")
    +        self.assertEqual(
    +            len([c for c in 
self.spark.catalog.listColumns("pyspark_bucket")
    +                 if c.name in ("x", "y") and c.isBucket]),
    +            2
    +        )
    +        self.assertSetEqual(set(data), 
set(self.spark.table("pyspark_bucket").collect()))
    +
    +        # Test write with bucket and sort with a list of columns
    +        (df.write.bucketBy(2, "x")
    +            .sortBy(["y", "z"])
    +            .mode("overwrite").saveAsTable("pyspark_bucket"))
    +        self.assertSetEqual(set(data), 
set(self.spark.table("pyspark_bucket").collect()))
    +
    +        # Test write with bucket and sort with multiple columns
    +        (df.write.bucketBy(2, "x")
    +            .sortBy("y", "z")
    +            .mode("overwrite").saveAsTable("pyspark_bucket"))
    --- End diff --
    
    I don't think that dropping before is necessary. We override on each write 
and name clashes are unlikely.
    
    We can drop down after the tests but I am not sure how to do it right. 
`SQLTests` is overgrown and I am not sure if we should add `tearDown`  only for 
this but adding `DROP TABLE` in test itself doesn't look right.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to