Skip to content

Commit 0491249

Browse files
committed
address comment: add comments
1 parent 2b00f35 commit 0491249

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,27 @@ abstract class Expression extends TreeNode[Expression] {
199199
* cosmetically (i.e. capitalization of names in attributes may be different).
200200
*
201201
* See [[Canonicalize]] for more details.
202+
*
203+
* This method should be used (instead of `sameResult`) when comparing if 2 expressions are the
204+
* same and one can replace the other (eg. in Optimizer/Analyzer rules when we want to replace
205+
* equivalent expressions). It should not be used (and `sameResult` should be used instead) when
206+
* comparing if 2 expressions produce the same output (in this case `semanticEquals` can be too
207+
* strict).
202208
*/
203209
def semanticEquals(other: Expression): Boolean =
204210
deterministic && other.deterministic && canonicalized == other.canonicalized
205211

206212
/**
207213
* Returns true when two expressions will always compute the same result, even if the output may
208214
* be different, because of different names or similar differences.
209-
* Usually this means they their canonicalized form equals, but it may also not be the case, as
215+
* Usually this means that their canonicalized form equals, but it may also not be the case, as
210216
* different output expressions can evaluate to the same result as well (eg. when an expression
211217
* is aliased).
218+
*
219+
* This method should be used (instead of `semanticEquals`) when checking if 2 expressions
220+
* produce the same output (eg. as in the case we are interested to check if the ordering is the
221+
* same). It should not be used (and `semanticEquals` should be used instead) when comparing if 2
222+
* expressions are the same and one can replace the other.
212223
*/
213224
def sameResult(other: Expression): Boolean = other match {
214225
case a: Alias => sameResult(a.child)

0 commit comments

Comments
 (0)