This is an automated email from the ASF dual-hosted git repository.
Yukang-Lian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new c6269286b0e [fix](nereids) Fix NPE in ADMIN COMPACT TABLE without
PARTITION clause (#70288)
c6269286b0e is described below
commit c6269286b0e9ef1712f61e2204540e27e999d6da
Author: Jamie <[email protected]>
AuthorDate: Fri Nov 27 17:55:01 2026 +0800
[fix](nereids) Fix NPE in ADMIN COMPACT TABLE without PARTITION clause
(#70288)
### Background
`ADMIN COMPACT TABLE db.tbl PARTITION p WHERE type =
'BASE/CUMULATIVE/FULL'` sends a compaction task for every replica of one
partition. The command requires exactly one partition; for a
non-partitioned table the single partition has the same name as the
table.
### What problem does this PR solve?
Issue Number: None
Related PR: #44861 (introduced the bug)
PR Type: Bugfix
Problem Summary:
When the `PARTITION` clause is omitted,
`AdminCompactTableCommand.validate()` throws a `NullPointerException`
and the user sees `Cannot invoke
"PartitionNamesInfo.getPartitionNames()" because the return value of
"TableRefInfo.getPartitionNamesInfo()" is null` instead of `No partition
selected for compaction`. This PR checks the `PartitionNamesInfo` itself
for null, so the command returns the intended error again.
### Details
- **Frequency:** Every `ADMIN COMPACT TABLE` without a `PARTITION`
clause, on both partitioned and non-partitioned tables.
- **Root cause:** When the legacy `AdminCompactTableStmt` was ported to
Nereids in #44861, the null check moved from the `PartitionNames` object
to the inner list. The parser passes a null `PartitionNamesInfo` when
there is no `PARTITION` clause, and the inner list of a non-null
`PartitionNamesInfo` is never null, so the check could never fire.
- **Why existing tests missed it:** There was no test for this command.
- **Fix:** Check `tableRefInfo.getPartitionNamesInfo()` for null,
matching the legacy statement. `run()` reads the partition names only
after `validate()` passes, so it needs no change.
- **Other paths and branches:** Branches that still use the legacy
`AdminCompactTableStmt` are not affected.
### Testing
Added `AdminCompactTableCommandTest` (FE UT): no `PARTITION` clause on a
partitioned and a non-partitioned table, multiple partitions, missing
`WHERE`, and an invalid `type`. The no-partition case fails with the NPE
before this fix and passes after it. Ran locally with `mvn -pl fe-core
-am test -Dtest=AdminCompactTableCommandTest`.
### Release note
Fix a NullPointerException when `ADMIN COMPACT TABLE` is run without a
`PARTITION` clause; it now returns "No partition selected for
compaction".
---
.../plans/commands/AdminCompactTableCommand.java | 7 ++-
.../commands/AdminCompactTableCommandTest.java | 69 ++++++++++++++++++++++
2 files changed, 73 insertions(+), 3 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AdminCompactTableCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AdminCompactTableCommand.java
index 0ca208575f1..73a2dff90fd 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AdminCompactTableCommand.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AdminCompactTableCommand.java
@@ -18,6 +18,7 @@
package org.apache.doris.nereids.trees.plans.commands;
import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.info.PartitionNamesInfo;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
@@ -76,9 +77,9 @@ public class AdminCompactTableCommand extends Command
implements ForwardWithSync
tableRefInfo.analyze(ctx.getNameSpaceContext());
Util.prohibitExternalCatalog(tableRefInfo.getTableNameInfo().getCtl(),
this.getClass().getSimpleName());
- List<String> partitionNames =
tableRefInfo.getPartitionNamesInfo().getPartitionNames();
- if (partitionNames != null) {
- if (partitionNames.size() != 1) {
+ PartitionNamesInfo partitionNamesInfo =
tableRefInfo.getPartitionNamesInfo();
+ if (partitionNamesInfo != null) {
+ if (partitionNamesInfo.getPartitionNames().size() != 1) {
throw new AnalysisException("Only support single partition for
compaction");
}
} else {
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/AdminCompactTableCommandTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/AdminCompactTableCommandTest.java
new file mode 100644
index 00000000000..9a2e2fc03f6
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/AdminCompactTableCommandTest.java
@@ -0,0 +1,69 @@
+// 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.doris.nereids.trees.plans.commands;
+
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.nereids.parser.NereidsParser;
+import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
+import org.apache.doris.utframe.TestWithFeService;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class AdminCompactTableCommandTest extends TestWithFeService {
+ @Override
+ protected void runBeforeAll() throws Exception {
+ createDatabase("test_admin_compact");
+ createTable("CREATE TABLE test_admin_compact.part_tbl (k INT, v INT)
DUPLICATE KEY(k)\n"
+ + "PARTITION BY RANGE(k) (PARTITION p1 VALUES LESS THAN (100),"
+ + " PARTITION p2 VALUES LESS THAN (200))\n"
+ + "DISTRIBUTED BY HASH(k) BUCKETS 1
PROPERTIES('replication_num' = '1')");
+ createTable("CREATE TABLE test_admin_compact.non_part_tbl (k INT, v
INT) DUPLICATE KEY(k)\n"
+ + "DISTRIBUTED BY HASH(k) BUCKETS 1
PROPERTIES('replication_num' = '1')");
+ }
+
+ private void assertAnalysisError(String sql, String expectedMsg) {
+ LogicalPlan plan = new NereidsParser().parseSingle(sql);
+ Assertions.assertTrue(plan instanceof AdminCompactTableCommand);
+ AnalysisException exception =
Assertions.assertThrows(AnalysisException.class,
+ () -> ((AdminCompactTableCommand) plan).run(connectContext,
null));
+ Assertions.assertTrue(exception.getMessage().contains(expectedMsg),
exception.getMessage());
+ }
+
+ @Test
+ public void testNoPartitionSpecified() {
+ assertAnalysisError("ADMIN COMPACT TABLE test_admin_compact.part_tbl
WHERE type = 'BASE'",
+ "No partition selected for compaction");
+ assertAnalysisError("ADMIN COMPACT TABLE
test_admin_compact.non_part_tbl WHERE type = 'BASE'",
+ "No partition selected for compaction");
+ }
+
+ @Test
+ public void testMultiplePartitions() {
+ assertAnalysisError("ADMIN COMPACT TABLE test_admin_compact.part_tbl
PARTITION (p1, p2) WHERE type = 'BASE'",
+ "Only support single partition for compaction");
+ }
+
+ @Test
+ public void testInvalidWhereClause() {
+ assertAnalysisError("ADMIN COMPACT TABLE test_admin_compact.part_tbl
PARTITION p1",
+ "Compaction type must be specified in Where clause");
+ assertAnalysisError("ADMIN COMPACT TABLE test_admin_compact.part_tbl
PARTITION p1 WHERE type = 'xxx'",
+ "Where clause should looks like");
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]