Xikui Wang has submitted this change and it was merged. Change subject: [ASTERIXDB-2514] Fix BigInt display in formatted JSON ......................................................................
[ASTERIXDB-2514] Fix BigInt display in formatted JSON - user model changes: no - storage format changes: no - interface changes: no Javascript treats all numbers as doubles. This causes large BigInt values cannot be displayed properly in the formatted JSON option, and the lower digits are replaced with "0". In this patch, we cast the numbers into strings with special characters, and cast those strings back after they are parsed by the JSON parser. Also, to make sure future new data types can be displayed properly, the default JSON display is set to "literal". Change-Id: I1bbef349efba0da24d01afb1cb17b4f7d5b7f261 Reviewed-on: https://asterix-gerrit.ics.uci.edu/3142 Sonar-Qube: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Integration-Tests: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Contrib: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Reviewed-by: Michael Blow <mb...@apache.org> --- M asterixdb/asterix-app/src/main/resources/webui/querytemplate.html M asterixdb/asterix-app/src/main/resources/webui/static/js/jquery.json-viewer.js 2 files changed, 11 insertions(+), 5 deletions(-) Approvals: Jenkins: Verified; No violations found; ; Verified Michael Blow: Looks good to me, approved diff --git a/asterixdb/asterix-app/src/main/resources/webui/querytemplate.html b/asterixdb/asterix-app/src/main/resources/webui/querytemplate.html index 1157c27..31448ee 100644 --- a/asterixdb/asterix-app/src/main/resources/webui/querytemplate.html +++ b/asterixdb/asterix-app/src/main/resources/webui/querytemplate.html @@ -181,7 +181,14 @@ if (results[iter1].length < 1) { continue; } - var resultJSON = $.parseJSON(results[iter1]); + var str_obj = results[iter1].replace(/:\s*(\d+)([\s,])/g, ': "#bigint#$1#bigint#"$2'); + resultJSON = JSON.parse(str_obj, (key, value) => { + if (/^#bigint#\d+#bigint#/g.test(value)) { + value = value.substring(8, value.length - 8); + return BigInt(value); + } + return value; + }); $(this).append($('<div/>').attr("id", "json-record"+idx+"-"+iter1)); $('#json-record'+idx+"-"+iter1).jsonViewer(resultJSON, {collapsed: true, level: 10}); } diff --git a/asterixdb/asterix-app/src/main/resources/webui/static/js/jquery.json-viewer.js b/asterixdb/asterix-app/src/main/resources/webui/static/js/jquery.json-viewer.js index 5e8a79e..f31b555 100644 --- a/asterixdb/asterix-app/src/main/resources/webui/static/js/jquery.json-viewer.js +++ b/asterixdb/asterix-app/src/main/resources/webui/static/js/jquery.json-viewer.js @@ -56,10 +56,7 @@ else html += '<span class="json-string">"' + json + '"</span>'; } - else if (typeof json === 'number') { - html += '<span class="json-literal">' + json + '</span>'; - } - else if (typeof json === 'boolean') { + else if (typeof json === 'number' || typeof json === 'boolean' || typeof json === 'bigint') { html += '<span class="json-literal">' + json + '</span>'; } else if (json === null) { @@ -111,6 +108,8 @@ else { html += '{}'; } + } else { + html += '<span class="json-literal">' + json + '</span>'; } return html; } -- To view, visit https://asterix-gerrit.ics.uci.edu/3142 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: merged Gerrit-Change-Id: I1bbef349efba0da24d01afb1cb17b4f7d5b7f261 Gerrit-PatchSet: 2 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Xikui Wang <xkk...@gmail.com> Gerrit-Reviewer: Ian Maxon <ima...@apache.org> Gerrit-Reviewer: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Gerrit-Reviewer: Michael Blow <mb...@apache.org> Gerrit-Reviewer: Xikui Wang <xkk...@gmail.com>