KnightChess commented on code in PR #11043: URL: https://github.com/apache/hudi/pull/11043#discussion_r1611759448
########## hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/analysis/HoodiePruneFileSourceFiles.scala: ########## @@ -0,0 +1,146 @@ +/* + * 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.spark.sql.hudi.analysis + +import org.apache.hudi.HoodieFileIndex.DataSkippingFailureMode +import org.apache.hudi.SparkAdapterSupport.sparkAdapter +import org.apache.hudi.exception.HoodieException +import org.apache.hudi.{HoodieBaseRelation, HoodieFileIndex} +import org.apache.spark.sql.SparkSession +import org.apache.spark.sql.catalyst.catalog.CatalogStatistics +import org.apache.spark.sql.catalyst.expressions.{And, AttributeReference, AttributeSet, Expression, ExpressionSet, NamedExpression, PredicateHelper, SubqueryExpression} +import org.apache.spark.sql.catalyst.planning.PhysicalOperation +import org.apache.spark.sql.catalyst.plans.logical.statsEstimation.FilterEstimation +import org.apache.spark.sql.catalyst.plans.logical.{Filter, LeafNode, LogicalPlan, Project} +import org.apache.spark.sql.catalyst.rules.Rule +import org.apache.spark.sql.execution.datasources.{HadoopFsRelation, LogicalRelation} +import org.apache.spark.sql.hudi.analysis.HoodiePruneFileSourceFiles.{HoodieRelationMatcher, exprUtils, getPartitionFiltersAndDataFilters, rebuildPhysicalOperation} +import org.apache.spark.sql.sources.BaseRelation +import org.apache.spark.sql.types.StructType + +import scala.util.{Failure, Success} + +case class HoodiePruneFileSourceFiles(spark: SparkSession) extends Rule[LogicalPlan] { Review Comment: It seems like can create a separate mr for support, as it doesn't seem to be directly related to the current functionality? ########## hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/BloomFiltersIndexSupport.scala: ########## @@ -0,0 +1,94 @@ +/* + * 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.hudi + +import org.apache.hudi.HoodieConversionUtils.toScalaOption +import org.apache.hudi.RecordLevelIndexSupport.filterQueryWithRecordKey +import org.apache.hudi.common.config.HoodieMetadataConfig +import org.apache.hudi.common.fs.FSUtils +import org.apache.hudi.common.model.FileSlice +import org.apache.hudi.common.table.HoodieTableMetaClient +import org.apache.hudi.metadata.HoodieTableMetadataUtil +import org.apache.hudi.storage.StoragePath +import org.apache.spark.sql.SparkSession +import org.apache.spark.sql.catalyst.expressions.Expression + +class BloomFiltersIndexSupport(spark: SparkSession, + metadataConfig: HoodieMetadataConfig, + metaClient: HoodieTableMetaClient) extends RecordLevelIndexSupport(spark, metadataConfig, metaClient) { + + override def getIndexName: String = BloomFiltersIndexSupport.INDEX_NAME + + override def computeCandidateFileNames(fileIndex: HoodieFileIndex, + queryFilters: Seq[Expression], + queryReferencedColumns: Seq[String], + prunedPartitionsAndFileSlices: Seq[(Option[BaseHoodieTableFileIndex.PartitionPath], Seq[FileSlice])], + shouldPushDownFilesFilter: Boolean + ): Option[Set[String]] = { + lazy val (_, recordKeys) = filterQueriesWithRecordKey(queryFilters) + val allFiles = getPrunedFileNames(prunedPartitionsAndFileSlices).map(new StoragePath(_) ).toSeq Review Comment: this logic can be executed after judging recordKeys ########## hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/functional/TestBloomFiltersIndexSupport.scala: ########## @@ -0,0 +1,126 @@ +/* + * 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.hudi.functional + +import org.apache.hudi.HoodieConversionUtils.toProperties +import org.apache.hudi.common.config.{HoodieMetadataConfig, HoodieStorageConfig} +import org.apache.hudi.common.model.HoodieTableType +import org.apache.hudi.common.table.HoodieTableMetaClient +import org.apache.hudi.functional.ColumnStatIndexTestBase.ColumnStatsTestCase +import org.apache.hudi.testutils.HoodieSparkClientTestBase +import org.apache.hudi.{BloomFiltersIndexSupport, DataSourceWriteOptions} +import org.apache.spark.sql.types._ +import org.apache.spark.sql.{Column, DataFrame, SaveMode, SparkSession} +import org.junit.jupiter.api.{AfterEach, BeforeEach} + +import scala.collection.JavaConverters._ + +class TestBloomFiltersIndexSupport extends HoodieSparkClientTestBase { Review Comment: Sorry, I couldn't find a way to execute this test. Is this a base test file? Perhaps the Impl test class is missing? ########## hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/BloomFiltersIndexSupport.scala: ########## @@ -0,0 +1,94 @@ +/* + * 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.hudi + +import org.apache.hudi.HoodieConversionUtils.toScalaOption +import org.apache.hudi.RecordLevelIndexSupport.filterQueryWithRecordKey +import org.apache.hudi.common.config.HoodieMetadataConfig +import org.apache.hudi.common.fs.FSUtils +import org.apache.hudi.common.model.FileSlice +import org.apache.hudi.common.table.HoodieTableMetaClient +import org.apache.hudi.metadata.HoodieTableMetadataUtil +import org.apache.hudi.storage.StoragePath +import org.apache.spark.sql.SparkSession +import org.apache.spark.sql.catalyst.expressions.Expression + +class BloomFiltersIndexSupport(spark: SparkSession, + metadataConfig: HoodieMetadataConfig, + metaClient: HoodieTableMetaClient) extends RecordLevelIndexSupport(spark, metadataConfig, metaClient) { + + override def getIndexName: String = BloomFiltersIndexSupport.INDEX_NAME + + override def computeCandidateFileNames(fileIndex: HoodieFileIndex, + queryFilters: Seq[Expression], + queryReferencedColumns: Seq[String], + prunedPartitionsAndFileSlices: Seq[(Option[BaseHoodieTableFileIndex.PartitionPath], Seq[FileSlice])], + shouldPushDownFilesFilter: Boolean + ): Option[Set[String]] = { + lazy val (_, recordKeys) = filterQueriesWithRecordKey(queryFilters) + val allFiles = getPrunedFileNames(prunedPartitionsAndFileSlices).map(new StoragePath(_) ).toSeq + if (recordKeys.nonEmpty) { + Option.apply(getCandidateFilesForRecordKeys(allFiles, recordKeys)) + } else { + Option.empty + } + } + + override def getCandidateFilesForRecordKeys(allFiles: Seq[StoragePath], recordKeys: List[String]): Set[String] = { + val candidateFiles = allFiles.filter { file => + val relativePartitionPath = FSUtils.getRelativePartitionPath(metaClient.getBasePathV2, file) Review Comment: compute `FSUtils.getRelativePartitionPath` for every file may cause performance problems. how about use prunedPartitionsAndFileSlices's patition info. this issue not blocking. -- 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]
