From c2b343f4606dc61fe93ac6f1d7556e42a9340537 Mon Sep 17 00:00:00 2001 From: star <15031259256@163.com> Date: Fri, 23 Sep 2022 17:11:42 +0800 Subject: [PATCH] fix(controller):set datastore api param 'ignoreNonExistingTable'=true (#1297) * set datastore api param 'ignoreNonExistingTable'=true * add warn log for empty table * update unit test --- .../api/protocol/datastore/QueryTableRequest.java | 2 +- .../mlops/api/protocol/datastore/ScanTableRequest.java | 2 +- .../java/ai/starwhale/mlops/datastore/DataStore.java | 10 ++++++++-- .../starwhale/mlops/api/DataStoreControllerTest.java | 4 ++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/server/controller/src/main/java/ai/starwhale/mlops/api/protocol/datastore/QueryTableRequest.java b/server/controller/src/main/java/ai/starwhale/mlops/api/protocol/datastore/QueryTableRequest.java index 04a05b2b70..726df492d5 100644 --- a/server/controller/src/main/java/ai/starwhale/mlops/api/protocol/datastore/QueryTableRequest.java +++ b/server/controller/src/main/java/ai/starwhale/mlops/api/protocol/datastore/QueryTableRequest.java @@ -32,5 +32,5 @@ public class QueryTableRequest { private int limit = -1; private boolean keepNone; private boolean rawResult; - private boolean ignoreNonExistingTable; + private boolean ignoreNonExistingTable = true; } diff --git a/server/controller/src/main/java/ai/starwhale/mlops/api/protocol/datastore/ScanTableRequest.java b/server/controller/src/main/java/ai/starwhale/mlops/api/protocol/datastore/ScanTableRequest.java index fa83fce205..80095a9e66 100644 --- a/server/controller/src/main/java/ai/starwhale/mlops/api/protocol/datastore/ScanTableRequest.java +++ b/server/controller/src/main/java/ai/starwhale/mlops/api/protocol/datastore/ScanTableRequest.java @@ -30,5 +30,5 @@ public class ScanTableRequest { private int limit = -1; private boolean keepNone; private boolean rawResult; - private boolean ignoreNonExistingTable; + private boolean ignoreNonExistingTable = true; } diff --git a/server/controller/src/main/java/ai/starwhale/mlops/datastore/DataStore.java b/server/controller/src/main/java/ai/starwhale/mlops/datastore/DataStore.java index 6e2ba9b7b0..b77522f80f 100644 --- a/server/controller/src/main/java/ai/starwhale/mlops/datastore/DataStore.java +++ b/server/controller/src/main/java/ai/starwhale/mlops/datastore/DataStore.java @@ -30,8 +30,10 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; import java.util.stream.Collectors; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +@Slf4j @Component public class DataStore { @@ -253,9 +255,13 @@ var record = new HashMap(); private MemoryTable getTable(String tableName, boolean allowNull) { var table = tables.get(tableName); - if (table == null && !allowNull) { - throw new SwValidationException(SwValidationException.ValidSubject.DATASTORE).tip( + if (table == null) { + if (allowNull) { + log.warn("not found table:{}!", tableName); + } else { + throw new SwValidationException(SwValidationException.ValidSubject.DATASTORE).tip( "invalid table name " + tableName); + } } return table; } diff --git a/server/controller/src/test/java/ai/starwhale/mlops/api/DataStoreControllerTest.java b/server/controller/src/test/java/ai/starwhale/mlops/api/DataStoreControllerTest.java index c95eb9c460..30d9fd2c81 100644 --- a/server/controller/src/test/java/ai/starwhale/mlops/api/DataStoreControllerTest.java +++ b/server/controller/src/test/java/ai/starwhale/mlops/api/DataStoreControllerTest.java @@ -641,6 +641,7 @@ public void testNullTableName() { @Test public void testTableNotExists() { this.req.setTableName("table not exists"); + this.req.setIgnoreNonExistingTable(false); assertThrows(SwValidationException.class, () -> DataStoreControllerTest.this.controller.queryTable(this.req), ""); @@ -649,7 +650,6 @@ public void testTableNotExists() { @Test public void testTableNotExistsIgnore() { this.req.setTableName("table not exists"); - this.req.setIgnoreNonExistingTable(true); var resp = DataStoreControllerTest.this.controller.queryTable(this.req); assertThat("test", resp.getStatusCode().is2xxSuccessful(), is(true)); @@ -1216,6 +1216,7 @@ public void testNullTableName() { @Test public void testInvalidTableName() { this.req.getTables().get(0).setTableName("invalid"); + this.req.setIgnoreNonExistingTable(false); assertThrows(SwValidationException.class, () -> DataStoreControllerTest.this.controller.scanTable(this.req), ""); @@ -1224,7 +1225,6 @@ public void testInvalidTableName() { @Test public void testTableNotExistsIgnore() { this.req.getTables().get(0).setTableName("invalid"); - this.req.setIgnoreNonExistingTable(true); var resp = DataStoreControllerTest.this.controller.scanTable(this.req); assertThat("test", resp.getStatusCode().is2xxSuccessful(), is(true));