wangyum commented on a change in pull request #30315:
URL: https://github.com/apache/spark/pull/30315#discussion_r520565188



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala
##########
@@ -561,14 +548,84 @@ case class InSet(child: Expression, hset: Set[Any]) 
extends UnaryExpression with
   }
 
   override def sql: String = {
-    val valueSQL = child.sql
+    val valueSQL = value.sql
+    val listSQL = list.map(_.sql).mkString(", ")
+    s"($valueSQL IN ($listSQL))"
+  }
+}
+
+/**
+ * Evaluates to `true` if `list` contains `value`.
+ */
+// scalastyle:off line.size.limit
+@ExpressionDescription(
+  usage = "expr1 _FUNC_(expr2, expr3, ...) - Returns true if `expr` equals to 
any valN.",
+  arguments = """
+    Arguments:
+      * expr1, expr2, expr3, ... - the arguments must be same type.
+  """,
+  examples = """
+    Examples:
+      > SELECT 1 _FUNC_(1, 2, 3);
+       true
+      > SELECT 1 _FUNC_(2, 3, 4);
+       false
+      > SELECT named_struct('a', 1, 'b', 2) _FUNC_(named_struct('a', 1, 'b', 
1), named_struct('a', 1, 'b', 3));
+       false
+      > SELECT named_struct('a', 1, 'b', 2) _FUNC_(named_struct('a', 1, 'b', 
2), named_struct('a', 1, 'b', 3));
+       true
+  """,
+  since = "1.0.0")
+// scalastyle:on line.size.limit
+case class In(value: Expression, list: Seq[Expression]) extends BasicIn {
+
+  override def optimized: Boolean = false
+  override def children: Seq[Expression] = value +: list
+
+  override def checkInputDataTypes(): TypeCheckResult = {
+    val mismatchOpt = list.find(l => !DataType.equalsStructurally(l.dataType, 
value.dataType,
+      ignoreNullability = true))
+    if (mismatchOpt.isDefined) {
+      TypeCheckResult.TypeCheckFailure(s"Arguments must be same type but were: 
" +
+        s"${value.dataType.catalogString} != 
${mismatchOpt.get.dataType.catalogString}")
+    } else {
+      TypeUtils.checkForOrderingExpr(value.dataType, s"function $prettyName")
+    }
+  }
+
+  override def toString: String = s"$value IN ${list.mkString("(", ",", ")")}"
+}
+
+/**
+ * Optimized version of In clause, when all filter values of In clause are
+ * static.
+ */
+case class InSet(value: Expression, list: Seq[Expression]) extends BasicIn {

Review comment:
       Could we avoid change `Set[Any]` to `Seq[Expression]`?




----------------------------------------------------------------
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]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to