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

[BugFix] Fix exception when loading empty json string to json column #380

Merged
merged 1 commit into from
Sep 19, 2024
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 @@ -132,7 +132,7 @@ private Object typeConvertion(LogicalType type, RowData record, int pos) {
columns.getOrDefault(columnNames[pos], StarRocksDataType.UNKNOWN);
if ((starRocksDataType == StarRocksDataType.JSON ||
starRocksDataType == StarRocksDataType.UNKNOWN)
&& (sValue.charAt(0) == '{' || sValue.charAt(0) == '[')) {
&& !sValue.isEmpty() && (sValue.charAt(0) == '{' || sValue.charAt(0) == '[')) {
// The json string need to be converted to a json object, and to the json string
// again via JSON.toJSONString in StarRocksJsonSerializer#serialize. Otherwise,
// the final json string in stream load will not be correct. For example, the received
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,8 @@ public void testJsonType() throws Exception {
DataStream<Row> dataStream =
env.fromElements(
Row.ofKind(RowKind.INSERT, 1, 1.0, "{\"a\": 1, \"b\": true}"),
Row.ofKind(RowKind.INSERT, 2, 2.0, "{\"a\": 2, \"b\": false}"));
Row.ofKind(RowKind.INSERT, 2, 2.0, "{\"a\": 2, \"b\": false}"),
Row.ofKind(RowKind.INSERT, 3, 3.0, ""));
Table table = tEnv.fromChangelogStream(dataStream, Schema.newBuilder().primaryKey("f0").build(), ChangelogMode.all());
tEnv.createTemporaryView("src", table);

Expand Down Expand Up @@ -687,7 +688,8 @@ public void testJsonType() throws Exception {

List<List<Object>> expectedData = Arrays.asList(
Arrays.asList(1, 1.0, "{\"a\": 1, \"b\": true}"),
Arrays.asList(2, 2.0, "{\"a\": 2, \"b\": false}")
Arrays.asList(2, 2.0, "{\"a\": 2, \"b\": false}"),
Arrays.asList(3, 3.0, "\"\"")
);

verifyResult(expectedData, actualData);
Expand Down
Loading