WeichenXu123 commented on a change in pull request #27565: [WIP][SPARK-30791][SQL][PYTHON] Add 'sameSemantics' and 'sementicHash' methods in Dataset URL: https://github.com/apache/spark/pull/27565#discussion_r379374685
########## File path: python/pyspark/sql/dataframe.py ########## @@ -2153,6 +2153,50 @@ 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 + >>> df1.sameSemantics(df1) + True + """ + if not isinstance(other, DataFrame): + raise ValueError("other parameter should be of DataFrame; however, got %s" + % type(other)) + return self._jdf.sameSemantics(other._jdf) + + @since(3.1) + def semanticHash(self): + """ + Returns a `hashCode` for the calculation performed by the query plan of this Dataset. + + >>> 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.semanticHash() == df2.semanticHash() + False + >>> df1.semanticHash() == df3.semanticHash() + False + >>> df1.semanticHash() == df4.semanticHash() + True Review comment: emm, let's change unit test. Don't test on dataframe created from in-memory list (LocalRelation), they have different implementation between scala and pyspark. Our usecase also do not care the behavior of LocalRelation. so, I suggested add a unit test on: `spark.range(100)` and do some equivalent transforms on it to see whether `sameSemantic` return True ---------------------------------------------------------------- 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