Skip to content

HIVE-29093 : Fix alter table add partition if DEFAULT_PARTITION_NAME propery is a substring of partitition value to be added #5977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

vikramahuja1001
Copy link
Contributor

…g of partition value.

What changes were proposed in this pull request?

Why are the changes needed?

Does this PR introduce any user-facing change?

How was this patch tested?

@vikramahuja1001 vikramahuja1001 changed the title Fix alter table add partition if DEFAULT_PARTITION_NAME is a substrin… HIVE-29093 : Fix alter table add partition if DEFAULT_PARTITION_NAME propery is a substring of partitition value to be added Jul 15, 2025
reservedPartitionValues.add(HiveConf.getVar(conf, ConfVars.METASTORE_INT_EXTRACTED));
reservedSuffixPartitionValues.add(HiveConf.getVar(conf, ConfVars.METASTORE_INT_ORIGINAL));
reservedSuffixPartitionValues.add(HiveConf.getVar(conf, ConfVars.METASTORE_INT_ARCHIVED));
reservedSuffixPartitionValues.add(HiveConf.getVar(conf, ConfVars.METASTORE_INT_EXTRACTED));

for (Entry<String, String> e : partitionSpec.entrySet()) {
Copy link
Member

@deniskuzZ deniskuzZ Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we please refactor with

partitionSpec.foreach((key, value) -> {
  if (value != null && reservedPartitionValue.containsKey(value)) {
  ...
  }
}

similar for reservedPartitionSuffixes

@@ -63,20 +63,28 @@ private PartitionUtils() {
*/
public static void validatePartitions(HiveConf conf, Map<String, String> partitionSpec) throws SemanticException {
Set<String> reservedPartitionValues = new HashSet<>();
Set<String> reservedSuffixPartitionValues = new HashSet<>();
Copy link
Member

@deniskuzZ deniskuzZ Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe reservedPartitionSuffixes ? also why not do anonymous initialization?

Set<String> reservedPartitionSuffixes = 
  new HashSet<String>() {{
    add(HiveConf.getVar(conf, ConfVars.METASTORE_INT_ORIGINAL));
    add(HiveConf.getVar(conf, ConfVars.METASTORE_INT_ARCHIVED));
    add(HiveConf.getVar(conf, ConfVars.METASTORE_INT_EXTRACTED));
  }};

}};

partitionSpec.forEach((key, value) -> {
if (value != null && reservedPartitionValues.contains(value)) {
Copy link
Member

@deniskuzZ deniskuzZ Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, my bad

partitionSpec.forEach((key, value) -> {
  if (value == null) {
    return;
  }
  reservedPartitionValues.stream().filter(value::contains).findAny()
    .ifPresent(s -> {
      throw new RuntimeException(ErrorMsg.RESERVED_PART_VAL.getMsg(
              "(User value: " + value + " Reserved string: " + s + ")"));
  });
  reservedPartitionSuffixes.stream().filter(value::endsWith)
    .ifPresent(s -> {
      throw new RuntimeException(ErrorMsg.RESERVED_PART_VAL.getMsg(
              "(User value: " + value + " Partition value cannot end with Reserved substring: " + s + ")"));
  });
});

Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants