nsivabalan commented on code in PR #12529: URL: https://github.com/apache/hudi/pull/12529#discussion_r1894118056
########## hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/HoodieIndexClientUtils.java: ########## @@ -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.hudi.client; + +import org.apache.hudi.common.model.HoodieCommitMetadata; +import org.apache.hudi.common.table.HoodieTableMetaClient; +import org.apache.hudi.common.table.timeline.HoodieInstant; +import org.apache.hudi.common.util.Functions; +import org.apache.hudi.config.HoodieWriteConfig; +import org.apache.hudi.exception.HoodieException; +import org.apache.hudi.metadata.HoodieTableMetadata; +import org.apache.hudi.metadata.HoodieTableMetadataUtil; +import org.apache.hudi.metadata.MetadataPartitionType; +import org.apache.hudi.table.HoodieTable; + +import java.util.List; + +public class HoodieIndexClientUtils { + + public static void updateColsToIndex(HoodieTable dataTable, HoodieWriteConfig config, HoodieCommitMetadata commitMetadata, + Functions.Function2<HoodieTableMetaClient, List<String>, Void> updateColSatsFunc) { + if (config.getMetadataConfig().isColumnStatsIndexEnabled()) { + try { + HoodieTableMetaClient mdtMetaClient = HoodieTableMetaClient.builder() + .setStorage(dataTable.getStorage()) + .setBasePath(HoodieTableMetadata.getMetadataTableBasePath(dataTable.getMetaClient().getBasePath())) + .build(); + HoodieInstant latestInstant = mdtMetaClient.getActiveTimeline().filterCompletedInstants().getInstantsOrderedByCompletionTime().reduce((a, b) -> b).get(); + + final HoodieCommitMetadata mdtCommitMetadata = mdtMetaClient.getTimelineLayout().getCommitMetadataSerDe().deserialize( + latestInstant, + mdtMetaClient.getActiveTimeline().getInstantDetails(latestInstant).get(), + HoodieCommitMetadata.class); + if (mdtCommitMetadata.getPartitionToWriteStats().containsKey(MetadataPartitionType.COLUMN_STATS.getPartitionPath())) { + // update data table's table config for list of columns indexed. + List<String> columnsToIndex = HoodieTableMetadataUtil.getColumnsToIndex(commitMetadata, dataTable.getMetaClient(), config.getMetadataConfig()); + // if col stats is getting updated, lets also update list of columns indexed if changed. + updateColSatsFunc.apply(dataTable.getMetaClient(), columnsToIndex); Review Comment: actually, its already taken care. ``` if (!indexMetadataOpt.get().getIndexDefinitions().get(indexName).getSourceFields().equals(indexDefinition.getSourceFields())) { ``` this is in HoodieTableMetaClient.buildColSatsIndexDefinition so, its already list of strings comparison. So, we should be good -- 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]
