You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/11/28 06:44:29 UTC

[GitHub] [spark] zhengruifeng commented on a diff in pull request #38801: [SPARK-40539] [CONNECT] [PYTHON] Add basic support for DataFrameWriter

zhengruifeng commented on code in PR #38801:
URL: https://github.com/apache/spark/pull/38801#discussion_r1033169179


##########
python/pyspark/sql/tests/connect/test_connect_basic.py:
##########
@@ -566,6 +569,27 @@ def test_agg_with_two_agg_exprs(self):
             self.spark.read.table(self.tbl_name).agg({"name": "min", "id": "max"}).toPandas(),
         )
 
+    def test_write_operations(self):
+        with tempfile.TemporaryDirectory() as d:
+            df = self.connect.range(1, 100)
+            df.write.mode("overwrite").format("csv").save(d)
+
+            ndf = self.connect.read.load(d, format="csv")
+            df.toPandas().equals(ndf.toPandas())
+
+        with tempfile.TemporaryDirectory() as d:
+            df = self.connect.range(1, 100)
+            df.write.mode("overwrite").csv(d, lineSep="|")
+
+            ndf = self.connect.read.load(d, format="csv", lineSep="|")
+            df.toPandas().equals(ndf.toPandas())
+
+        df = self.connect.range(1, 100)
+        df.write.format("parquet").saveAsTable("parquet_test")
+
+        ndf = self.connect.read.table("parquet_test")
+        df.toPandas().equals(ndf.toPandas())

Review Comment:
   ditto



##########
python/pyspark/sql/tests/connect/test_connect_basic.py:
##########
@@ -566,6 +569,27 @@ def test_agg_with_two_agg_exprs(self):
             self.spark.read.table(self.tbl_name).agg({"name": "min", "id": "max"}).toPandas(),
         )
 
+    def test_write_operations(self):
+        with tempfile.TemporaryDirectory() as d:
+            df = self.connect.range(1, 100)
+            df.write.mode("overwrite").format("csv").save(d)
+
+            ndf = self.connect.read.load(d, format="csv")
+            df.toPandas().equals(ndf.toPandas())

Review Comment:
   we'd better use `self.assertEqual` instead, otherwise it will be painful to debug if it fails



##########
python/pyspark/sql/tests/connect/test_connect_basic.py:
##########
@@ -566,6 +569,27 @@ def test_agg_with_two_agg_exprs(self):
             self.spark.read.table(self.tbl_name).agg({"name": "min", "id": "max"}).toPandas(),
         )
 
+    def test_write_operations(self):
+        with tempfile.TemporaryDirectory() as d:
+            df = self.connect.range(1, 100)
+            df.write.mode("overwrite").format("csv").save(d)
+
+            ndf = self.connect.read.load(d, format="csv")
+            df.toPandas().equals(ndf.toPandas())
+
+        with tempfile.TemporaryDirectory() as d:
+            df = self.connect.range(1, 100)
+            df.write.mode("overwrite").csv(d, lineSep="|")
+
+            ndf = self.connect.read.load(d, format="csv", lineSep="|")
+            df.toPandas().equals(ndf.toPandas())

Review Comment:
   ditto



##########
python/pyspark/sql/connect/writer.py:
##########
@@ -0,0 +1,926 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+from typing import Optional, Union, List, overload, Tuple, cast, Any
+from typing import TYPE_CHECKING
+
+from pyspark.sql.connect.plan import WriteOperation, LogicalPlan
+from pyspark.sql.types import StructType
+from pyspark.sql.utils import to_str
+
+if TYPE_CHECKING:
+    from pyspark.sql.connect._typing import OptionalPrimitiveType
+    from pyspark.sql.connect.session import SparkSession
+
+
+PathOrPaths = Union[str, List[str]]
+TupleOrListOfString = Union[List[str], Tuple[str, ...]]
+
+
+class OptionUtils:

Review Comment:
   can this also be used in `DataFrameReader`?



##########
python/pyspark/sql/connect/writer.py:
##########
@@ -0,0 +1,926 @@
+#

Review Comment:
   why creating a separate file?
   
   should it be in `readwriter.py`?



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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