From 2beb7ed9b2deb81734397644c67ca340febd0f8a Mon Sep 17 00:00:00 2001 From: Gengliang Wang Date: Wed, 19 Feb 2025 18:20:23 -0800 Subject: [PATCH] [SPARK-51260][SQL] Move V2ExpressionBuilder and PushableExpression to Catalyst module ### What changes were proposed in this pull request? The class `V2ExpressionBuilder` is under the package `org.apache.spark.sql.catalyst.util` while the file path is under the SQL Core module. The file path should be under the SQL Catalyst module instead. Since V2ExpressionBuilder references the object PushableExpression, this PR moves it to the Catalyst module as well. ### Why are the changes needed? 1. Code clean up. Remove the `../catalyst/util` folder under `sql/core` 2. After refactoring, V2ExpressionBuilder and PushableExpression can be accessed from the Catalyst module. This will be useful for new projects like V2 constraints. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? GA ### Was this patch authored or co-authored using generative AI tooling? No Closes #50011 from gengliangwang/move. Authored-by: Gengliang Wang Signed-off-by: Gengliang Wang --- .../spark/sql/catalyst/util/V2ExpressionBuilder.scala | 8 +++++++- .../sql/execution/datasources/DataSourceStrategy.scala | 9 +-------- 2 files changed, 8 insertions(+), 9 deletions(-) rename sql/{core => catalyst}/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala (99%) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala similarity index 99% rename from sql/core/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala rename to sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala index 23ae5ee7b9be4..fad73a6d81464 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala @@ -26,7 +26,6 @@ import org.apache.spark.sql.connector.catalog.functions.ScalarFunction import org.apache.spark.sql.connector.expressions.{Cast => V2Cast, Expression => V2Expression, Extract => V2Extract, FieldReference, GeneralScalarExpression, LiteralValue, NullOrdering, SortDirection, SortValue, UserDefinedScalarFunc} import org.apache.spark.sql.connector.expressions.aggregate.{AggregateFunc, Avg, Count, CountStar, GeneralAggregateFunc, Max, Min, Sum, UserDefinedAggregateFunc} import org.apache.spark.sql.connector.expressions.filter.{AlwaysFalse, AlwaysTrue, And => V2And, Not => V2Not, Or => V2Or, Predicate => V2Predicate} -import org.apache.spark.sql.execution.datasources.PushableExpression import org.apache.spark.sql.internal.SQLConf import org.apache.spark.sql.types.{BooleanType, DataType, IntegerType, StringType} @@ -451,3 +450,10 @@ object ColumnOrField { case _ => None } } + +/** + * Get the expression of DS V2 to represent catalyst expression that can be pushed down. + */ +object PushableExpression { + def unapply(e: Expression): Option[V2Expression] = new V2ExpressionBuilder(e).build() +} diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSourceStrategy.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSourceStrategy.scala index 32decd9c429da..2f6588c3aac35 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSourceStrategy.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSourceStrategy.scala @@ -40,7 +40,7 @@ import org.apache.spark.sql.catalyst.plans.logical.{AppendData, InsertIntoDir, I import org.apache.spark.sql.catalyst.rules.Rule import org.apache.spark.sql.catalyst.streaming.StreamingRelationV2 import org.apache.spark.sql.catalyst.types.DataTypeUtils -import org.apache.spark.sql.catalyst.util.{GeneratedColumn, IdentityColumn, ResolveDefaultColumns, V2ExpressionBuilder} +import org.apache.spark.sql.catalyst.util.{GeneratedColumn, IdentityColumn, PushableExpression, ResolveDefaultColumns} import org.apache.spark.sql.classic.{SparkSession, Strategy} import org.apache.spark.sql.connector.catalog.{SupportsRead, V1Table} import org.apache.spark.sql.connector.catalog.TableCapability._ @@ -866,10 +866,3 @@ object PushableColumnAndNestedColumn extends PushableColumnBase { object PushableColumnWithoutNestedColumn extends PushableColumnBase { override val nestedPredicatePushdownEnabled = false } - -/** - * Get the expression of DS V2 to represent catalyst expression that can be pushed down. - */ -object PushableExpression { - def unapply(e: Expression): Option[V2Expression] = new V2ExpressionBuilder(e).build() -}