Davis-Zhang-Onehouse commented on code in PR #13489: URL: https://github.com/apache/hudi/pull/13489#discussion_r2180656699
########## hudi-common/src/main/java/org/apache/hudi/common/model/HoodieIndexDefinition.java: ########## @@ -183,8 +225,23 @@ public Builder withIndexOptions(Map<String, String> indexOptions) { return this; } + public Builder withVersion(HoodieIndexVersion version) { + // Make sure the version enum matching the metadata partition is used. + this.version = version; + return this; + } + public HoodieIndexDefinition build() { - return new HoodieIndexDefinition(indexName, indexType, indexFunction, sourceFields, indexOptions); + ValidationUtils.checkArgument(indexName != null, "Could not build index definition with a null index name"); + ValidationUtils.checkArgument(indexType != null, "Could not build index definition with a null index type"); + return new HoodieIndexDefinition( + indexName, Review Comment: done in "address misc comments (Jul 2)". added the validation when we read from / write to disk index definitions org.apache.hudi.common.table.HoodieTableMetaClient#loadIndexDefFromStorage org.apache.hudi.common.table.HoodieTableMetaClient#writeIndexMetadataToStorage(org.apache.hudi.storage.HoodieStorage, java.lang.String, org.apache.hudi.common.model.HoodieIndexMetadata, org.apache.hudi.common.table.HoodieTableVersion) we cannot add null check here as we need to read json without version attribute ########## hudi-common/src/main/java/org/apache/hudi/common/util/IndexVersionUtils.java: ########## @@ -0,0 +1,44 @@ +/* + * 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.common.util; + +import org.apache.hudi.common.model.HoodieIndexMetadata; +import org.apache.hudi.common.table.HoodieTableVersion; +import org.apache.hudi.metadata.HoodieIndexVersion; + +/** + * Utility class for managing index version operations. + */ +public class IndexVersionUtils { + + /** + * Populates missing version attributes in index definitions based on table version. + * + * @param tableVersion the table version to determine appropriate index versions + * @param indexDefOption optional index metadata containing index definitions + */ + public static void populateIndexVersionIfMissing(HoodieTableVersion tableVersion, Option<HoodieIndexMetadata> indexDefOption) { + indexDefOption.ifPresent(idxDefs -> Review Comment: done in "address misc comments (Jul 2)" -- 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: commits-unsubscr...@hudi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org