Github user mgaido91 commented on a diff in the pull request:
https://github.com/apache/spark/pull/22029#discussion_r229706218
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
---
@@ -212,27 +212,27 @@ object ReorderAssociativeOperator extends
Rule[LogicalPlan] {
* 1. Converts the predicate to false when the list is empty and
* the value is not nullable.
* 2. Removes literal repetitions.
- * 3. Replaces [[In (value, seq[Literal])]] with optimized version
+ * 3. Replaces [[In (values, seq[Literal])]] with optimized version
* [[InSet (value, HashSet[Literal])]] which is much faster.
*/
object OptimizeIn extends Rule[LogicalPlan] {
def apply(plan: LogicalPlan): LogicalPlan = plan transform {
case q: LogicalPlan => q transformExpressionsDown {
- case In(v, list) if list.isEmpty =>
+ case i @ In(_, list) if list.isEmpty =>
// When v is not nullable, the following expression will be
optimized
// to FalseLiteral which is tested in OptimizeInSuite.scala
- If(IsNotNull(v), FalseLiteral, Literal(null, BooleanType))
- case expr @ In(v, list) if expr.inSetConvertible =>
+ If(IsNotNull(i.value), FalseLiteral, Literal(null, BooleanType))
+ case expr @ In(_, list) if expr.inSetConvertible =>
val newList = ExpressionSet(list).toSeq
if (newList.length == 1
// TODO: `EqualTo` for structural types are not working. Until
SPARK-24443 is addressed,
// TODO: we exclude them in this rule.
- && !v.isInstanceOf[CreateNamedStructLike]
+ && !expr.value.isInstanceOf[CreateNamedStructLike]
--- End diff --
not really, because `expr.value.isInstanceOf[CreateNamedStructLike]` means:
- either `expr.values.length == 1`;
- or `expr.values.head.isInstanceOf[CreateNamedStructLike]`;
Basically there are 2 cases: one where we have several attributes in the
value before IN; the other when there is a single value before IN but the value
is a struct. `expr.value.isInstanceOf[CreateNamedStructLike]` catches both. I
can add a comment explaining these 2 cases if you think is needed.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]