HyukjinKwon commented on a change in pull request #27565: [WIP][SPARK-30791] 
Dataframe add sameSemantics and sementicHash method
URL: https://github.com/apache/spark/pull/27565#discussion_r379342918
 
 

 ##########
 File path: python/pyspark/sql/dataframe.py
 ##########
 @@ -2153,6 +2153,45 @@ def transform(self, func):
                                               "should have been DataFrame." % 
type(result)
         return result
 
+    @since(3.1)
+    def sameSemantics(self, other):
+        """
+        Return true when the query plan of the given :class:`DataFrame` will 
return the same
+        results as this :class:`DataFrame`.
+
+        >>> df1 = spark.createDataFrame([(1, 2),(4, 5)], ["col1", "col2"])
+        >>> df2 = spark.createDataFrame([(1, 2),(4, 5)], ["col0", "col2"])
+        >>> df3 = spark.createDataFrame([(0, 2),(4, 5)], ["col1", "col2"])
+        >>> df4 = spark.createDataFrame([(1, 2),(4, 5)], ["col1", "col2"])
+        >>> df1.sameSemantics(df2)
+        False
+        >>> df1.sameSemantics(df3)
+        False
+        >>> df1.sameSemantics(df4)
+        True
+        """
+        if not isinstance(other, DataFrame):
+            raise ValueError("other parameter should be of DataFrame; however, 
got %s" % type(other))
 
 Review comment:
   Shall we also add one test that checks error message? could be added as 
below (not tested):
   
   ```diff
   diff --git a/python/pyspark/sql/tests/test_dataframe.py 
b/python/pyspark/sql/tests/test_dataframe.py
   index d738449799b..942cd4b4b0e 100644
   --- a/python/pyspark/sql/tests/test_dataframe.py
   +++ b/python/pyspark/sql/tests/test_dataframe.py
   @@ -782,6 +782,11 @@ class DataFrameTests(ReusedSQLTestCase):
                        break
                self.assertEqual(df.take(8), result)
   
   +    def test_same_semantics_error(self):
   +        with QuietTest(self.sc):
   +            with self.assertRaisesRegexp(ValueError, "should be of 
DataFrame.*int"):
   +                self.spark.range(10).sameSemantics(1)
   +
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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

Reply via email to