vinothchandar commented on code in PR #12983: URL: https://github.com/apache/hudi/pull/12983#discussion_r2103896212
########## hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/index/IndexerFactory.java: ########## @@ -0,0 +1,107 @@ +/* + * 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.RecordIndexer; +import org.apache.hudi.metadata.index.secondary.SecondaryIndexer; +import org.apache.hudi.table.HoodieTable; +import org.apache.hudi.util.Lazy; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +import static org.apache.hudi.metadata.MetadataPartitionType.getValidValues; + +public class IndexerFactory { + public static Indexer getIndexer(MetadataPartitionType partitionType, + HoodieEngineContext engineContext, + HoodieWriteConfig dataTableWriteConfig, + HoodieTableMetaClient dataTableMetaClient, + Lazy<HoodieTable> table, + ExpressionIndexRecordGenerator expressionIndexRecordGenerator) { + switch (partitionType) { + case BLOOM_FILTERS: + return new BloomFiltersIndexer( + engineContext, dataTableWriteConfig, dataTableMetaClient); + case COLUMN_STATS: + return new ColumnStatsIndexer( + engineContext, dataTableWriteConfig, dataTableMetaClient); + case EXPRESSION_INDEX: + return new ExpressionIndexer( + engineContext, dataTableWriteConfig, dataTableMetaClient, expressionIndexRecordGenerator); + case FILES: + return new FilesIndexer(engineContext); + case PARTITION_STATS: + return new PartitionStatsIndexer( + engineContext, dataTableWriteConfig, dataTableMetaClient); + case RECORD_INDEX: + return new RecordIndexer( + engineContext, dataTableWriteConfig, dataTableMetaClient, table); + case SECONDARY_INDEX: + return new SecondaryIndexer( + engineContext, expressionIndexRecordGenerator.getEngineType(), dataTableWriteConfig, dataTableMetaClient); + default: + throw new HoodieNotSupportedException( + "Unsupported metadata partition type for indexing: " + partitionType); + } + } + + /** + * @param engineContext {@link HoodieEngineContext} instance + * @param dataTableWriteConfig write config for the data table + * @param dataTableMetaClient meta client of the data table + * @param table lazy {@link HoodieTable} instance presenting the data table + * @param expressionIndexRecordGenerator record generator for the expression index + * @return the map of metadata partition type to the indexer for the enabled metadata + * partition types based on the metadata config and table config. + */ + // TODO(yihua): remove MetadataPartitionType#getEnabledIndexBuilderMap Review Comment: is this valid ########## hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/index/IndexerFactory.java: ########## @@ -0,0 +1,107 @@ +/* + * 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.RecordIndexer; +import org.apache.hudi.metadata.index.secondary.SecondaryIndexer; +import org.apache.hudi.table.HoodieTable; +import org.apache.hudi.util.Lazy; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +import static org.apache.hudi.metadata.MetadataPartitionType.getValidValues; + +public class IndexerFactory { + public static Indexer getIndexer(MetadataPartitionType partitionType, + HoodieEngineContext engineContext, + HoodieWriteConfig dataTableWriteConfig, + HoodieTableMetaClient dataTableMetaClient, + Lazy<HoodieTable> table, + ExpressionIndexRecordGenerator expressionIndexRecordGenerator) { + switch (partitionType) { + case BLOOM_FILTERS: + return new BloomFiltersIndexer( Review Comment: why the newline ########## hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/index/Indexer.java: ########## @@ -0,0 +1,137 @@ +/* + * 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.data.HoodieData; +import org.apache.hudi.common.model.FileSlice; +import org.apache.hudi.common.model.HoodieRecord; +import org.apache.hudi.common.util.ValidationUtils; +import org.apache.hudi.common.util.collection.Pair; +import org.apache.hudi.common.util.collection.Tuple3; +import org.apache.hudi.util.Lazy; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * Interface for initializing and updating a type of metadata or index + * in the metadata table + * <p> + * When a new type of index is added to MetadataPartitionType, an + * implementation of the {@link Indexer} interface is required, and it + * must be added to {@link IndexerFactory}. + */ +public interface Indexer { + /** + * Generates records for initializing the index. + * + * @param dataTableInstantTime instant time of the data table that the metadata table + * is initialized on + * @param partitionIdToAllFilesMap map of partition to files + * @param lazyLatestMergedPartitionFileSliceList lazily-evaluated list of file slices for the indexer + * that needs it + * @return a list of {@link InitialIndexPartitionData}, which each data item + * representing the records to initialize a particular partition (note that + * one index type can correspond to one or multiple partitions in the metadata + * table). An empty list returned indicates that the metadata partition does + * not need to be initialized. + * @throws IOException upon IO error + */ + List<InitialIndexPartitionData> initialize( + String dataTableInstantTime, + Map<String, Map<String, Long>> partitionIdToAllFilesMap, + Lazy<List<Pair<String, FileSlice>>> lazyLatestMergedPartitionFileSliceList) throws IOException; + + /** + * Updates the table config of the data table to reflect the state of the index + */ + default void updateTableConfig() { + // No index-specific table config update by default + } + + static List<Tuple3<String, String, Boolean>> fetchPartitionFileInfoTriplets( + Map<String, Map<String, Long>> partitionToAppendedFiles) { + // Total number of files which are added or deleted + final int totalFiles = partitionToAppendedFiles.values().stream().mapToInt(Map::size).sum(); + final List<Tuple3<String, String, Boolean>> partitionFileFlagTupleList = new ArrayList<>(totalFiles); + partitionToAppendedFiles.entrySet().stream() + .flatMap( + entry -> entry.getValue().keySet().stream().map(addedFile -> Tuple3.of(entry.getKey(), addedFile, false))) + .collect(Collectors.toCollection(() -> partitionFileFlagTupleList)); + return partitionFileFlagTupleList; + } + + class IndexPartitionData { + private final String partitionName; Review Comment: rename: indexPartitionName. Assuming thats what you mean. ########## hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/index/Indexer.java: ########## @@ -0,0 +1,137 @@ +/* + * 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.data.HoodieData; +import org.apache.hudi.common.model.FileSlice; +import org.apache.hudi.common.model.HoodieRecord; +import org.apache.hudi.common.util.ValidationUtils; +import org.apache.hudi.common.util.collection.Pair; +import org.apache.hudi.common.util.collection.Tuple3; +import org.apache.hudi.util.Lazy; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * Interface for initializing and updating a type of metadata or index + * in the metadata table + * <p> + * When a new type of index is added to MetadataPartitionType, an + * implementation of the {@link Indexer} interface is required, and it + * must be added to {@link IndexerFactory}. + */ +public interface Indexer { + /** + * Generates records for initializing the index. + * + * @param dataTableInstantTime instant time of the data table that the metadata table + * is initialized on + * @param partitionIdToAllFilesMap map of partition to files + * @param lazyLatestMergedPartitionFileSliceList lazily-evaluated list of file slices for the indexer + * that needs it + * @return a list of {@link InitialIndexPartitionData}, which each data item + * representing the records to initialize a particular partition (note that + * one index type can correspond to one or multiple partitions in the metadata + * table). An empty list returned indicates that the metadata partition does + * not need to be initialized. + * @throws IOException upon IO error + */ + List<InitialIndexPartitionData> initialize( + String dataTableInstantTime, + Map<String, Map<String, Long>> partitionIdToAllFilesMap, + Lazy<List<Pair<String, FileSlice>>> lazyLatestMergedPartitionFileSliceList) throws IOException; + + /** + * Updates the table config of the data table to reflect the state of the index + */ + default void updateTableConfig() { + // No index-specific table config update by default + } + + static List<Tuple3<String, String, Boolean>> fetchPartitionFileInfoTriplets( + Map<String, Map<String, Long>> partitionToAppendedFiles) { + // Total number of files which are added or deleted + final int totalFiles = partitionToAppendedFiles.values().stream().mapToInt(Map::size).sum(); + final List<Tuple3<String, String, Boolean>> partitionFileFlagTupleList = new ArrayList<>(totalFiles); + partitionToAppendedFiles.entrySet().stream() + .flatMap( + entry -> entry.getValue().keySet().stream().map(addedFile -> Tuple3.of(entry.getKey(), addedFile, false))) + .collect(Collectors.toCollection(() -> partitionFileFlagTupleList)); + return partitionFileFlagTupleList; + } + + class IndexPartitionData { + private final String partitionName; + private final HoodieData<HoodieRecord> records; + + private IndexPartitionData(String partitionName, HoodieData<HoodieRecord> records) { + this.partitionName = partitionName; + this.records = records; + } + + public static IndexPartitionData of(String partitionName, HoodieData<HoodieRecord> records) { + return new IndexPartitionData(partitionName, records); + } + + public String partitionName() { + return partitionName; + } + + public HoodieData<HoodieRecord> records() { + return records; + } + } + + class InitialIndexPartitionData { Review Comment: rename: InitialIndexData ########## hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/index/Indexer.java: ########## @@ -0,0 +1,137 @@ +/* + * 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.data.HoodieData; +import org.apache.hudi.common.model.FileSlice; +import org.apache.hudi.common.model.HoodieRecord; +import org.apache.hudi.common.util.ValidationUtils; +import org.apache.hudi.common.util.collection.Pair; +import org.apache.hudi.common.util.collection.Tuple3; +import org.apache.hudi.util.Lazy; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * Interface for initializing and updating a type of metadata or index + * in the metadata table + * <p> + * When a new type of index is added to MetadataPartitionType, an + * implementation of the {@link Indexer} interface is required, and it + * must be added to {@link IndexerFactory}. + */ +public interface Indexer { + /** + * Generates records for initializing the index. + * + * @param dataTableInstantTime instant time of the data table that the metadata table + * is initialized on + * @param partitionIdToAllFilesMap map of partition to files + * @param lazyLatestMergedPartitionFileSliceList lazily-evaluated list of file slices for the indexer + * that needs it + * @return a list of {@link InitialIndexPartitionData}, which each data item + * representing the records to initialize a particular partition (note that + * one index type can correspond to one or multiple partitions in the metadata + * table). An empty list returned indicates that the metadata partition does + * not need to be initialized. + * @throws IOException upon IO error + */ + List<InitialIndexPartitionData> initialize( + String dataTableInstantTime, + Map<String, Map<String, Long>> partitionIdToAllFilesMap, + Lazy<List<Pair<String, FileSlice>>> lazyLatestMergedPartitionFileSliceList) throws IOException; + + /** + * Updates the table config of the data table to reflect the state of the index + */ + default void updateTableConfig() { + // No index-specific table config update by default + } + + static List<Tuple3<String, String, Boolean>> fetchPartitionFileInfoTriplets( + Map<String, Map<String, Long>> partitionToAppendedFiles) { + // Total number of files which are added or deleted + final int totalFiles = partitionToAppendedFiles.values().stream().mapToInt(Map::size).sum(); + final List<Tuple3<String, String, Boolean>> partitionFileFlagTupleList = new ArrayList<>(totalFiles); + partitionToAppendedFiles.entrySet().stream() + .flatMap( + entry -> entry.getValue().keySet().stream().map(addedFile -> Tuple3.of(entry.getKey(), addedFile, false))) + .collect(Collectors.toCollection(() -> partitionFileFlagTupleList)); + return partitionFileFlagTupleList; + } + + class IndexPartitionData { Review Comment: lombok can limit this sort of code.. should we try it.. ########## hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/index/Indexer.java: ########## @@ -0,0 +1,137 @@ +/* + * 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.data.HoodieData; +import org.apache.hudi.common.model.FileSlice; +import org.apache.hudi.common.model.HoodieRecord; +import org.apache.hudi.common.util.ValidationUtils; +import org.apache.hudi.common.util.collection.Pair; +import org.apache.hudi.common.util.collection.Tuple3; +import org.apache.hudi.util.Lazy; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * Interface for initializing and updating a type of metadata or index + * in the metadata table + * <p> + * When a new type of index is added to MetadataPartitionType, an + * implementation of the {@link Indexer} interface is required, and it + * must be added to {@link IndexerFactory}. + */ +public interface Indexer { + /** + * Generates records for initializing the index. + * + * @param dataTableInstantTime instant time of the data table that the metadata table + * is initialized on + * @param partitionIdToAllFilesMap map of partition to files + * @param lazyLatestMergedPartitionFileSliceList lazily-evaluated list of file slices for the indexer + * that needs it + * @return a list of {@link InitialIndexPartitionData}, which each data item + * representing the records to initialize a particular partition (note that + * one index type can correspond to one or multiple partitions in the metadata + * table). An empty list returned indicates that the metadata partition does + * not need to be initialized. + * @throws IOException upon IO error + */ + List<InitialIndexPartitionData> initialize( + String dataTableInstantTime, + Map<String, Map<String, Long>> partitionIdToAllFilesMap, Review Comment: partitionPath or partitionId? consistent naming.. also is there a pojo for the Map<String, Long>? Trying to see how/if we can avoid this kind of multimap argument.. ########## hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/index/Indexer.java: ########## @@ -0,0 +1,137 @@ +/* + * 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.data.HoodieData; +import org.apache.hudi.common.model.FileSlice; +import org.apache.hudi.common.model.HoodieRecord; +import org.apache.hudi.common.util.ValidationUtils; +import org.apache.hudi.common.util.collection.Pair; +import org.apache.hudi.common.util.collection.Tuple3; +import org.apache.hudi.util.Lazy; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * Interface for initializing and updating a type of metadata or index + * in the metadata table + * <p> + * When a new type of index is added to MetadataPartitionType, an + * implementation of the {@link Indexer} interface is required, and it + * must be added to {@link IndexerFactory}. + */ +public interface Indexer { + /** + * Generates records for initializing the index. + * + * @param dataTableInstantTime instant time of the data table that the metadata table + * is initialized on + * @param partitionIdToAllFilesMap map of partition to files + * @param lazyLatestMergedPartitionFileSliceList lazily-evaluated list of file slices for the indexer + * that needs it + * @return a list of {@link InitialIndexPartitionData}, which each data item + * representing the records to initialize a particular partition (note that + * one index type can correspond to one or multiple partitions in the metadata + * table). An empty list returned indicates that the metadata partition does + * not need to be initialized. + * @throws IOException upon IO error + */ + List<InitialIndexPartitionData> initialize( + String dataTableInstantTime, + Map<String, Map<String, Long>> partitionIdToAllFilesMap, + Lazy<List<Pair<String, FileSlice>>> lazyLatestMergedPartitionFileSliceList) throws IOException; + + /** + * Updates the table config of the data table to reflect the state of the index + */ + default void updateTableConfig() { + // No index-specific table config update by default + } + + static List<Tuple3<String, String, Boolean>> fetchPartitionFileInfoTriplets( + Map<String, Map<String, Long>> partitionToAppendedFiles) { + // Total number of files which are added or deleted + final int totalFiles = partitionToAppendedFiles.values().stream().mapToInt(Map::size).sum(); + final List<Tuple3<String, String, Boolean>> partitionFileFlagTupleList = new ArrayList<>(totalFiles); + partitionToAppendedFiles.entrySet().stream() + .flatMap( + entry -> entry.getValue().keySet().stream().map(addedFile -> Tuple3.of(entry.getKey(), addedFile, false))) + .collect(Collectors.toCollection(() -> partitionFileFlagTupleList)); + return partitionFileFlagTupleList; + } + + class IndexPartitionData { + private final String partitionName; + private final HoodieData<HoodieRecord> records; + + private IndexPartitionData(String partitionName, HoodieData<HoodieRecord> records) { + this.partitionName = partitionName; + this.records = records; + } + + public static IndexPartitionData of(String partitionName, HoodieData<HoodieRecord> records) { + return new IndexPartitionData(partitionName, records); + } + + public String partitionName() { + return partitionName; + } + + public HoodieData<HoodieRecord> records() { + return records; + } + } + + class InitialIndexPartitionData { Review Comment: do we need two pojos.. ########## hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/index/NotSupportedExpressionIndexRecordGenerator.java: ########## @@ -0,0 +1,61 @@ +/* + * 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.data.HoodieData; +import org.apache.hudi.common.engine.EngineType; +import org.apache.hudi.common.model.HoodieIndexDefinition; +import org.apache.hudi.common.model.HoodieRecord; +import org.apache.hudi.common.table.HoodieTableMetaClient; +import org.apache.hudi.common.table.HoodieTableVersion; +import org.apache.hudi.exception.HoodieNotSupportedException; +import org.apache.hudi.storage.StorageConfiguration; + +import org.apache.avro.Schema; + +import java.util.List; + +public class NotSupportedExpressionIndexRecordGenerator implements ExpressionIndexRecordGenerator { Review Comment: rename: Unsupported.... ########## hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/index/Indexer.java: ########## @@ -0,0 +1,137 @@ +/* + * 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.data.HoodieData; +import org.apache.hudi.common.model.FileSlice; +import org.apache.hudi.common.model.HoodieRecord; +import org.apache.hudi.common.util.ValidationUtils; +import org.apache.hudi.common.util.collection.Pair; +import org.apache.hudi.common.util.collection.Tuple3; +import org.apache.hudi.util.Lazy; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * Interface for initializing and updating a type of metadata or index + * in the metadata table + * <p> + * When a new type of index is added to MetadataPartitionType, an + * implementation of the {@link Indexer} interface is required, and it + * must be added to {@link IndexerFactory}. + */ +public interface Indexer { + /** + * Generates records for initializing the index. + * + * @param dataTableInstantTime instant time of the data table that the metadata table + * is initialized on + * @param partitionIdToAllFilesMap map of partition to files + * @param lazyLatestMergedPartitionFileSliceList lazily-evaluated list of file slices for the indexer + * that needs it + * @return a list of {@link InitialIndexPartitionData}, which each data item + * representing the records to initialize a particular partition (note that + * one index type can correspond to one or multiple partitions in the metadata + * table). An empty list returned indicates that the metadata partition does + * not need to be initialized. + * @throws IOException upon IO error + */ + List<InitialIndexPartitionData> initialize( + String dataTableInstantTime, + Map<String, Map<String, Long>> partitionIdToAllFilesMap, + Lazy<List<Pair<String, FileSlice>>> lazyLatestMergedPartitionFileSliceList) throws IOException; + + /** + * Updates the table config of the data table to reflect the state of the index + */ + default void updateTableConfig() { + // No index-specific table config update by default + } + + static List<Tuple3<String, String, Boolean>> fetchPartitionFileInfoTriplets( + Map<String, Map<String, Long>> partitionToAppendedFiles) { + // Total number of files which are added or deleted + final int totalFiles = partitionToAppendedFiles.values().stream().mapToInt(Map::size).sum(); + final List<Tuple3<String, String, Boolean>> partitionFileFlagTupleList = new ArrayList<>(totalFiles); + partitionToAppendedFiles.entrySet().stream() + .flatMap( + entry -> entry.getValue().keySet().stream().map(addedFile -> Tuple3.of(entry.getKey(), addedFile, false))) + .collect(Collectors.toCollection(() -> partitionFileFlagTupleList)); + return partitionFileFlagTupleList; + } + + class IndexPartitionData { Review Comment: rename: IndexRecords or IndexData the index is a partition in MT.. but the `Indexer`'s scope should be limited to that partition.. ########## hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/index/Indexer.java: ########## @@ -0,0 +1,137 @@ +/* + * 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.data.HoodieData; +import org.apache.hudi.common.model.FileSlice; +import org.apache.hudi.common.model.HoodieRecord; +import org.apache.hudi.common.util.ValidationUtils; +import org.apache.hudi.common.util.collection.Pair; +import org.apache.hudi.common.util.collection.Tuple3; +import org.apache.hudi.util.Lazy; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * Interface for initializing and updating a type of metadata or index + * in the metadata table + * <p> + * When a new type of index is added to MetadataPartitionType, an + * implementation of the {@link Indexer} interface is required, and it + * must be added to {@link IndexerFactory}. + */ +public interface Indexer { + /** + * Generates records for initializing the index. + * + * @param dataTableInstantTime instant time of the data table that the metadata table + * is initialized on + * @param partitionIdToAllFilesMap map of partition to files + * @param lazyLatestMergedPartitionFileSliceList lazily-evaluated list of file slices for the indexer + * that needs it + * @return a list of {@link InitialIndexPartitionData}, which each data item + * representing the records to initialize a particular partition (note that + * one index type can correspond to one or multiple partitions in the metadata + * table). An empty list returned indicates that the metadata partition does + * not need to be initialized. + * @throws IOException upon IO error + */ + List<InitialIndexPartitionData> initialize( + String dataTableInstantTime, + Map<String, Map<String, Long>> partitionIdToAllFilesMap, + Lazy<List<Pair<String, FileSlice>>> lazyLatestMergedPartitionFileSliceList) throws IOException; + + /** + * Updates the table config of the data table to reflect the state of the index + */ + default void updateTableConfig() { + // No index-specific table config update by default + } + + static List<Tuple3<String, String, Boolean>> fetchPartitionFileInfoTriplets( Review Comment: Not a fan of the `Tuple3`.. if you are introducing it, can we call it just `Triplet` ? we already have `Pair` should we embrace sth like lombok.. and get case classes style pojos for these cases.. -- 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]
