Skip to content

Commit

Permalink
[BugFix] Fix exception when loading empty json string to json column
Browse files Browse the repository at this point in the history
Signed-off-by: PengFei Li <[email protected]>
  • Loading branch information
banmoy committed Aug 21, 2024
1 parent 98226dd commit d629536
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
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

0 comments on commit d629536

Please sign in to comment.