cloud-fan commented on a change in pull request #35768: URL: https://github.com/apache/spark/pull/35768#discussion_r823413184
########## File path: sql/core/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala ########## @@ -41,29 +44,63 @@ class V2ExpressionBuilder(e: Expression) { private def generateExpression(expr: Expression): Option[V2Expression] = expr match { case Literal(value, dataType) => Some(LiteralValue(value, dataType)) - case attr: Attribute => Some(FieldReference.column(attr.name)) + case pushableColumn(name) if nestedPredicatePushdownEnabled => + Some(FieldReference(name)) + case pushableColumn(name) if !nestedPredicatePushdownEnabled => + Some(FieldReference.column(name)) + case in @ InSet(child, hset) => + generateExpression(child).map { v => + val children = + (v +: hset.toSeq.map(elem => LiteralValue(elem, in.dataType))).toArray[V2Expression] + new V2Predicate("IN", children) + } + // Because we only convert In to InSet in Optimizer when there are more than certain + // items. So it is possible we still get an In expression here that needs to be pushed + // down. + case In(value, list) => + val v = generateExpression(value) + val listExpressions = list.flatMap(generateExpression) + if (v.isDefined && list.length == listExpressions.length) { + val children = (v.get +: listExpressions).toArray[V2Expression] + // The children looks like [expr, value1, ..., valueN] + Some(new V2Predicate("IN", children)) + } else { + None + } case IsNull(col) => generateExpression(col) - .map(c => new GeneralScalarExpression("IS_NULL", Array[V2Expression](c))) + .map(c => new V2Predicate("IS_NULL", Array[V2Expression](c))) case IsNotNull(col) => generateExpression(col) - .map(c => new GeneralScalarExpression("IS_NOT_NULL", Array[V2Expression](c))) + .map(c => new V2Predicate("IS_NOT_NULL", Array[V2Expression](c))) + case p: StringPredicate => + val left = generateExpression(p.left) + val right = generateExpression(p.right) + if (left.isDefined && right.isDefined) { + Some(new V2Predicate(p.nodeName, Array[V2Expression](left.get, right.get))) + } else { + None + } case b: BinaryOperator if canTranslate(b) => val left = generateExpression(b.left) val right = generateExpression(b.right) if (left.isDefined && right.isDefined) { - Some(new GeneralScalarExpression(b.sqlOperator, Array[V2Expression](left.get, right.get))) + if (b.isInstanceOf[Predicate]) { Review comment: More specifically, I think we are only targeting `BinaryComparison`? -- 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. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org