codope commented on code in PR #12653:
URL: https://github.com/apache/hudi/pull/12653#discussion_r1928889057
##########
hudi-common/src/main/java/org/apache/hudi/common/table/HoodieTableMetaClient.java:
##########
@@ -211,38 +210,28 @@ public String getIndexDefinitionPath() {
}
/**
- * Builds expression index definition and writes to index definition file.
- * Support mutable and immutable index definition. Only col stats is
mutable, while all others are immutable.
- * Inacse of immutable index definition, we could only create or delete the
definition.
- * Incase of mutable (col stats), list of source columns (or list of columns
to index) could also change.
+ * Builds index definition and writes to index definition file. Support
mutable and immutable index definition.
+ * For instance, if index definition is mutable (like column stats), list of
source columns (or list of columns to index) could also change.
+ * If an index definition is present for the index name, it will be updated
only when there is difference between present and new index definition.
+ *
* @return true if index definition is updated.
*/
public boolean buildIndexDefinition(HoodieIndexDefinition indexDefinition) {
String indexName = indexDefinition.getIndexName();
- boolean isIndexDefnImmutable =
!indexDefinition.getIndexName().equals(PARTITION_NAME_COLUMN_STATS); // only
col stats is mutable.
- if (isIndexDefnImmutable) {
- checkState(
- !indexMetadataOpt.isPresent() ||
(!indexMetadataOpt.get().getIndexDefinitions().containsKey(indexName)),
- "Index metadata is already present");
- }
String indexMetaPath = getIndexDefinitionPath();
boolean updateIndexDefn = true;
if (indexMetadataOpt.isPresent()) {
- if (isIndexDefnImmutable) {
- indexMetadataOpt.get().getIndexDefinitions().put(indexName,
indexDefinition);
- } else {
- // if index defn is mutable, lets check for difference and only update
if required.
- if
(indexMetadataOpt.get().getIndexDefinitions().containsKey(indexName)) {
- if
(!indexMetadataOpt.get().getIndexDefinitions().get(indexName).getSourceFields().equals(indexDefinition.getSourceFields()))
{
- LOG.info(String.format("List of columns to index is changing. Old
value %s. New value %s",
-
indexMetadataOpt.get().getIndexDefinitions().get(indexName).getSourceFields(),
indexDefinition.getSourceFields()));
- indexMetadataOpt.get().getIndexDefinitions().put(indexName,
indexDefinition);
- } else {
- updateIndexDefn = false;
- }
- } else {
+ // if index definition is present, lets check for difference and only
update if required.
+ if (indexMetadataOpt.get().getIndexDefinitions().containsKey(indexName))
{
+ if
(!indexMetadataOpt.get().getIndexDefinitions().get(indexName).getSourceFields().equals(indexDefinition.getSourceFields()))
{
Review Comment:
as discussed, we have already checked that before coming here
--
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]