This is an automated email from the ASF dual-hosted git repository.
kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new ab0f2f2e5f0 [minor](stats) Fix potential npe when loading stats #27200
(#27241)
ab0f2f2e5f0 is described below
commit ab0f2f2e5f018e86bdd7aa919e66bf2db6d4945d
Author: AKIRA <[email protected]>
AuthorDate: Mon Nov 20 18:43:03 2023 +0900
[minor](stats) Fix potential npe when loading stats #27200 (#27241)
---
.../statistics/ColumnStatisticsCacheLoader.java | 5 ++-
.../org/apache/doris/statistics/CacheTest.java | 38 +++++++++++++++++-----
2 files changed, 31 insertions(+), 12 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/statistics/ColumnStatisticsCacheLoader.java
b/fe/fe-core/src/main/java/org/apache/doris/statistics/ColumnStatisticsCacheLoader.java
index 281a0e82502..22f0cad9d00 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/statistics/ColumnStatisticsCacheLoader.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/statistics/ColumnStatisticsCacheLoader.java
@@ -50,11 +50,10 @@ public class ColumnStatisticsCacheLoader extends
StatisticsCacheLoader<Optional<
}
// Load from data source metadata
try {
- TableIf table =
Env.getCurrentEnv().getCatalogMgr().getCatalog(key.catalogId)
-
.getDbOrMetaException(key.dbId).getTableOrMetaException(key.tableId);
+ TableIf table = StatisticsUtil.findTable(key.catalogId, key.dbId,
key.tableId);
columnStatistic = table.getColumnStatistic(key.colName);
} catch (Exception e) {
- LOG.warn(String.format("Exception to get column statistics by
metadata. [Catalog:%d, DB:%d, Table:%d]",
+ LOG.debug(String.format("Exception to get column statistics by
metadata. [Catalog:%d, DB:%d, Table:%d]",
key.catalogId, key.dbId, key.tableId), e);
}
return columnStatistic;
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/statistics/CacheTest.java
b/fe/fe-core/src/test/java/org/apache/doris/statistics/CacheTest.java
index 95ed5023e36..cde8d20177f 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/statistics/CacheTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/statistics/CacheTest.java
@@ -18,12 +18,17 @@
package org.apache.doris.statistics;
import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.DatabaseIf;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.PrimitiveType;
+import org.apache.doris.catalog.TableIf;
import org.apache.doris.catalog.Type;
+import org.apache.doris.catalog.external.ExternalDatabase;
+import org.apache.doris.catalog.external.ExternalTable;
import org.apache.doris.catalog.external.HMSExternalDatabase;
import org.apache.doris.catalog.external.HMSExternalTable;
import org.apache.doris.common.ThreadPoolManager;
+import org.apache.doris.datasource.CatalogIf;
import org.apache.doris.datasource.CatalogMgr;
import org.apache.doris.datasource.HMSExternalCatalog;
import org.apache.doris.ha.FrontendNodeType;
@@ -57,6 +62,7 @@ import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
+import java.util.function.Function;
public class CacheTest extends TestWithFeService {
@@ -229,20 +235,34 @@ public class CacheTest extends TestWithFeService {
}
};
+ new MockUp<CatalogMgr>() {
+ @Mock
+ public <E extends Exception> CatalogIf<? extends DatabaseIf<?
extends TableIf>>
+ getCatalogOrException(long id, Function<Long, E> e) throws
E {
+ return catalog;
+ }
+ };
+
+ new MockUp<HMSExternalCatalog>() {
+ @Mock
+ public ExternalDatabase<? extends ExternalTable>
getDbNullable(long dbId) {
+ return db;
+ }
+ };
+
+ new MockUp<HMSExternalDatabase>() {
+
+ @Mock
+ public HMSExternalTable getTableNullable(long tableId) {
+ return table;
+ }
+ };
+
new Expectations() {
{
env.getCatalogMgr();
result = mgr;
- mgr.getCatalog(1);
- result = catalog;
-
- catalog.getDbOrMetaException(1);
- result = db;
-
- db.getTableOrMetaException(1);
- result = table;
-
table.getColumnStatistic("col");
result = new ColumnStatistic(1, 2,
null, 3, 4, 5, 6, 7,
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]