Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(controller):set datastore api param 'ignoreNonExistingTable'=true #1297

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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