maomaodev commented on code in PR #7476:
URL: https://github.com/apache/kyuubi/pull/7476#discussion_r3788125964
##########
extensions/spark/kyuubi-spark-connector-hive/src/main/scala/org/apache/spark/sql/hive/kyuubi/connector/HiveBridgeHelper.scala:
##########
@@ -119,4 +126,74 @@ object HiveBridgeHelper {
implicit class NamespaceHelper(namespace: Array[String]) {
def quoted: String = namespace.map(quoteIfNeeded).mkString(".")
}
+
+ def orcConvertibleFilters(
+ schema: StructType,
+ caseSensitive: Boolean,
+ dataFilters: Seq[Filter]): Seq[Filter] = {
+ val dataTypeMap = OrcFilters.getSearchableTypeMap(schema, caseSensitive)
+ OrcFilters.convertibleFilters(dataTypeMap, dataFilters)
+ }
+
+ def parquetConvertibleFilters(
+ readDataSchema: StructType,
+ dataFilters: Seq[Filter]): Seq[Filter] = {
+ val sqlConf = SQLConf.get
+ val pushDownDate = sqlConf.parquetFilterPushDownDate
+ val pushDownTimestamp = sqlConf.parquetFilterPushDownTimestamp
+ val pushDownDecimal = sqlConf.parquetFilterPushDownDecimal
+ // sqlConf.parquetFilterPushDownStringPredicate is added in 3.4+, so we use
+ // spark.sql.parquet.filterPushdown.string.startsWith to remain compatible
with Spark 3.3
+ val pushDownStringPredicate =
+
sqlConf.getConf(SQLConf.PARQUET_FILTER_PUSHDOWN_STRING_STARTSWITH_ENABLED)
+ val pushDownInFilterThreshold =
sqlConf.parquetFilterPushDownInFilterThreshold
+ val isCaseSensitive = sqlConf.caseSensitiveAnalysis
+ val parquetSchema = new
SparkToParquetSchemaConverter(sqlConf).convert(readDataSchema)
+ val rebaseSpec = rebaseSpecCorrected
+ val parquetFilters = new ParquetFilters(
+ parquetSchema,
+ pushDownDate,
+ pushDownTimestamp,
+ pushDownDecimal,
+ pushDownStringPredicate,
+ pushDownInFilterThreshold,
+ isCaseSensitive,
+ rebaseSpec)
+ parquetFilters.convertibleFilters(dataFilters)
+ }
+
+ /**
+ * `RebaseSpec(LegacyBehaviorPolicy.CORRECTED, None)` constructed via
reflection so
+ * the same code compiles against Spark 3.3 / 3.4 (where
`LegacyBehaviorPolicy` is
+ * nested in `SQLConf`) and Spark 3.5+ (SPARK-44538 promoted it to a
top-level object
+ * under `org.apache.spark.sql.internal`). Cached because the value is
immutable.
+ */
+ private lazy val rebaseSpecCorrected: RebaseSpec = {
+ val policyCls = DynClasses.builder()
+ .impl("org.apache.spark.sql.internal.LegacyBehaviorPolicy$") //
SPARK-44538: Spark 3.5+
+ .impl("org.apache.spark.sql.internal.SQLConf$LegacyBehaviorPolicy$") //
Spark 3.3 / 3.4
+ .buildChecked()
+
+ val policyModule = DynFields.builder()
+ .impl(policyCls, "MODULE$")
+ .buildStaticChecked[AnyRef]()
+ .get()
+
+ val correctedPolicy = DynMethods.builder("CORRECTED")
+ .impl(policyCls)
+ .buildChecked()
+ .invoke[AnyRef](policyModule)
+
+ // `RebaseSpec.mode` is typed as `LegacyBehaviorPolicy.Value`, which after
+ // erasure becomes `scala.Enumeration$Value` in the constructor signature.
+ // Use the erased type explicitly so `DynConstructors` can match exactly.
+ val enumValueCls = Class.forName("scala.Enumeration$Value")
+ DynConstructors.builder()
+ .impl(
+ "org.apache.spark.sql.catalyst.util.RebaseDateTime$RebaseSpec",
Review Comment:
Resolved by rebase. The PR is now based on latest master which drops Spark
3.3 / 3.4 support (#7631).
--
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]