This is an automated email from the ASF dual-hosted git repository.

dengzhhu653 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new f499507dd82 HIVE-30148: Fix NPE in 
TableStoreImpl.getPartitionSpecsByFilterAndProjection when filterSpec is unset 
(#6863)
f499507dd82 is described below

commit f499507dd82126651cd17aadfb94d75ea7b90907
Author: Yuming Wang <[email protected]>
AuthorDate: Mon Oct 12 16:12:29 2026 +0800

    HIVE-30148: Fix NPE in 
TableStoreImpl.getPartitionSpecsByFilterAndProjection when filterSpec is unset 
(#6863)
---
 .../test/queries/clientpositive/show_tablestatus.q |  3 +++
 .../clientpositive/llap/show_tablestatus.q.out     | 17 +++++++++++++
 .../src/main/thrift/hive_metastore.thrift          |  2 +-
 .../metastore/metastore/impl/TableStoreImpl.java   |  7 +++++-
 ...GetPartitionsUsingProjectionAndFilterSpecs.java | 29 ++++++++++++++++++++++
 5 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/ql/src/test/queries/clientpositive/show_tablestatus.q 
b/ql/src/test/queries/clientpositive/show_tablestatus.q
index 0340670a6c8..19c9a0b99fd 100644
--- a/ql/src/test/queries/clientpositive/show_tablestatus.q
+++ b/ql/src/test/queries/clientpositive/show_tablestatus.q
@@ -19,4 +19,7 @@ SHOW TABLE EXTENDED from default LIKE "%";
 
 SHOW TABLE EXTENDED LIKE `srcpart` PARTITION(ds='2008-04-08', hr=11);
 
+-- no PARTITION clause on a partitioned table: must list all of its partitions
+SHOW TABLE EXTENDED LIKE `srcpart`;
+
 SHOW TABLE EXTENDED from default LIKE src;
diff --git a/ql/src/test/results/clientpositive/llap/show_tablestatus.q.out 
b/ql/src/test/results/clientpositive/llap/show_tablestatus.q.out
index 763287a4921..0dc035906fb 100644
--- a/ql/src/test/results/clientpositive/llap/show_tablestatus.q.out
+++ b/ql/src/test/results/clientpositive/llap/show_tablestatus.q.out
@@ -156,6 +156,23 @@ maxFileSize:#Masked#
 minFileSize:#Masked#
 #### A masked pattern was here ####
 
+PREHOOK: query: SHOW TABLE EXTENDED LIKE `srcpart`
+PREHOOK: type: SHOW_TABLESTATUS
+POSTHOOK: query: SHOW TABLE EXTENDED LIKE `srcpart`
+POSTHOOK: type: SHOW_TABLESTATUS
+tableName:srcpart
+#### A masked pattern was here ####
+inputformat:org.apache.hadoop.mapred.TextInputFormat
+outputformat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
+columns:struct columns { string key, string value}
+partitioned:true
+partitionColumns:struct partition_columns { string ds, string hr}
+totalNumberFiles:4
+totalFileSize:#Masked#
+maxFileSize:#Masked#
+minFileSize:#Masked#
+#### A masked pattern was here ####
+
 PREHOOK: query: SHOW TABLE EXTENDED from default LIKE src
 PREHOOK: type: SHOW_TABLESTATUS
 POSTHOOK: query: SHOW TABLE EXTENDED from default LIKE src
diff --git 
a/standalone-metastore/metastore-common/src/main/thrift/hive_metastore.thrift 
b/standalone-metastore/metastore-common/src/main/thrift/hive_metastore.thrift
index a092471aa65..a4707447128 100644
--- 
a/standalone-metastore/metastore-common/src/main/thrift/hive_metastore.thrift
+++ 
b/standalone-metastore/metastore-common/src/main/thrift/hive_metastore.thrift
@@ -2351,7 +2351,7 @@ struct GetPartitionsRequest {
    5: optional string user,
    6: optional list<string> groupNames,
    7: GetProjectionsSpec projectionSpec
-   8: GetPartitionsFilterSpec filterSpec,
+   8: GetPartitionsFilterSpec filterSpec, // if unset, no filtering is applied 
and all partitions are returned
    9: optional list<string> processorCapabilities,
    10: optional string processorIdentifier,
    11: optional string validWriteIdList
diff --git 
a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/metastore/impl/TableStoreImpl.java
 
b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/metastore/impl/TableStoreImpl.java
index 0c4690ba141..6caed023de5 100644
--- 
a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/metastore/impl/TableStoreImpl.java
+++ 
b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/metastore/impl/TableStoreImpl.java
@@ -2069,7 +2069,12 @@ protected List<Partition> getJdoResult() throws 
MetaException, NoSuchObjectExcep
   @Override
   public List<Partition> getPartitionSpecsByFilterAndProjection(Table table,
       GetProjectionsSpec partitionsProjectSpec,
-      GetPartitionsFilterSpec filterSpec) throws MetaException, 
NoSuchObjectException {
+      GetPartitionsFilterSpec rawFilterSpec) throws MetaException, 
NoSuchObjectException {
+    // filterSpec is an optional field on the thrift request (e.g. SHOW TABLE 
EXTENDED without a
+    // PARTITION clause leaves it unset to mean "no filter"); normalize once 
here so the SQL/JDO
+    // code paths below can treat it uniformly instead of null-checking at 
every usage site.
+    final GetPartitionsFilterSpec filterSpec =
+        rawFilterSpec != null ? rawFilterSpec : new GetPartitionsFilterSpec();
     List<String> fieldList = null;
     String inputIncludePattern = null;
     String inputExcludePattern = null;
diff --git 
a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestGetPartitionsUsingProjectionAndFilterSpecs.java
 
b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestGetPartitionsUsingProjectionAndFilterSpecs.java
index dc0619895c5..2c325ba66ae 100644
--- 
a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestGetPartitionsUsingProjectionAndFilterSpecs.java
+++ 
b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestGetPartitionsUsingProjectionAndFilterSpecs.java
@@ -662,6 +662,35 @@ public void testGetPartitionsUsingNamesWithJDO() throws 
Exception {
     runGetPartitionsUsingNames();
   }
 
+  private void runGetPartitionsWithNullFilterSpec() throws TException {
+    // a client that never calls setFilterSpec() leaves the field null; the 
server
+    // must treat that the same as an "accept all partitions" filter instead 
of throwing NPE
+    GetPartitionsRequest request = getGetPartitionsRequest();
+    request.setFilterSpec(null);
+    request.getProjectionSpec().setFieldList(Arrays.asList("sd.location"));
+
+    GetPartitionsResponse response = client.getPartitionsWithSpecs(request);
+    Assert.assertNotNull(response);
+    Assert.assertEquals(1, response.getPartitionSpecSize());
+    PartitionSpecWithSharedSD partitionSpecWithSharedSD =
+        response.getPartitionSpec().get(0).getSharedSDPartitionSpec();
+    Assert.assertNotNull(partitionSpecWithSharedSD);
+    Assert.assertEquals("All partitions should be returned when filterSpec is 
null",
+        origPartitions.size(), partitionSpecWithSharedSD.getPartitionsSize());
+  }
+
+  @Test
+  public void testGetPartitionsWithNullFilterSpec() throws Exception {
+    runGetPartitionsWithNullFilterSpec();
+  }
+
+  @Test
+  public void testGetPartitionsWithNullFilterSpecUsingJDO() throws Exception {
+    // disable direct SQL to make sure the JDO code path is exercised
+    client.setMetaConf(ConfVars.TRY_DIRECT_SQL.getVarname(), "false");
+    runGetPartitionsWithNullFilterSpec();
+  }
+
   @Test(expected = MetaException.class)
   public void testInvalidFilterByNames() throws Exception {
     runWithInvalidFilterByNames();

Reply via email to