Skip to content

HIVE-29782:ALTER VIEW ADD PARTITION does not honor non string partition columns - #6658

Open
ramitg254 wants to merge 2 commits into
apache:masterfrom
ramitg254:master
Open

HIVE-29782:ALTER VIEW ADD PARTITION does not honor non string partition columns#6658
ramitg254 wants to merge 2 commits into
apache:masterfrom
ramitg254:master

Conversation

@ramitg254

@ramitg254 ramitg254 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Change-Id: I56fa674c2d7c8db6187d75e9fd2f5d39a3ec766e

What changes were proposed in this pull request?

Fixed the behaviour of ALTER VIEW ADD PARTITION for non string partition columns

Why are the changes needed?

in postProcess in AlterViewAddPartitionAnalyzer.java all partition values are treated as string literals which prevent it from adding partition in parition columns are other than string columns.
Steps to reproduce are explained on jira: https://issues.apache.org/jira/browse/HIVE-29782

Does this PR introduce any user-facing change?

No

How was this patch tested?

Added ut and results of ci

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes HIVE-29782 by ensuring ALTER VIEW ... ADD PARTITION generates correctly-typed partition literals (instead of forcing all partition values to be treated as strings), so partitions can be added for views partitioned on non-string primitive columns.

Changes:

  • Update AlterViewAddPartitionAnalyzer to format partition literals based on the partition column type.
  • Add validation in CreateViewAnalyzer to reject non-primitive partition columns for partitioned views.
  • Add new positive/negative qtests covering primitive (int/boolean/date/decimal) and non-primitive (struct) partition columns.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/partition/add/AlterViewAddPartitionAnalyzer.java Generate type-aware literals for the internal validation query used by ALTER VIEW ADD PARTITION.
ql/src/java/org/apache/hadoop/hive/ql/ddl/view/create/CreateViewAnalyzer.java Validate that view partition columns are primitive types.
ql/src/test/queries/clientpositive/partitioned_view_add_parts.q New positive coverage for adding partitions to views with non-string primitive partition columns.
ql/src/test/results/clientpositive/llap/partitioned_view_add_parts.q.out Expected output for the new positive test.
ql/src/test/queries/clientnegative/partitioned_view_add_parts_complex.q New negative coverage: reject non-primitive partition column in CREATE VIEW ... PARTITIONED ON.
ql/src/test/results/clientnegative/partitioned_view_add_parts_complex.q.out Expected error output for the new negative test.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +109 to +115
private static String formatPartitionLiteral(FieldSchema partCol, String partSpecValue) {
TypeInfo typeInfo = TypeInfoFactory.getPrimitiveTypeInfo(partCol.getType());
ObjectInspector partColOI = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(typeInfo);
Object converted = ObjectInspectorConverters.getConverter(
PrimitiveObjectInspectorFactory.javaStringObjectInspector, partColOI).convert(partSpecValue);
return new ExprNodeConstantDesc(typeInfo, converted).getExprString();
}

@ramitg254 ramitg254 Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

addressed it 785694e

…on columns

Change-Id: I56fa674c2d7c8db6187d75e9fd2f5d39a3ec766e

Change-Id: I790b126f63e73d03dc0ef2d04ed1e71d37f79028
Change-Id: Ie22bcfb10d777360d9ee013d8f2ccba65c91f218
@sonarqubecloud

Copy link
Copy Markdown

@ayushtkn ayushtkn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanx @ramitg254 for working on this. Have dropped a couple of comments

Comment on lines +193 to +198
try {
TypeInfoFactory.getPrimitiveTypeInfo(fieldSchema.getType());
} catch (Exception e) {
throw new SemanticException(ErrorMsg.PARTITION_COLUMN_NON_PRIMITIVE.getMsg() + " Found "
+ columnName + " of type: " + fieldSchema.getType());
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we instead of catching Exception and throwing do

TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromTypeString(fieldSchema.getType());
      if (typeInfo.getCategory() != ObjectInspector.Category.PRIMITIVE) {
        throw new SemanticException(ErrorMsg.PARTITION_COLUMN_NON_PRIMITIVE.getMsg() + " Found "
            + columnName + " of type: " + fieldSchema.getType());
      }

} else {
where.append(" AND ");
}
FieldSchema partCol = table.getColumnByName(entry.getKey());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shoudln't this be?

FieldSchema partCol = table.getPartColByName(entry.getKey());

can u check how it is working currently, the logic inside getPartColByName handles nonNativePartition as well, see if it is working

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.

5 participants