Repository: zeppelin Updated Branches: refs/heads/master 0c3260e91 -> c1c1aa892
[Zeppelin-3224] - Fix "ultimate" visualization ### What is this PR for? This PR fixes problems with incorrect data visualization using "ultimate". With certain aggregations, the data was not displayed. Also PR improves sorting by columns / rows, before PR it compared by Unicode encoding, but now if there are only numeric data on the axis, sorting will be by values. ### What type of PR is it? [Bug Fix & Improvement] ### What is the Jira issue? [ZEPPELIN-3224](https://issues.apache.org/jira/browse/ZEPPELIN-3224) ### Screenshots (if appropriate) **Error:** ![error](https://user-images.githubusercontent.com/30798933/37035027-3ca6022c-215c-11e8-901c-d33e833ad505.PNG) **Now:** ![default](https://user-images.githubusercontent.com/30798933/37038600-48482d8a-2166-11e8-87cd-d0cb861441d2.PNG) ### Questions: * Does the licenses files need update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Author: Savalek <def...@mail.ru> Author: tinkoff-dwh <tinkoff....@gmail.com> Closes #2841 from Savalek/ZEPPELIN-3224 and squashes the following commits: f546b457c [Savalek] fix count of arguments in parseFloat function a56ea59d9 [Savalek] Improved number check 5c866b183 [tinkoff-dwh] small fix e7d1cd7cc [tinkoff-dwh] Merge branch 'master' into ZEPPELIN-3224 d4b2a4913 [Savalek] add test 17d3f8d0e [Savalek] add tests for sortWithNumberSupport() dc78f3d2b [Savalek] code style fix ba7a6e3e4 [tinkoff-dwh] Merge branch 'master' into ZEPPELIN-3224 9583f2cce [Savalek] small fix eab5d86d2 [Savalek] Merge branch 'master' into ZEPPELIN-3224 33676b468 [Savalek] fix XY legend sort for numbers 94026be39 [Savalek] fix graph display Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/c1c1aa89 Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/c1c1aa89 Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/c1c1aa89 Branch: refs/heads/master Commit: c1c1aa892dbd7621815c19a9d72b175a330ee51e Parents: 0c3260e Author: Savalek <def...@mail.ru> Authored: Fri Apr 6 11:58:50 2018 +0300 Committer: Lee moon soo <m...@apache.org> Committed: Wed May 2 15:32:53 2018 -0400 ---------------------------------------------------------------------- .../tabledata/advanced-transformation-util.js | 38 +++++++++++++------- .../advanced-transformation-util.test.js | 37 +++++++++++++++++++ zeppelin-web/src/app/tabledata/tabledata.js | 4 +++ 3 files changed, 67 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/c1c1aa89/zeppelin-web/src/app/tabledata/advanced-transformation-util.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/tabledata/advanced-transformation-util.js b/zeppelin-web/src/app/tabledata/advanced-transformation-util.js index 97c1b2c..71ed7b8 100644 --- a/zeppelin-web/src/app/tabledata/advanced-transformation-util.js +++ b/zeppelin-web/src/app/tabledata/advanced-transformation-util.js @@ -771,7 +771,7 @@ export function getKGACube(rows, keyColumns, groupColumns, aggrColumns) { cube = {[mergedGroupColumnName]: cube}; keyNames = [mergedGroupColumnName]; } else { - keyNames = Object.keys(cube).sort(); /** keys should be sorted */ + keyNames = sortWithNumberSupport(Object.keys(cube)); /** keys should be sorted */ } return { @@ -883,7 +883,7 @@ export function getKAGCube(rows, keyColumns, groupColumns, aggrColumns) { cube = {[mergedGroupColumnName]: cube}; keyNames = [mergedGroupColumnName]; } else { - keyNames = Object.keys(cube).sort(); /** keys should be sorted */ + keyNames = sortWithNumberSupport(Object.keys(cube)); /** keys should be sorted */ } return { @@ -1015,8 +1015,8 @@ export function getKKGACube(rows, key1Columns, key2Columns, groupColumns, aggrCo } /** end loop for aggrColumns */ } - let key1Names = Object.keys(key1NameSet).sort(); /** keys should be sorted */ - let key2Names = Object.keys(key2NameSet).sort(); /** keys should be sorted */ + let key1Names = sortWithNumberSupport(Object.keys(key1NameSet)); /** keys should be sorted */ + let key2Names = sortWithNumberSupport(Object.keys(key2NameSet)); /** keys should be sorted */ return { cube: cube, @@ -1072,7 +1072,7 @@ export function getNameWithIndex(names) { export function getArrayRowsFromKKGACube(cube, schema, aggregatorColumns, key1Names, key2Names, groupNameSet, selectorNameWithIndex) { - const sortedSelectors = Object.keys(selectorNameWithIndex).sort(); + const sortedSelectors = sortWithNumberSupport(Object.keys(selectorNameWithIndex)); const sortedSelectorNameWithIndex = getNameWithIndex(sortedSelectors); const selectorRows = new Array(sortedSelectors.length); @@ -1087,7 +1087,7 @@ export function getArrayRowsFromKKGACube(cube, schema, aggregatorColumns, key1NameWithIndex: key1NameWithIndex, key2NameWithIndex: key2NameWithIndex, transformed: selectorRows, - groupNames: Array.from(groupNameSet).sort(), + groupNames: sortWithNumberSupport(Array.from(groupNameSet)), sortedSelectors: sortedSelectors, }; } @@ -1167,7 +1167,7 @@ export function fillSelectorRows(schema, cube, selectorRows, export function getArrayRowsFromKGACube(cube, schema, aggregatorColumns, keyColumnName, keyNames, groupNameSet, selectorNameWithIndex) { - const sortedSelectors = Object.keys(selectorNameWithIndex).sort(); + const sortedSelectors = sortWithNumberSupport(Object.keys(selectorNameWithIndex)); const sortedSelectorNameWithIndex = getNameWithIndex(sortedSelectors); const keyArrowRows = new Array(sortedSelectors.length); @@ -1184,7 +1184,7 @@ export function getArrayRowsFromKGACube(cube, schema, aggregatorColumns, return { transformed: keyArrowRows, - groupNames: Array.from(groupNameSet).sort(), + groupNames: sortWithNumberSupport(Array.from(groupNameSet)), sortedSelectors: sortedSelectors, }; } @@ -1244,8 +1244,8 @@ export function getObjectRowsFromKGACube(cube, schema, aggregatorColumns, return { transformed: rows, - sortedSelectors: Object.keys(selectorNameWithIndex).sort(), - groupNames: Array.from(groupNameSet).sort(), + sortedSelectors: sortWithNumberSupport(Object.keys(selectorNameWithIndex)), + groupNames: sortWithNumberSupport(Array.from(groupNameSet)), }; } @@ -1289,12 +1289,12 @@ export function getObjectRow(schema, aggrColumns, obj, groupNameSet) { export function getDrilldownRowsFromKAGCube(cube, schema, aggregatorColumns, keyColumnName, keyNames, groupNameSet, selectorNameWithIndex) { - const sortedSelectors = Object.keys(selectorNameWithIndex).sort(); + const sortedSelectors = sortWithNumberSupport(Object.keys(selectorNameWithIndex)); const sortedSelectorNameWithIndex = getNameWithIndex(sortedSelectors); const rows = new Array(sortedSelectors.length); - const groupNames = Array.from(groupNameSet).sort(); + const groupNames = sortWithNumberSupport(Array.from(groupNameSet)); keyNames.map((key) => { const obj = cube[key]; @@ -1339,3 +1339,17 @@ export function fillDrillDownRow(schema, obj, rows, key, rows[selectorIndex] = row; } } + +export function sortWithNumberSupport(arr) { + let isNumeric = function(n) { + return !isNaN(parseFloat(n)) && isFinite(n); + }; + + if (arr.every(isNumeric)) { + return arr.sort(function(a, b) { + return parseFloat(a) - parseFloat(b); + }); + } else { + return arr.sort(); + } +} http://git-wip-us.apache.org/repos/asf/zeppelin/blob/c1c1aa89/zeppelin-web/src/app/tabledata/advanced-transformation-util.test.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/tabledata/advanced-transformation-util.test.js b/zeppelin-web/src/app/tabledata/advanced-transformation-util.test.js index 84ea441..28ce67d 100644 --- a/zeppelin-web/src/app/tabledata/advanced-transformation-util.test.js +++ b/zeppelin-web/src/app/tabledata/advanced-transformation-util.test.js @@ -1737,5 +1737,42 @@ describe('advanced-transformation-util', () => { ]); }); }); // end: describe('method: array:2-key') + + describe('sortWithNumberSupport() check', () => { + it('sorting a positive numeric array', () => { + let positive = [5, 4, 9, 8, 3, 1, 7, 2, 6]; + let sortedArray = [1, 2, 3, 4, 5, 6, 7, 8, 9]; + let testArr = Util.sortWithNumberSupport(positive); + expect(testArr).toEqual(sortedArray); + }); + + it('sorting a negative numeric array', () => { + let negative = [-5, -4, -9, -8, -3, -1, -7, -2, -6]; + let sortedArray = [-9, -8, -7, -6, -5, -4, -3, -2, -1]; + let testArr = Util.sortWithNumberSupport(negative); + expect(testArr).toEqual(sortedArray); + }); + + it('sorting a mixed numeric array', () => { + let mixed = [5, -4, 9, -8, 3, 1, 7, -2, -6]; + let sortedArray = [-8, -6, -4, -2, 1, 3, 5, 7, 9]; + let testArr = Util.sortWithNumberSupport(mixed); + expect(testArr).toEqual(sortedArray); + }); + + it('checking sorting by value (not by unicode\'s encoding)', () => { + let long = [2, 3, 1, 4, 9999, 30, 33, 20, 27, 42, 26, 58, 73, 99, 21, 122]; + let sortedArray = [1, 2, 3, 4, 20, 21, 26, 27, 30, 33, 42, 58, 73, 99, 122, 9999]; + let testArr = Util.sortWithNumberSupport(long); + expect(testArr).toEqual(sortedArray); + }); + + it('sorting a string array', () => { + let strings = ['34', '77', '5', '65', '7', '23', '88', '-45']; + let sortedArray = ['-45', '5', '7', '23', '34', '65', '77', '88']; + let testArr = Util.sortWithNumberSupport(strings); + expect(testArr).toEqual(sortedArray); + }); + }); }); // end: describe('getTransformer') }); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/c1c1aa89/zeppelin-web/src/app/tabledata/tabledata.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/tabledata/tabledata.js b/zeppelin-web/src/app/tabledata/tabledata.js index 745ab17..1f01bca 100644 --- a/zeppelin-web/src/app/tabledata/tabledata.js +++ b/zeppelin-web/src/app/tabledata/tabledata.js @@ -59,6 +59,10 @@ export default class TableData extends Dataset { if (i === 0) { columnNames.push({name: col, index: j, aggr: 'sum'}); } else { + let valueOfCol; + if (!isNaN(valueOfCol = parseFloat(col)) && isFinite(col)) { + col = valueOfCol; + } cols.push(col); cols2.push({key: (columnNames[i]) ? columnNames[i].name : undefined, value: col}); }