yihua commented on code in PR #11889:
URL: https://github.com/apache/hudi/pull/11889#discussion_r1762036382
##########
hudi-client/hudi-client-common/pom.xml:
##########
@@ -174,7 +174,16 @@
</exclusion>
</exclusions>
</dependency>
-
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-inline</artifactId>
+ <scope>test</scope>
+ </dependency>
Review Comment:
What compilation error are you seeing?
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/EightToSevenDowngradeHandler.java:
##########
@@ -92,4 +113,49 @@ private static void
downgradePartitionFields(HoodieWriteConfig config, HoodieEng
tablePropsToAdd.put(HoodieTableConfig.PARTITION_FIELDS,
tableConfig.getPartitionFieldProp());
}
}
+
+ static void downgradeMetadataPartitions(HoodieEngineContext context,
+ HoodieStorage hoodieStorage,
+ HoodieTableMetaClient metaClient,
+ Map<ConfigProperty, String>
tablePropsToAdd) {
+ // Fetch metadata partition paths.
+ List<String> metadataPartitions = FSUtils.getAllPartitionPaths(
+ context,
+ hoodieStorage,
+ metaClient.getBasePath(),
Review Comment:
The passed-in meta client is the data table meta client. Should the
metadata table meta client be constructed and passed in here?
##########
hudi-client/hudi-client-common/src/test/java/org/apache/hudi/table/upgrade/TestEightToSevenDowngradeHandler.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.table.upgrade;
+
+import org.apache.hudi.common.config.ConfigProperty;
+import org.apache.hudi.common.engine.HoodieEngineContext;
+import org.apache.hudi.common.fs.FSUtils;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.metadata.HoodieTableMetadataUtil;
+import org.apache.hudi.storage.HoodieStorage;
+import org.apache.hudi.storage.StoragePath;
+import org.apache.hudi.storage.hadoop.HoodieHadoopStorage;
+
+import org.apache.hadoop.conf.Configuration;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static
org.apache.hudi.common.table.HoodieTableConfig.TABLE_METADATA_PARTITIONS;
+import static org.apache.hudi.metadata.MetadataPartitionType.FUNCTIONAL_INDEX;
+import static org.apache.hudi.metadata.MetadataPartitionType.PARTITION_STATS;
+import static org.apache.hudi.metadata.MetadataPartitionType.SECONDARY_INDEX;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class TestEightToSevenDowngradeHandler {
+ private static final List<String> SAMPLE_METADATA_PATHS = Arrays.asList(
+ FUNCTIONAL_INDEX.getPartitionPath(),
+ SECONDARY_INDEX.getPartitionPath(),
Review Comment:
That should be good.
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/EightToSevenDowngradeHandler.java:
##########
@@ -92,4 +116,57 @@ private static void
downgradePartitionFields(HoodieWriteConfig config, HoodieEng
tablePropsToAdd.put(HoodieTableConfig.PARTITION_FIELDS,
tableConfig.getPartitionFieldProp());
}
}
+
+ static void downgradeMetadataPartitions(HoodieEngineContext context,
+ HoodieStorage hoodieStorage,
+ HoodieTableMetaClient mdtMetaClient,
+ Map<ConfigProperty, String>
tablePropsToAdd) {
+ // Fetch metadata partition paths.
+ List<String> metadataPartitions = FSUtils.getAllPartitionPaths(
+ context,
+ hoodieStorage,
+ mdtMetaClient.getBasePath(),
+ false);
+
+ // Delete partitions.
+ List<String> validPartitionPaths =
+ deleteMetadataPartition(context, mdtMetaClient, metadataPartitions);
+
+ // Clean the configuration.
+ tablePropsToAdd.put(
+ TABLE_METADATA_PARTITIONS, String.join(",", validPartitionPaths));
+ }
+
+ static List<String> deleteMetadataPartition(HoodieEngineContext context,
+ HoodieTableMetaClient
mdtMetaClient,
+ List<String> metadataPartitions)
{
+ metadataPartitions.stream()
Review Comment:
Makes sense. The new logic is better than `for` loop.
##########
hudi-client/hudi-client-common/src/test/java/org/apache/hudi/table/upgrade/TestEightToSevenDowngradeHandler.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.table.upgrade;
+
+import org.apache.hudi.common.config.ConfigProperty;
+import org.apache.hudi.common.engine.HoodieEngineContext;
+import org.apache.hudi.common.fs.FSUtils;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.metadata.HoodieTableMetadataUtil;
+import org.apache.hudi.storage.HoodieStorage;
+import org.apache.hudi.storage.HoodieStorageUtils;
+import org.apache.hudi.storage.StoragePath;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.io.TempDir;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static
org.apache.hudi.common.table.HoodieTableConfig.TABLE_METADATA_PARTITIONS;
+import static
org.apache.hudi.common.testutils.HoodieTestUtils.getDefaultStorageConf;
+import static org.apache.hudi.metadata.MetadataPartitionType.COLUMN_STATS;
+import static org.apache.hudi.metadata.MetadataPartitionType.FILES;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class TestEightToSevenDowngradeHandler {
+ @TempDir
+ private File baseDir;
+
+ private static final List<String> SAMPLE_METADATA_PATHS = Arrays.asList(
+ "func_index_random",
+ "secondary_index_random",
+ "partition_stats",
+ FILES.getPartitionPath(),
+ COLUMN_STATS.getPartitionPath());
+ @Mock
+ HoodieTableMetaClient mdtMetaClient;
+ @Mock
+ HoodieEngineContext context;
+
+ @Test
+ void testDeleteMetadataPartition() {
+ try (MockedStatic<HoodieTableMetadataUtil> mockedMetadataUtils =
mockStatic(HoodieTableMetadataUtil.class)) {
+ List<String> leftPartitionPaths =
+ EightToSevenDowngradeHandler.deleteMetadataPartition(context,
mdtMetaClient, SAMPLE_METADATA_PATHS);
Review Comment:
Does `EightToSevenDowngradeHandler#deleteMetadataPartition` expect data
table or metadata table meta client?
--
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]