Skip to content

Commit

Permalink
fix(controller):set datastore api param 'ignoreNonExistingTable'=true (
Browse files Browse the repository at this point in the history
…#1297)

* set datastore api param 'ignoreNonExistingTable'=true

* add warn log for empty table

* update unit test
  • Loading branch information
goldenxinxing authored Sep 23, 2022
1 parent 7f40068 commit c2b343f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ public class QueryTableRequest {
private int limit = -1;
private boolean keepNone;
private boolean rawResult;
private boolean ignoreNonExistingTable;
private boolean ignoreNonExistingTable = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ public class ScanTableRequest {
private int limit = -1;
private boolean keepNone;
private boolean rawResult;
private boolean ignoreNonExistingTable;
private boolean ignoreNonExistingTable = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -253,9 +255,13 @@ var record = new HashMap<String, String>();

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
"");
Expand All @@ -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));
Expand Down Expand Up @@ -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),
"");
Expand All @@ -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));
Expand Down

0 comments on commit c2b343f

Please sign in to comment.