maomaodev commented on code in PR #7476: URL: https://github.com/apache/kyuubi/pull/7476#discussion_r3788132012
########## extensions/spark/kyuubi-spark-connector-hive/src/main/scala-spark-3.5-plus/org/apache/kyuubi/spark/connector/hive/read/KyuubiOrcColumnarMixin.scala: ########## @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.kyuubi.spark.connector.hive.read + +import org.apache.spark.sql.connector.read.Scan +import org.apache.spark.sql.execution.WholeStageCodegenExec +import org.apache.spark.sql.execution.datasources.orc.OrcUtils +import org.apache.spark.sql.types.StructType + +/** + * Hard prerequisite for [[KyuubiOrcScan]]'s DPP support on Spark 3.5+. + * [[org.apache.spark.sql.connector.read.Scan.ColumnarSupportMode]] is + * introduced in Spark 3.5.0 (SPARK-44505). A no-op trait lives under + * `src/main/scala-spark-pre-3.5/` for Spark 3.3 / 3.4. + * + * With the default [[Scan.ColumnarSupportMode.PARTITION_DEFINED]], + * `DataSourceV2ScanExecBase.supportsColumnar` materialises `inputPartitions` + * during planning to probe each partition's reader factory, which through + * `FileScan.partitions` -> `HiveCatalogFileIndex.listFiles` triggers a + * full-table HDFS listing before runtime filters arrive via + * [[org.apache.spark.sql.connector.read.SupportsRuntimeFiltering.filter]]. + * DPP still prunes the data scan correctly, but its end-to-end win is + * cancelled by this wasted pre-DPP listing. Vanilla Spark sidesteps the + * issue because Hive Parquet/ORC tables fall back to V1 `FileSourceScanExec` + * and never consult [[Scan.columnarSupportMode]]. + */ +trait KyuubiOrcColumnarMixin { this: KyuubiOrcScan => + + /** + * The decision returned here is semantically identical to Spark's + * `OrcPartitionReaderFactory.supportColumnarReads`, so advertising it at + * scan-level is safe. + */ + override def columnarSupportMode(): Scan.ColumnarSupportMode = { + val sqlConf = sparkSession.sessionState.conf + val schema = StructType(readDataSchema.fields ++ readPartitionSchema.fields) + val supportsColumnar = sqlConf.orcVectorizedReaderEnabled && + sqlConf.wholeStageEnabled && + !WholeStageCodegenExec.isTooManyFields(sqlConf, schema) && + schema.forall(s => + OrcUtils.supportColumnarReads( + s.dataType, + sqlConf.orcVectorizedReaderNestedColumnEnabled)) + if (supportsColumnar) Scan.ColumnarSupportMode.SUPPORTED Review Comment: Added to scaladoc of `columnarSupportMode()` in both scans. -- 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]
