Skip to content

Commit

Permalink
make string resp
Browse files Browse the repository at this point in the history
  • Loading branch information
jialeicui committed Sep 15, 2022
1 parent 61ea2f8 commit c3c39be
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public ResponseEntity<ResponseMessage<RecordListVo>> queryTable(QueryTableReques
.ignoreNonExistingTable(request.isIgnoreNonExistingTable())
.build());
return ResponseEntity.ok(Code.success.asResponse(RecordListVo.builder()
.columnTypes(recordList.getColumnTypeMap())
.columnTypes(recordList.getColumnTypeStringMap())
.records(recordList.getRecords())
.build()));
} catch (SwValidationException e) {
Expand Down Expand Up @@ -154,7 +154,7 @@ public ResponseEntity<ResponseMessage<RecordListVo>> scanTable(ScanTableRequest
.ignoreNonExistingTable(request.isIgnoreNonExistingTable())
.build());
return ResponseEntity.ok(Code.success.asResponse(RecordListVo.builder()
.columnTypes(recordList.getColumnTypeMap())
.columnTypes(recordList.getColumnTypeStringMap())
.records(recordList.getRecords())
.lastKey(recordList.getLastKey())
.build()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package ai.starwhale.mlops.api.protocol.datastore;

import ai.starwhale.mlops.datastore.ColumnType;
import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
Expand All @@ -30,7 +29,7 @@
@AllArgsConstructor
public class RecordListVo {

private Map<String, ColumnType> columnTypes;
private Map<String, String> columnTypes;
private List<Map<String, String>> records;
private String lastKey;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import lombok.Getter;

Expand All @@ -28,4 +29,9 @@ public class RecordList {
private Map<String, ColumnType> columnTypeMap;
private List<Map<String, String>> records;
private String lastKey;

public Map<String, String> getColumnTypeStringMap() {
return columnTypeMap.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, i -> i.getValue().toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public void testUpdate() {
assertThat("t1", resp.getStatusCode().is2xxSuccessful(), is(true));
assertThat("t1",
Objects.requireNonNull(resp.getBody()).getData().getColumnTypes(),
is(Map.of("k", ColumnType.INT32, "b", ColumnType.INT32)));
is(Map.of("k", ColumnType.INT32.toString(), "b", ColumnType.INT32.toString())));
assertThat("t1",
Objects.requireNonNull(resp.getBody()).getData().getRecords(),
is(List.of(Map.of("k", "1", "b", "2"))));
Expand All @@ -241,7 +241,7 @@ public void testUpdate() {
assertThat("t2", resp.getStatusCode().is2xxSuccessful(), is(true));
assertThat("t2",
Objects.requireNonNull(resp.getBody()).getData().getColumnTypes(),
is(Map.of("k", ColumnType.INT32, "b", ColumnType.INT32)));
is(Map.of("k", ColumnType.INT32.toString(), "b", ColumnType.INT32.toString())));
assertThat("t2",
Objects.requireNonNull(resp.getBody()).getData().getRecords(),
is(List.of(Map.of("k", "3", "b", "2"))));
Expand Down Expand Up @@ -550,7 +550,8 @@ public void testQueryDefault() {
assertThat("test", resp.getStatusCode().is2xxSuccessful(), is(true));
assertThat("test",
Objects.requireNonNull(resp.getBody()).getData().getColumnTypes(),
is(Map.of("k", ColumnType.INT32, "a", ColumnType.INT32, "x", ColumnType.INT32)));
is(Map.of("k", ColumnType.INT32.toString(), "a", ColumnType.INT32.toString(), "x",
ColumnType.INT32.toString())));
assertThat("test",
Objects.requireNonNull(resp.getBody()).getData().getRecords(),
is(List.of(Map.of("k", "0", "a", "5"),
Expand All @@ -566,7 +567,7 @@ public void testQuery() {
assertThat("test", resp.getStatusCode().is2xxSuccessful(), is(true));
assertThat("test",
Objects.requireNonNull(resp.getBody()).getData().getColumnTypes(),
is(Map.of("k", ColumnType.INT32, "b", ColumnType.INT32)));
is(Map.of("k", ColumnType.INT32.toString(), "b", ColumnType.INT32.toString())));
assertThat("test",
Objects.requireNonNull(resp.getBody()).getData().getRecords(),
is(List.of(Map.of("k", "1", "b", "4"),
Expand All @@ -584,7 +585,7 @@ public void testQuery() {
assertThat("test", resp.getStatusCode().is2xxSuccessful(), is(true));
assertThat("test",
Objects.requireNonNull(resp.getBody()).getData().getColumnTypes(),
is(Map.of("k", ColumnType.INT32, "b", ColumnType.INT32)));
is(Map.of("k", ColumnType.INT32.toString(), "b", ColumnType.INT32.toString())));
assertThat("test",
Objects.requireNonNull(resp.getBody()).getData().getRecords(),
is(List.of(Map.of("k", "1", "b", "4"))));
Expand All @@ -599,7 +600,8 @@ public void testQuery() {
assertThat("test", resp.getStatusCode().is2xxSuccessful(), is(true));
assertThat("test",
Objects.requireNonNull(resp.getBody()).getData().getColumnTypes(),
is(Map.of("k", ColumnType.INT32, "b", ColumnType.INT32, "x", ColumnType.INT32)));
is(Map.of("k", ColumnType.INT32.toString(), "b", ColumnType.INT32.toString(), "x",
ColumnType.INT32.toString())));
assertThat("test",
Objects.requireNonNull(resp.getBody()).getData().getRecords(),
is(List.of(new HashMap<>() {
Expand All @@ -615,7 +617,8 @@ public void testQuery() {
assertThat("test", resp.getStatusCode().is2xxSuccessful(), is(true));
assertThat("test",
Objects.requireNonNull(resp.getBody()).getData().getColumnTypes(),
is(Map.of("k", ColumnType.INT32, "b", ColumnType.INT32, "x", ColumnType.INT32)));
is(Map.of("k", ColumnType.INT32.toString(), "b", ColumnType.INT32.toString(), "x",
ColumnType.INT32.toString())));
assertThat("test",
Objects.requireNonNull(resp.getBody()).getData().getRecords(),
is(List.of(new HashMap<>() {
Expand Down Expand Up @@ -747,7 +750,7 @@ public void testEqualNull() {
var resp = DataStoreControllerTest.this.controller.queryTable(this.req);
assertThat(resp.getStatusCode().is2xxSuccessful(), is(true));
assertThat(Objects.requireNonNull(resp.getBody()).getData().getColumnTypes(),
is(Map.of("k", ColumnType.INT32, "b", ColumnType.INT32)));
is(Map.of("k", ColumnType.INT32.toString(), "b", ColumnType.INT32.toString())));
assertThat(Objects.requireNonNull(resp.getBody()).getData().getRecords(),
is(List.of(new HashMap<>() {
{
Expand Down Expand Up @@ -1134,7 +1137,7 @@ public void testScanDefault() {
assertThat("test", resp.getStatusCode().is2xxSuccessful(), is(true));
assertThat("test",
Objects.requireNonNull(resp.getBody()).getData().getColumnTypes(),
is(Map.of("k", ColumnType.INT32, "a", ColumnType.INT32)));
is(Map.of("k", ColumnType.INT32.toString(), "a", ColumnType.INT32.toString())));
assertThat("test",
Objects.requireNonNull(resp.getBody()).getData().getRecords(),
is(List.of(Map.of("k", "0", "a", "5"),
Expand All @@ -1151,7 +1154,8 @@ public void testScan() {
assertThat("test", resp.getStatusCode().is2xxSuccessful(), is(true));
assertThat("test",
Objects.requireNonNull(resp.getBody()).getData().getColumnTypes(),
is(Map.of("k", ColumnType.INT32, "a", ColumnType.INT32, "b", ColumnType.INT32)));
is(Map.of("k", ColumnType.INT32.toString(), "a", ColumnType.INT32.toString(), "b",
ColumnType.INT32.toString())));
assertThat("test",
Objects.requireNonNull(resp.getBody()).getData().getRecords(),
is(List.of(Map.of("k", "1", "b", "1", "a", "10"),
Expand All @@ -1169,7 +1173,8 @@ public void testScan() {
assertThat("test", resp.getStatusCode().is2xxSuccessful(), is(true));
assertThat("test",
Objects.requireNonNull(resp.getBody()).getData().getColumnTypes(),
is(Map.of("k", ColumnType.INT32, "a", ColumnType.INT32, "b", ColumnType.INT32)));
is(Map.of("k", ColumnType.INT32.toString(), "a", ColumnType.INT32.toString(), "b",
ColumnType.INT32.toString())));
assertThat("test",
Objects.requireNonNull(resp.getBody()).getData().getRecords(),
is(List.of(Map.of("k", "1", "b", "1", "a", "10"))));
Expand All @@ -1180,7 +1185,8 @@ public void testScan() {
assertThat("test", resp.getStatusCode().is2xxSuccessful(), is(true));
assertThat("test",
Objects.requireNonNull(resp.getBody()).getData().getColumnTypes(),
is(Map.of("k", ColumnType.INT32, "a", ColumnType.INT32, "b", ColumnType.INT32)));
is(Map.of("k", ColumnType.INT32.toString(), "a", ColumnType.INT32.toString(), "b",
ColumnType.INT32.toString())));
assertThat("test",
Objects.requireNonNull(resp.getBody()).getData().getRecords(),
is(List.of(Map.of("k", "1", "b", "1", "a", "16"))));
Expand Down

0 comments on commit c3c39be

Please sign in to comment.