cshuo commented on code in PR #18348: URL: https://github.com/apache/hudi/pull/18348#discussion_r3050371951
########## hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/index/IndexerFactory.java: ########## @@ -0,0 +1,105 @@ +/* + * 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.metadata.index; + +import org.apache.hudi.common.engine.HoodieEngineContext; +import org.apache.hudi.common.table.HoodieTableMetaClient; +import org.apache.hudi.config.HoodieWriteConfig; +import org.apache.hudi.exception.HoodieNotSupportedException; +import org.apache.hudi.metadata.MetadataPartitionType; +import org.apache.hudi.metadata.index.bloomfilters.BloomFiltersIndexer; +import org.apache.hudi.metadata.index.columnstats.ColumnStatsIndexer; +import org.apache.hudi.metadata.index.expression.ExpressionIndexer; +import org.apache.hudi.metadata.index.files.FilesIndexer; +import org.apache.hudi.metadata.index.partitionstats.PartitionStatsIndexer; +import org.apache.hudi.metadata.index.record.PartitionedRecordIndexer; +import org.apache.hudi.metadata.index.record.RecordIndexer; +import org.apache.hudi.metadata.index.secondary.SecondaryIndexer; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * Factory for creating {@link Indexer} implementations and resolving enabled indexers + * based on table and metadata configuration. + */ +public class IndexerFactory { + private static Indexer createIndexer(MetadataPartitionType partitionType, + HoodieEngineContext engineContext, + HoodieWriteConfig dataTableWriteConfig, + HoodieTableMetaClient dataTableMetaClient, + ExpressionIndexRecordGenerator expressionIndexRecordGenerator) { + switch (partitionType) { + case FILES: + return new FilesIndexer(engineContext, dataTableWriteConfig, dataTableMetaClient); + case BLOOM_FILTERS: + return new BloomFiltersIndexer(engineContext, dataTableWriteConfig, dataTableMetaClient); + case COLUMN_STATS: + return new ColumnStatsIndexer(engineContext, dataTableWriteConfig, dataTableMetaClient); + case RECORD_INDEX: + return dataTableWriteConfig.isRecordLevelIndexEnabled() + ? new PartitionedRecordIndexer(engineContext, dataTableWriteConfig, dataTableMetaClient) + : new RecordIndexer(engineContext, dataTableWriteConfig, dataTableMetaClient); + case EXPRESSION_INDEX: + return new ExpressionIndexer(engineContext, dataTableWriteConfig, dataTableMetaClient, expressionIndexRecordGenerator); + case PARTITION_STATS: + return new PartitionStatsIndexer(engineContext, dataTableWriteConfig, dataTableMetaClient); + case SECONDARY_INDEX: + return new SecondaryIndexer(engineContext, dataTableWriteConfig, dataTableMetaClient); + default: + throw new HoodieNotSupportedException("Unsupported metadata partition type for indexing: " + partitionType); + } + } + + /** + * Returns the map of metadata partition type to the indexer for the enabled metadata + * partition types based on the metadata config and table config. + */ + public static Map<MetadataPartitionType, Indexer> getEnabledIndexerMap( + HoodieEngineContext engineContext, + HoodieWriteConfig dataTableWriteConfig, + HoodieTableMetaClient dataTableMetaClient, + ExpressionIndexRecordGenerator expressionIndexRecordGenerator) { + if (!dataTableWriteConfig.getMetadataConfig().isEnabled()) { + return Collections.emptyMap(); + } + return Collections.unmodifiableMap(Arrays.stream(MetadataPartitionType.getValidValues(dataTableMetaClient.getTableConfig().getTableVersion())) + .filter(partitionType -> + (partitionType.isMetadataPartitionEnabled(dataTableWriteConfig.getMetadataConfig(), dataTableMetaClient.getTableConfig()) Review Comment: yes, they are covered. -- 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]
