cloud-fan commented on a change in pull request #35768:
URL: https://github.com/apache/spark/pull/35768#discussion_r823417370



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Strategy.scala
##########
@@ -609,20 +543,67 @@ private[sql] object DataSourceV2Strategy {
   }
 
   protected[sql] def rebuildExpressionFromFilter(
-      filter: V2Filter,
-      translatedFilterToExpr: mutable.HashMap[V2Filter, Expression]): 
Expression = {
-    filter match {
-      case and: V2And =>
-        expressions.And(rebuildExpressionFromFilter(and.left, 
translatedFilterToExpr),
-          rebuildExpressionFromFilter(and.right, translatedFilterToExpr))
-      case or: V2Or =>
-        expressions.Or(rebuildExpressionFromFilter(or.left, 
translatedFilterToExpr),
-          rebuildExpressionFromFilter(or.right, translatedFilterToExpr))
-      case not: V2Not =>
-        expressions.Not(rebuildExpressionFromFilter(not.child, 
translatedFilterToExpr))
-      case other =>
-        translatedFilterToExpr.getOrElse(other,
-          throw new IllegalStateException("Failed to rebuild Expression for 
filter: " + filter))
+      predicate: V2Predicate,
+      translatedFilterToExpr: mutable.HashMap[V2Predicate, Expression]): 
Expression = {
+    predicate.name() match {
+      case "AND" =>
+        expressions.And(
+          
rebuildExpressionFromFilter(predicate.children()(0).asInstanceOf[V2Predicate],
+            translatedFilterToExpr),
+          
rebuildExpressionFromFilter(predicate.children()(1).asInstanceOf[V2Predicate],
+            translatedFilterToExpr))
+      case "OR" =>
+        expressions.Or(
+          
rebuildExpressionFromFilter(predicate.children()(0).asInstanceOf[V2Predicate],
+            translatedFilterToExpr),
+          
rebuildExpressionFromFilter(predicate.children()(1).asInstanceOf[V2Predicate],
+            translatedFilterToExpr))
+      case "NOT" =>

Review comment:
       For AND, OR, NOT, their children must be `Predicate` as well. To get 
more type safety, we can create dedicated classes for these 3:
   ```
   class And extends Predicate {
     Predicate left;
     Predicate right;
   }
   ```




-- 
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: [email protected]

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