From f4e8b4dbc53c1255ba7761fb5e88ad5bc570bc33 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Mon, 10 Sep 2018 22:16:18 -0700 Subject: [PATCH] [sql lab] handle large ints, prevent overflow (#5829) * [sql lab] handle large ints, prevent overflow * Fix tests (cherry picked from commit 039e7c56d8d7338759213f3acd0d7a81a724781f) (cherry picked from commit 0e49205dce79006701d757ce7e5117956a139655) --- superset/assets/package.json | 1 + .../assets/spec/javascripts/sqllab/actions_spec.js | 9 +-------- superset/assets/src/SqlLab/actions.js | 7 +++++-- superset/assets/yarn.lock | 14 ++++++++++++++ yarn.lock | 4 ---- 5 files changed, 21 insertions(+), 14 deletions(-) delete mode 100644 yarn.lock diff --git a/superset/assets/package.json b/superset/assets/package.json index c148f42839f43..52508e01faf8d 100644 --- a/superset/assets/package.json +++ b/superset/assets/package.json @@ -71,6 +71,7 @@ "immutable": "^3.8.2", "jed": "^1.1.1", "jquery": "3.1.1", + "json-bigint": "^0.3.0", "lodash.throttle": "^4.1.1", "mapbox-gl": "^0.45.0", "mathjs": "^3.20.2", diff --git a/superset/assets/spec/javascripts/sqllab/actions_spec.js b/superset/assets/spec/javascripts/sqllab/actions_spec.js index 5909ca8241c25..c3d4aa275792a 100644 --- a/superset/assets/spec/javascripts/sqllab/actions_spec.js +++ b/superset/assets/spec/javascripts/sqllab/actions_spec.js @@ -56,7 +56,7 @@ describe('async actions', () => { }); it('calls querySuccess on ajax success', () => { - ajaxStub.yieldsTo('success', { data: '' }); + ajaxStub.yieldsTo('success', '{ "data": "" }'); makeRequest(); expect(dispatch.callCount).to.equal(2); expect(dispatch.getCall(1).args[0].type).to.equal(actions.QUERY_SUCCESS); @@ -86,13 +86,6 @@ describe('async actions', () => { expect(dispatch.args[0][0].type).to.equal(actions.START_QUERY); }); - it('calls querySuccess on ajax success', () => { - ajaxStub.yieldsTo('success', { data: '' }); - makeRequest(); - expect(dispatch.callCount).to.equal(2); - expect(dispatch.getCall(1).args[0].type).to.equal(actions.QUERY_SUCCESS); - }); - it('calls queryFailed on ajax error', () => { ajaxStub.yieldsTo('error', { responseJSON: { error: 'error text' } }); makeRequest(); diff --git a/superset/assets/src/SqlLab/actions.js b/superset/assets/src/SqlLab/actions.js index efd4b97dd8620..81bd91356db7f 100644 --- a/superset/assets/src/SqlLab/actions.js +++ b/superset/assets/src/SqlLab/actions.js @@ -2,6 +2,8 @@ /* eslint no-undef: 2 */ import $ from 'jquery'; import shortid from 'shortid'; +import JSONbig from 'json-bigint'; + import { now } from '../modules/dates'; import { t } from '../locales'; import { @@ -125,10 +127,11 @@ export function fetchQueryResults(query) { const sqlJsonUrl = `/superset/results/${query.resultsKey}/`; $.ajax({ type: 'GET', - dataType: 'json', + dataType: 'text', url: sqlJsonUrl, success(results) { - dispatch(querySuccess(query, results)); + const parsedResults = JSONbig.parse(results); + dispatch(querySuccess(query, parsedResults)); }, error(err) { let msg = t('Failed at retrieving results from the results backend'); diff --git a/superset/assets/yarn.lock b/superset/assets/yarn.lock index efae1cd8ce99b..15d0e053d1a84 100644 --- a/superset/assets/yarn.lock +++ b/superset/assets/yarn.lock @@ -2045,6 +2045,14 @@ big.js@^3.1.3: version "3.2.0" resolved "https://registry.yarnpkg.com/big.js/-/big.js-3.2.0.tgz#a5fc298b81b9e0dca2e458824784b65c52ba588e" +bignumber.js@^2.1.0: + version "2.4.0" + resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-2.4.0.tgz#838a992da9f9d737e0f4b2db0be62bb09dd0c5e8" + +bignumber.js@^7.0.0: + version "7.2.1" + resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-7.2.1.tgz#80c048759d826800807c4bfd521e50edbba57a5f" + binary-extensions@^1.0.0: version "1.11.0" resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.11.0.tgz#46aa1751fb6a2f93ee5e689bb1087d4b14c6c205" @@ -6004,6 +6012,12 @@ jsesc@~0.5.0: version "0.5.0" resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d" +json-bigint@^0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/json-bigint/-/json-bigint-0.3.0.tgz#0ccd912c4b8270d05f056fbd13814b53d3825b1e" + dependencies: + bignumber.js "^7.0.0" + json-buffer@3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/json-buffer/-/json-buffer-3.0.0.tgz#5b1f397afc75d677bde8bcfc0e47e1f9a3d9a898" diff --git a/yarn.lock b/yarn.lock deleted file mode 100644 index fb57ccd13afbd..0000000000000 --- a/yarn.lock +++ /dev/null @@ -1,4 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - -