Repository: zeppelin Updated Branches: refs/heads/master 38ba2d475 -> a82e3ec3a
[ZEPPELIN-3075]Fix unqiue algo for the web side in pivot.js file. ### What is this PR for? unique() algorithm is not correct in pivot.js file. If the input is `[2, 3, 3, 3, 4, 5]` and the output will be `[2, 3, 3, 4, 5]`. The number `3` is still duplicated. ### What type of PR is it? [Bug Fix] ### Todos * [ ] - Task ### What is the Jira issue? https://issues.apache.org/jira/browse/ZEPPELIN-3075 [ZEPPELIN-3075] ### How should this be tested? This is very easy and no need test. ### Screenshots (if appropriate) ### Questions: * Does the licenses files need update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Author: liguohui <[email protected]> Closes #2685 from liguohuicmss/pivot-unqiue-algo and squashes the following commits: 2063175d5 [liguohui] delete the multi empty line ea582d95e [liguohui] delete some spaces at the end of the line 79c763a6b [liguohui] add a empty line 99cf93da9 [liguohui] Revert "Chart field is also draggable and sortable in the 'keys', 'groups' and 'values'" fdde39f52 [liguohui] add unit test for unique algo in pivot.js f99674724 [liguohui] Chart field is also draggable and sortable in the 'keys', 'groups' and 'values' 943e80a96 [liguohui] Fix unqiue algo for the web side in pivot.js file. Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/a82e3ec3 Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/a82e3ec3 Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/a82e3ec3 Branch: refs/heads/master Commit: a82e3ec3a335863a30959cabbc3371169e2c1ce9 Parents: 38ba2d4 Author: liguohui <[email protected]> Authored: Thu Nov 30 15:01:27 2017 +0800 Committer: Lee moon soo <[email protected]> Committed: Thu Dec 7 11:16:14 2017 -0800 ---------------------------------------------------------------------- zeppelin-web/src/app/tabledata/pivot.js | 1 + .../src/app/tabledata/tabledata.test.js | 45 ++++++++++++++++++++ 2 files changed, 46 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/a82e3ec3/zeppelin-web/src/app/tabledata/pivot.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/tabledata/pivot.js b/zeppelin-web/src/app/tabledata/pivot.js index 1c938ea..a0f61b2 100644 --- a/zeppelin-web/src/app/tabledata/pivot.js +++ b/zeppelin-web/src/app/tabledata/pivot.js @@ -89,6 +89,7 @@ export default class PivotTransformation extends Transformation { for (let j = i + 1; j < list.length; j++) { if (angular.equals(list[i], list[j])) { list.splice(j, 1) + j-- } } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/a82e3ec3/zeppelin-web/src/app/tabledata/tabledata.test.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/tabledata/tabledata.test.js b/zeppelin-web/src/app/tabledata/tabledata.test.js index 7e41de4..3de2fa3 100644 --- a/zeppelin-web/src/app/tabledata/tabledata.test.js +++ b/zeppelin-web/src/app/tabledata/tabledata.test.js @@ -13,6 +13,7 @@ */ import TableData from './tabledata.js' +import PivotTransformation from './pivot.js' describe('TableData build', function () { let td @@ -39,3 +40,47 @@ describe('TableData build', function () { expect(td.comment).toBe('hello') }) }) + +describe('PivotTransformation build', function() { + let pt + + beforeEach(function () { + console.log(PivotTransformation) + pt = new PivotTransformation() + }) + + it('check the result of keys, groups and values unique', function() { + // set inited mock data + let config = { + common: { + pivot: { + keys: [{index: 4, name: '4'}, + {index: 3, name: '3'}, + {index: 4, name: '4'}, + {index: 3, name: '3'}, + {index: 3, name: '3'}, + {index: 3, name: '3'}, + {index: 3, name: '3'}, + {index: 5, name: '5'}], + groups: [], + values: [] + } + } + } + pt.tableDataColumns = [ + {index: 1, name: '1'}, + {index: 2, name: '2'}, + {index: 3, name: '3'}, + {index: 4, name: '4'}, + {index: 5, name: '5'}] + + pt.setConfig(config) + + pt.removeUnknown() + + expect(config.common.pivot.keys.length).toBe(3) + expect(config.common.pivot.keys[0].index).toBe(4) + expect(config.common.pivot.keys[1].index).toBe(3) + expect(config.common.pivot.keys[2].index).toBe(5) + }) +})
