ajantha-bhat commented on a change in pull request #3757: URL: https://github.com/apache/iceberg/pull/3757#discussion_r771769167
########## File path: spark/v3.2/spark/src/main/scala/org/apache/spark/sql/execution/datasources/SparkExpressionConverter.scala ########## @@ -30,4 +34,18 @@ object SparkExpressionConverter { // But these two conversions already exist and well tested. So, we are going with this approach. SparkFilters.convert(DataSourceStrategy.translateFilter(sparkExpression, supportNestedPredicatePushdown = true).get) } + + @throws[AnalysisException] + def collectResolvedSparkExpression(session: SparkSession, tableName: String, where: String): Expression = { + var expression:Expression = null + // Add a dummy prefix linking to the table to collect the resolved spark expression from analyzed plan. + val prefix = String.format("SELECT 42 from %s where ", tableName) + val logicalPlan = session.sessionState.sqlParser.parsePlan(prefix + where) + val analyzedLogicalPlan = session.sessionState.executePlan(logicalPlan, CommandExecutionMode.ALL).analyzed + analyzedLogicalPlan.collectFirst { + case filter: Filter => + expression = filter.expressions.head + } + expression Review comment: a. we can't use SparkFilters.convert, as Filter in plan is `org.apache.spark.sql.catalyst.plans.logical.Filter` and Filter in SparkFilters.convert is `org.apache.spark.sql.sources.Filter` b. I think we can use collectFirst as the plan is fixed always as query is fixed. It is simple Project + Filter + scan operators in the pan. -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org