HyukjinKwon 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_r379368127
##########
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:
If this is the case, we might have to leave an explicit caveat that false
positive case possible. Also we might have to mark those APIs as `@Unstable` or
`@Experimental` due to this reason cc @mengxr.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]