raminqaf commented on code in PR #29342:
URL: https://github.com/apache/flink/pull/29342#discussion_r4153018266
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/scalar/ParseJsonFunction.java:
##########
@@ -43,9 +44,19 @@ public
ParseJsonFunction(SpecializedFunction.SpecializedContext context) {
return null;
}
+ final byte[] bytes = jsonStr.toBytes();
try {
- return BinaryVariantInternalBuilder.parseJson(jsonStr.toString(),
allowDuplicateKeys);
+ return BinaryVariantInternalBuilder.parseJson(bytes,
allowDuplicateKeys);
} catch (Throwable e) {
+ final int invalidIndex =
+ StringUtf8Utils.firstInvalidUtf8ByteIndex(bytes, 0,
bytes.length);
+ if (invalidIndex >= 0) {
+ throw new TableRuntimeException(
+ String.format(
+ "Failed to parse json string: Invalid UTF-8
byte at index %d of %d.",
Review Comment:
Addressed
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/scalar/ParseJsonFunction.java:
##########
@@ -43,9 +44,19 @@ public
ParseJsonFunction(SpecializedFunction.SpecializedContext context) {
return null;
}
+ final byte[] bytes = jsonStr.toBytes();
try {
- return BinaryVariantInternalBuilder.parseJson(jsonStr.toString(),
allowDuplicateKeys);
+ return BinaryVariantInternalBuilder.parseJson(bytes,
allowDuplicateKeys);
} catch (Throwable e) {
+ final int invalidIndex =
+ StringUtf8Utils.firstInvalidUtf8ByteIndex(bytes, 0,
bytes.length);
+ if (invalidIndex >= 0) {
+ throw new TableRuntimeException(
+ String.format(
+ "Failed to parse json string: Invalid UTF-8
byte at index %d of %d.",
+ invalidIndex, bytes.length),
+ e);
+ }
throw new TableRuntimeException(
String.format("Failed to parse json string: %s", jsonStr),
e);
Review Comment:
Addressed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]