codope commented on code in PR #6248: URL: https://github.com/apache/hudi/pull/6248#discussion_r934141283
########## hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/FourToFiveUpgradeHandler.java: ########## @@ -0,0 +1,60 @@ +/* + * 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.config.HoodieMetadataConfig; +import org.apache.hudi.common.engine.HoodieEngineContext; +import org.apache.hudi.common.fs.FSUtils; +import org.apache.hudi.config.HoodieWriteConfig; +import org.apache.hudi.exception.HoodieException; + +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; + +import java.util.HashMap; +import java.util.Map; + +import static org.apache.hudi.keygen.KeyGenUtils.OLD_DEPRECATED_DEFAULT_PARTITION_PATH; + +/** + * Upgrade handler to upgrade Hudi's table version from 4 to 5. + */ +public class FourToFiveUpgradeHandler implements UpgradeHandler { + + private static final Logger LOG = LogManager.getLogger(FourToFiveUpgradeHandler.class); + + @Override + public Map<ConfigProperty, String> upgrade(HoodieWriteConfig config, HoodieEngineContext context, String instantTime, SupportsUpgradeDowngrade upgradeDowngradeHelper) { + if (FSUtils.getAllPartitionPaths(context, HoodieMetadataConfig.newBuilder().enable(false).build(), config.getBasePath()) + .contains(OLD_DEPRECATED_DEFAULT_PARTITION_PATH)) { + LOG.error("\"default\" partition detected. From 0.12, we are changing the default partition in hudi to \"__HIVE_DEFAULT_PARTITION__\". " Review Comment: let's use String.format() and the constants wherever possible. ########## hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/FourToFiveUpgradeHandler.java: ########## @@ -0,0 +1,60 @@ +/* + * 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.config.HoodieMetadataConfig; +import org.apache.hudi.common.engine.HoodieEngineContext; +import org.apache.hudi.common.fs.FSUtils; +import org.apache.hudi.config.HoodieWriteConfig; +import org.apache.hudi.exception.HoodieException; + +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; + +import java.util.HashMap; +import java.util.Map; + +import static org.apache.hudi.keygen.KeyGenUtils.OLD_DEPRECATED_DEFAULT_PARTITION_PATH; + +/** + * Upgrade handler to upgrade Hudi's table version from 4 to 5. + */ +public class FourToFiveUpgradeHandler implements UpgradeHandler { + + private static final Logger LOG = LogManager.getLogger(FourToFiveUpgradeHandler.class); + + @Override + public Map<ConfigProperty, String> upgrade(HoodieWriteConfig config, HoodieEngineContext context, String instantTime, SupportsUpgradeDowngrade upgradeDowngradeHelper) { + if (FSUtils.getAllPartitionPaths(context, HoodieMetadataConfig.newBuilder().enable(false).build(), config.getBasePath()) Review Comment: Should we also check for partition field data type and keygen? If the partition field is of string type or if it's a complex keygen with multiple columns then we can skip this check right? Just thinking about how to reduce the scope of this validation. ########## hudi-client/hudi-client-common/src/main/java/org/apache/hudi/keygen/KeyGenUtils.java: ########## @@ -41,6 +41,7 @@ public class KeyGenUtils { protected static final String EMPTY_RECORDKEY_PLACEHOLDER = "__empty__"; protected static final String HUDI_DEFAULT_PARTITION_PATH = PartitionPathEncodeUtils.DEFAULT_PARTITION_PATH; + public static final String OLD_DEPRECATED_DEFAULT_PARTITION_PATH = "default"; Review Comment: let's rename it `DEPRECATED_DEFAULT_PARTITION_PATH`? Also, should we move this constant to `PartitionPathEncodeUtils`? That's where the old one was defined. ########## hudi-common/src/main/java/org/apache/hudi/common/table/HoodieTableVersion.java: ########## @@ -36,7 +36,9 @@ public enum HoodieTableVersion { // 0.10.0 onwards THREE(3), // 0.11.0 onwards - FOUR(4); + FOUR(4), + // 0.12 onwards Review Comment: ```suggestion // 0.12.0 onwards ``` ########## hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/FourToFiveUpgradeHandler.java: ########## @@ -0,0 +1,60 @@ +/* + * 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.config.HoodieMetadataConfig; +import org.apache.hudi.common.engine.HoodieEngineContext; +import org.apache.hudi.common.fs.FSUtils; +import org.apache.hudi.config.HoodieWriteConfig; +import org.apache.hudi.exception.HoodieException; + +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; + +import java.util.HashMap; +import java.util.Map; + +import static org.apache.hudi.keygen.KeyGenUtils.OLD_DEPRECATED_DEFAULT_PARTITION_PATH; + +/** + * Upgrade handler to upgrade Hudi's table version from 4 to 5. + */ +public class FourToFiveUpgradeHandler implements UpgradeHandler { + + private static final Logger LOG = LogManager.getLogger(FourToFiveUpgradeHandler.class); + + @Override + public Map<ConfigProperty, String> upgrade(HoodieWriteConfig config, HoodieEngineContext context, String instantTime, SupportsUpgradeDowngrade upgradeDowngradeHelper) { + if (FSUtils.getAllPartitionPaths(context, HoodieMetadataConfig.newBuilder().enable(false).build(), config.getBasePath()) + .contains(OLD_DEPRECATED_DEFAULT_PARTITION_PATH)) { + LOG.error("\"default\" partition detected. From 0.12, we are changing the default partition in hudi to \"__HIVE_DEFAULT_PARTITION__\". " + + " Please read and write back the data in \"default\" partition in hudi to new partition path \"__HIVE_DEFAULT_PARTITION__\". " + + "Sample spark command to use: \n" + + "val df = spark.read.format(\"hudi\").load(HUDI_TABLE_PATH); \t \n" Review Comment: Should we also log the such partition values and ask user to rewrite only such partitions instead of whole table? -- 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]
