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): use type string name other than category #1191

Merged
merged 2 commits into from
Sep 15, 2022
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 @@ -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 @@ -90,7 +90,7 @@ public void writeToStore(String tableName, InputStream jsonLine) {

private TableSchemaDesc toSchema(Map<String, ColumnType> tableSchemaMap) {
List<ColumnSchemaDesc> columnSchemaDescs = tableSchemaMap.entrySet().stream()
.map(entry -> new ColumnSchemaDesc(entry.getKey(), entry.getValue().getCategory())).collect(
.map(entry -> new ColumnSchemaDesc(entry.getKey(), entry.getValue().toString())).collect(
Collectors.toList());
return new TableSchemaDesc("id", columnSchemaDescs);
}
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,22 @@ public void testLegacySchema() {
List<ColumnSchemaDesc> columnSchemaList = tableSchemaDesc.getColumnSchemaList();
columnSchemaList.forEach(columnSchemaDesc -> {
if ("id".equals(columnSchemaDesc.getName())) {
Assertions.assertEquals(ColumnType.INT64.getCategory(), columnSchemaDesc.getType());
Assertions.assertEquals("INT64", columnSchemaDesc.getType());
}
if ("data_offset".equals(columnSchemaDesc.getName())) {
Assertions.assertEquals(ColumnType.INT64.getCategory(), columnSchemaDesc.getType());
Assertions.assertEquals("INT64", columnSchemaDesc.getType());
}
if ("data_size".equals(columnSchemaDesc.getName())) {
Assertions.assertEquals(ColumnType.INT64.getCategory(), columnSchemaDesc.getType());
Assertions.assertEquals("INT64", columnSchemaDesc.getType());
}
if ("data_format".equals(columnSchemaDesc.getName())) {
Assertions.assertEquals(ColumnType.STRING.getCategory(), columnSchemaDesc.getType());
Assertions.assertEquals("STRING", columnSchemaDesc.getType());
}
if ("object_store_type".equals(columnSchemaDesc.getName())) {
Assertions.assertEquals(ColumnType.STRING.getCategory(), columnSchemaDesc.getType());
Assertions.assertEquals("STRING", columnSchemaDesc.getType());
}
if ("score".equals(columnSchemaDesc.getName())) {
Assertions.assertEquals(ColumnType.FLOAT64.getCategory(), columnSchemaDesc.getType());
Assertions.assertEquals("FLOAT64", columnSchemaDesc.getType());
}
});
Assertions.assertEquals("table-x", request.getTableName());
Expand Down