From 951302bcd1c2426b32ffc225d45fb4270dbe9bfc Mon Sep 17 00:00:00 2001 From: kangkaisen Date: Sat, 7 Jan 2017 15:34:57 +0800 Subject: [PATCH] KYLIN-2308 Allow user to set more columnFamily in web --- webapp/app/js/controllers/cubeAdvanceSetting.js | 75 +++++++++++++++++- webapp/app/js/controllers/cubeEdit.js | 51 ------------ webapp/app/js/controllers/cubeSchema.js | 13 +++ webapp/app/js/filters/filter.js | 22 ++++-- .../partials/cubeDesigner/advanced_settings.html | 92 +++++++++++++++++++++- 5 files changed, 194 insertions(+), 59 deletions(-) diff --git a/webapp/app/js/controllers/cubeAdvanceSetting.js b/webapp/app/js/controllers/cubeAdvanceSetting.js index 760133a..39d36b0 100644 --- a/webapp/app/js/controllers/cubeAdvanceSetting.js +++ b/webapp/app/js/controllers/cubeAdvanceSetting.js @@ -278,11 +278,84 @@ KylinApp.controller('CubeAdvanceSettingCtrl', function ($scope, $modal,cubeConfi $scope.isReuse=!$scope.isReuse; } - $scope.removeDictionaries = function(arr,element){ + $scope.removeElement = function(arr,element){ var index = arr.indexOf(element); if (index > -1) { arr.splice(index, 1); } }; + $scope.newColFamily = function (index) { + return { + "name": "F" + index, + "columns": [ + { + "qualifier": "M", + "measure_refs": [] + } + ] + }; + }; + + $scope.initColumnFamily = function () { + $scope.cubeMetaFrame.hbase_mapping.column_family = []; + var normalMeasures = [], distinctCountMeasures = []; + angular.forEach($scope.cubeMetaFrame.measures, function (measure, index) { + if (measure.function.expression === 'COUNT_DISTINCT') { + distinctCountMeasures.push(measure); + } else { + normalMeasures.push(measure); + } + }); + if (normalMeasures.length > 0) { + var nmcf = $scope.newColFamily(1); + angular.forEach(normalMeasures, function (normalM, index) { + nmcf.columns[0].measure_refs.push(normalM.name); + }); + $scope.cubeMetaFrame.hbase_mapping.column_family.push(nmcf); + } + + if (distinctCountMeasures.length > 0) { + var dccf = $scope.newColFamily(2); + angular.forEach(distinctCountMeasures, function (dcm, index) { + dccf.columns[0].measure_refs.push(dcm.name); + }); + $scope.cubeMetaFrame.hbase_mapping.column_family.push(dccf); + } + }; + + $scope.getAllMeasureNames = function () { + var measures = []; + angular.forEach($scope.cubeMetaFrame.measures, function (measure, index) { + measures.push(measure.name); + }); + return measures; + }; + + $scope.getAssignedMeasureNames = function () { + var assignedMeasures = []; + angular.forEach($scope.cubeMetaFrame.hbase_mapping.column_family, function (colFamily, index) { + angular.forEach(colFamily.columns[0].measure_refs, function (measure, index) { + assignedMeasures.push(measure); + }); + }); + return assignedMeasures; + }; + + if ($scope.getAllMeasureNames().length != $scope.getAssignedMeasureNames().length) { + $scope.initColumnFamily(); + } + + + $scope.addColumnFamily = function () { + var colFamily = $scope.newColFamily($scope.cubeMetaFrame.hbase_mapping.column_family.length + 1); + $scope.cubeMetaFrame.hbase_mapping.column_family.push(colFamily); + }; + + $scope.refreshColumnFamily = function (column_familys, index, colFamily) { + if (column_familys) { + column_familys[index] = colFamily; + } + }; + }); diff --git a/webapp/app/js/controllers/cubeEdit.js b/webapp/app/js/controllers/cubeEdit.js index edbb421..da19b22 100755 --- a/webapp/app/js/controllers/cubeEdit.js +++ b/webapp/app/js/controllers/cubeEdit.js @@ -284,25 +284,6 @@ KylinApp.controller('CubeEditCtrl', function ($scope, $q, $routeParams, $locatio return type; }; - var ColFamily = function () { - var index = 1; - return function () { - var newColFamily = - { - "name": "f" + index, - "columns": [ - { - "qualifier": "m", - "measure_refs": [] - } - ] - }; - index += 1; - - return newColFamily; - } - }; - // ~ Define data $scope.state = { @@ -380,8 +361,6 @@ KylinApp.controller('CubeEditCtrl', function ($scope, $q, $routeParams, $locatio $scope.prepareCube = function () { - //generate column family - generateColumnFamily(); //generate rowkey reGenerateRowKey(); @@ -793,36 +772,6 @@ KylinApp.controller('CubeEditCtrl', function ($scope, $q, $routeParams, $locatio return groups; } - - // ~ private methods - function generateColumnFamily() { - $scope.cubeMetaFrame.hbase_mapping.column_family = []; - var colFamily = ColFamily(); - var normalMeasures = [], distinctCountMeasures = []; - angular.forEach($scope.cubeMetaFrame.measures, function (measure, index) { - if (measure.function.expression === 'COUNT_DISTINCT') { - distinctCountMeasures.push(measure); - } else { - normalMeasures.push(measure); - } - }); - if (normalMeasures.length > 0) { - var nmcf = colFamily(); - angular.forEach(normalMeasures, function (normalM, index) { - nmcf.columns[0].measure_refs.push(normalM.name); - }); - $scope.cubeMetaFrame.hbase_mapping.column_family.push(nmcf); - } - - if (distinctCountMeasures.length > 0) { - var dccf = colFamily(); - angular.forEach(distinctCountMeasures, function (dcm, index) { - dccf.columns[0].measure_refs.push(dcm.name); - }); - $scope.cubeMetaFrame.hbase_mapping.column_family.push(dccf); - } - } - $scope.$watch('projectModel.selectedProject', function (newValue, oldValue) { if(!$scope.projectModel.getSelectedProject()) { return; diff --git a/webapp/app/js/controllers/cubeSchema.js b/webapp/app/js/controllers/cubeSchema.js index af8ee7c..17371f2 100755 --- a/webapp/app/js/controllers/cubeSchema.js +++ b/webapp/app/js/controllers/cubeSchema.js @@ -275,6 +275,19 @@ KylinApp.controller('CubeSchemaCtrl', function ($scope, QueryService, UserServic errors.push("At most one 'shard by' column is allowed."); } + var cfMeasures = []; + angular.forEach($scope.cubeMetaFrame.hbase_mapping.column_family,function(cf){ + angular.forEach(cf.columns[0].measure_refs, function (measure, index) { + cfMeasures.push(measure); + }); + }); + + var uniqCfMeasures = _.uniq(cfMeasures); + if(uniqCfMeasures.length != $scope.cubeMetaFrame.measures.length) { + errors.push("All measures need to be assigned to column family"); + } + + var errorInfo = ""; angular.forEach(errors,function(item){ errorInfo+="\n"+item; diff --git a/webapp/app/js/filters/filter.js b/webapp/app/js/filters/filter.js index aff4e3a..d097075 100755 --- a/webapp/app/js/filters/filter.js +++ b/webapp/app/js/filters/filter.js @@ -193,16 +193,26 @@ KylinApp }).filter('inDimNotInMea', function ($filter) { return function (inputArr, table, arr) { var out=[]; - angular.forEach(arr,function(item){ - if(item.table==table){ - angular.forEach(inputArr,function(inputItem){ - if(item.columns.indexOf(inputItem.name)==-1){ + angular.forEach(arr,function(item) { + if (item.table == table) { + angular.forEach(inputArr, function (inputItem) { + if (item.columns.indexOf(inputItem.name) == -1) { out.push(inputItem); } }); } }); + } + }).filter('assignedMeasureNames', function ($filter) { + //return the measures that haven't assign to column family + return function (inputArr, assignedArr) { + var out = []; + angular.forEach(inputArr, function (inputItem) { + if (assignedArr.indexOf(inputItem) == -1) { + out.push(inputItem); + } + }); return out; } - }) - ; + }); + diff --git a/webapp/app/partials/cubeDesigner/advanced_settings.html b/webapp/app/partials/cubeDesigner/advanced_settings.html index f9e422c..bf95256 100755 --- a/webapp/app/partials/cubeDesigner/advanced_settings.html +++ b/webapp/app/partials/cubeDesigner/advanced_settings.html @@ -302,7 +302,7 @@ - @@ -388,6 +388,89 @@ + + +
+

Advanced ColumnFamily

+
+
+ +
+ + + + + + + + + + + + + + + +
CFMeasures
+ {{colFamily.name}} + + {{colFamily.columns[0].measure_refs}} +
+
+ + +
+ + + + + + + + + + + + + + + + +
CFMeasuresActions
+ {{colFamily.name}} + + + {{$item}} + + {{measure}} + + + + + +
+
+ +
+ +
+ +
+
+
@@ -419,3 +502,10 @@

Special settings for dictionaries. Leave blank by default.

+ + -- 2.10.1 (Apple Git-78)