codope commented on code in PR #12653:
URL: https://github.com/apache/hudi/pull/12653#discussion_r1927423995
##########
hudi-common/src/main/java/org/apache/hudi/metadata/HoodieTableMetadataUtil.java:
##########
@@ -2766,6 +2768,79 @@ private static void validatePayload(int type,
Map<String, HoodieMetadataFileInfo
}
}
+ public static Set<String>
getExpressionIndexPartitionsToInit(MetadataPartitionType partitionType,
HoodieMetadataConfig metadataConfig, HoodieTableMetaClient dataMetaClient) {
+ Set<String> expressionIndexPartitionsToInit =
getIndexPartitionsToInit(partitionType, dataMetaClient);
+ if (expressionIndexPartitionsToInit.isEmpty()) {
+ if (isNewExpressionIndexDefinitionRequired(metadataConfig,
dataMetaClient)) {
+ String indexedColumn = metadataConfig.getExpressionIndexColumn();
+ String indexName = metadataConfig.getExpressionIndexName();
+ String indexType = metadataConfig.getExpressionIndexType();
+ // Use a default index name if the indexed column is specified but
index name is not
+ if (StringUtils.isNullOrEmpty(indexName) &&
StringUtils.nonEmpty(indexedColumn)) {
+ indexName = PARTITION_NAME_EXPRESSION_INDEX_PREFIX + indexedColumn;
+ }
+ // if user defined index name does not contain the expression_index_
prefix, then add it
+ if (StringUtils.nonEmpty(indexName) &&
!indexName.startsWith(PARTITION_NAME_EXPRESSION_INDEX_PREFIX)) {
+ indexName = PARTITION_NAME_EXPRESSION_INDEX_PREFIX + indexName;
+ }
+ // Build and register the new index definition
+ HoodieIndexDefinition indexDefinition =
HoodieIndexDefinition.newBuilder()
+ .withIndexName(indexName)
+ .withIndexType(indexType)
+ .withSourceFields(Collections.singletonList(indexedColumn))
+ .withIndexOptions(metadataConfig.getExpressionIndexOptions())
+ .build();
+ dataMetaClient.buildIndexDefinition(indexDefinition);
+ // Re-fetch the partitions after adding the new definition
+ expressionIndexPartitionsToInit =
getIndexPartitionsToInit(partitionType, dataMetaClient);
+ } else {
+ return null;
+ }
+ }
+ return expressionIndexPartitionsToInit;
+ }
+
+ public static Set<String>
getSecondaryIndexPartitionsToInit(MetadataPartitionType partitionType,
HoodieMetadataConfig metadataConfig, HoodieTableMetaClient dataMetaClient) {
+ Set<String> secondaryIndexPartitionsToInit =
getIndexPartitionsToInit(partitionType, dataMetaClient);
Review Comment:
refactored
--
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]