KYLIN-1875,refine the alisMap

Signed-off-by: Hongbin Ma <mahong...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/ed413ee3
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/ed413ee3
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/ed413ee3

Branch: refs/heads/master-hbase0.98
Commit: ed413ee34a6f0301b57133ef7b4d45d58fc9f534
Parents: d7ecd6e
Author: luguosheng <550175...@qq.com>
Authored: Mon Feb 20 16:36:53 2017 +0800
Committer: Hongbin Ma <mahong...@apache.org>
Committed: Mon Feb 20 18:29:35 2017 +0800

----------------------------------------------------------------------
 webapp/app/js/controllers/cubeDimensions.js     | 26 +-----
 webapp/app/js/controllers/cubeEdit.js           | 58 ++----------
 webapp/app/js/controllers/cubeSchema.js         | 94 +++++++++++++++++++-
 webapp/app/js/model/modelsManager.js            |  8 ++
 .../app/partials/cubeDesigner/dimensions.html   |  6 +-
 5 files changed, 112 insertions(+), 80 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/ed413ee3/webapp/app/js/controllers/cubeDimensions.js
----------------------------------------------------------------------
diff --git a/webapp/app/js/controllers/cubeDimensions.js 
b/webapp/app/js/controllers/cubeDimensions.js
index 80d54bb..44739ac 100644
--- a/webapp/app/js/controllers/cubeDimensions.js
+++ b/webapp/app/js/controllers/cubeDimensions.js
@@ -52,19 +52,6 @@ KylinApp.controller('CubeDimensionsCtrl', function ($scope, 
$modal,MetaModel,cub
 
         var rootFactTable = 
VdmUtil.removeNameSpace($scope.metaModel.model.fact_table);
 
-        if($scope.aliasName.length==0){
-          $scope.aliasName.push(rootFactTable);
-          
$scope.aliasTableMap[rootFactTable]=$scope.metaModel.model.fact_table;
-          
$scope.tableAliasMap[$scope.metaModel.model.fact_table]=rootFactTable;
-          angular.forEach($scope.metaModel.model.lookups,function(joinTable){
-            if(!joinTable.alias){
-              joinTable.alias=VdmUtil.removeNameSpace(joinTable.table);
-            }
-            $scope.aliasTableMap[joinTable.alias]=joinTable.table;
-            $scope.tableAliasMap[joinTable.table]=joinTable.alias;
-            $scope.aliasName.push(joinTable.alias);
-          });
-        }
         // At first dump the columns of fact table.
 
         var cols = $scope.getDimColumnsByAlias(rootFactTable);
@@ -83,17 +70,10 @@ KylinApp.controller('CubeDimensionsCtrl', function ($scope, 
$modal,MetaModel,cub
         $scope.availableColumns[rootFactTable] = cols;
         factSelectAvailable.all=false;
         $scope.selectedColumns[rootFactTable] = factSelectAvailable;
-//        $scope.availableTables.push(rootFactTable);
-        $scope.availableFactTables.push(rootFactTable);
         // Then dump each lookup tables.
         var lookups = $scope.metaModel.model.lookups;
 
         for (var j = 0; j < lookups.length; j++) {
-            if(lookups[j].kind=="FACT"){
-                $scope.availableFactTables.push(lookups[j].alias);
-            }else{
-                $scope.availableLookupTables.push(lookups[j].alias);
-            }
             var cols2 = $scope.getDimColumnsByAlias(lookups[j].alias);
 
             // Initialize selected available.
@@ -380,7 +360,7 @@ KylinApp.controller('CubeDimensionsCtrl', function ($scope, 
$modal,MetaModel,cub
         var selectedCols = $scope.getSelectedCols();
         dimList=[];
         angular.forEach(selectedCols, function (cols, table) {
-            if ($scope.availableFactTables.indexOf(table)!=-1) {
+            if ($scope.modelsManager.availableFactTables.indexOf(table)!=-1) {
                 // Fact table: for each selected column, create one normal 
dimension.
                 for (var i = 0; i < cols.length; i++) {
                     dimList.push(Dimension(cols[i].name, table, [cols[i].col], 
'normal'));
@@ -401,7 +381,7 @@ KylinApp.controller('CubeDimensionsCtrl', function ($scope, 
$modal,MetaModel,cub
     };
 
     $scope.autoChange = function(table,name){
-         if($scope.availableFactTables.indexOf(table)!=-1){
+         if($scope.modelsManager.availableFactTables.indexOf(table)!=-1){
                if($scope.selectedColumns[table][name].selected==false){
                     $scope.selectedColumns[table].all=false;
                }else{
@@ -435,7 +415,7 @@ KylinApp.controller('CubeDimensionsCtrl', function ($scope, 
$modal,MetaModel,cub
     }
 
     $scope.autoChangeAll= function(table){
-         if($scope.availableFactTables.indexOf(table)!=-1){
+         if($scope.modelsManager.availableFactTables.indexOf(table)!=-1){
               if($scope.selectedColumns[table].all==true){
                    angular.forEach($scope.selectedColumns[table],function(col){
                         if(typeof col==="object"){

http://git-wip-us.apache.org/repos/asf/kylin/blob/ed413ee3/webapp/app/js/controllers/cubeEdit.js
----------------------------------------------------------------------
diff --git a/webapp/app/js/controllers/cubeEdit.js 
b/webapp/app/js/controllers/cubeEdit.js
index bc0bceb..92d8305 100755
--- a/webapp/app/js/controllers/cubeEdit.js
+++ b/webapp/app/js/controllers/cubeEdit.js
@@ -23,11 +23,7 @@ KylinApp.controller('CubeEditCtrl', function ($scope, $q, 
$routeParams, $locatio
   $scope.cubeConfig = cubeConfig;
   $scope.metaModel = {};
   $scope.modelsManager = modelsManager;
-  $scope.tableAliasMap=$scope.modelsManager.tableAliasMap;
-  $scope.aliasTableMap=$scope.modelsManager.aliasTableMap;
-  $scope.availableFactTables =$scope.modelsManager.availableFactTables;
-  $scope.availableLookupTables =$scope.modelsManager.availableLookupTables;
-  $scope.aliasName=$scope.modelsManager.aliasName;
+
   //add or edit ?
   var absUrl = $location.absUrl();
   $scope.cubeMode = absUrl.indexOf("/cubes/add") != -1 ? 'addNewCube' : 
absUrl.indexOf("/cubes/edit") != -1 ? 'editExistCube' : 'default';
@@ -86,41 +82,6 @@ KylinApp.controller('CubeEditCtrl', function ($scope, $q, 
$routeParams, $locatio
     $scope.store.supportedEncoding = $scope.cubeConfig.encodings;
   })
 
-  $scope.getDatabaseByColumnName=function(column){
-    return  
VdmUtil.getNameSpaceTopName($scope.aliasTableMap[VdmUtil.getNameSpaceTopName(column)])
-  }
-  $scope.getColumnTypeByAliasName=function(column){
-    return 
TableModel.columnNameTypeMap[$scope.aliasTableMap[VdmUtil.getNameSpaceTopName(column)]+'.'+VdmUtil.removeNameSpace(column)];
-  }
-  $scope.getEncodings =function (name){
-    var filterName=name;
-    var columnType= modelsManager.getColumnTypeByColumnName(filterName);
-    var 
matchList=VdmUtil.getObjValFromLikeKey($scope.store.encodingMaps,columnType);
-    var encodings =$scope.store.supportedEncoding,filterEncoding;
-    if($scope.isEdit){
-      var rowkey_columns=$scope.cubeMetaFrame.rowkey.rowkey_columns;
-      if(rowkey_columns&&filterName){
-        for(var s=0;s<rowkey_columns.length;s++){
-          var 
database=$scope.getDatabaseByColumnName(rowkey_columns[s].column);
-          if(filterName==rowkey_columns[s].column){
-            var version=rowkey_columns[s].encoding_version;
-            var noLenEncoding=rowkey_columns[s].encoding.replace(/:\d+/,"");
-            
filterEncoding=VdmUtil.getFilterObjectListByOrFilterVal(encodings,'value',noLenEncoding+(version?"[v"+version+"]":"[v1]"),'suggest',true)
-            matchList.push(noLenEncoding);
-            
filterEncoding=VdmUtil.getObjectList(filterEncoding,'baseValue',matchList);
-            break;
-          }
-        }
-      }else{
-        
filterEncoding=VdmUtil.getFilterObjectListByOrFilterVal(encodings,'suggest',true);
-        
filterEncoding=VdmUtil.getObjectList(filterEncoding,'baseValue',matchList)
-      }
-    }else{
-      
filterEncoding=VdmUtil.getFilterObjectListByOrFilterVal(encodings,'suggest',true);
-      
filterEncoding=VdmUtil.getObjectList(filterEncoding,'baseValue',matchList)
-    }
-    return filterEncoding;
-  }
   $scope.getColumnsByAlias = function (alias) {
     var temp = [];
     angular.forEach(TableModel.selectProjectTables, function (table) {
@@ -145,7 +106,7 @@ KylinApp.controller('CubeEditCtrl', function ($scope, $q, 
$routeParams, $locatio
     if (!alias) {
       return [];
     }
-    var tableColumns = $scope.getColumnsByAlias(alias);
+    var tableColumns = $scope.modelsManager.getColumnsByAlias(alias);
     var tableDim = _.find($scope.metaModel.model.dimensions, function 
(dimension) {
       return dimension.table == alias
     });
@@ -229,7 +190,7 @@ KylinApp.controller('CubeEditCtrl', function ($scope, $q, 
$routeParams, $locatio
     var me_columns = [];
     //add cube dimension column for specific measure
     angular.forEach($scope.cubeMetaFrame.dimensions,function(dimension,index){
-      if($scope.availableFactTables.indexOf(dimension.table)==-1){
+      
if($scope.modelsManager.availableFactTables.indexOf(dimension.table)==-1){
         return;
       }
       if(dimension.column && dimension.derived == null){
@@ -261,23 +222,14 @@ KylinApp.controller('CubeEditCtrl', function ($scope, $q, 
$routeParams, $locatio
            me_columns.push(measure.function.parameter.value);
          }
     });
-
-    var unique = []
-
-    angular.forEach(me_columns, function (column) {
-        if (unique.indexOf(column) === -1) {
-          unique.push(column);
-        }
-      });
-
-      return unique;
+    return distinct_array(me_columns);
 
   };
 
 
 
   $scope.getColumnType = function (_column, alias) {
-    var columns = $scope.getColumnsByAlias(alias);
+    var columns = $scope.modelsManager.getColumnsByAlias(alias);
     var type;
     angular.forEach(columns, function (column) {
       if (_column === column.name) {

http://git-wip-us.apache.org/repos/asf/kylin/blob/ed413ee3/webapp/app/js/controllers/cubeSchema.js
----------------------------------------------------------------------
diff --git a/webapp/app/js/controllers/cubeSchema.js 
b/webapp/app/js/controllers/cubeSchema.js
index 6aeea3c..91a1567 100755
--- a/webapp/app/js/controllers/cubeSchema.js
+++ b/webapp/app/js/controllers/cubeSchema.js
@@ -18,7 +18,7 @@
 
 'use strict';
 
-KylinApp.controller('CubeSchemaCtrl', function ($scope, QueryService, 
UserService,modelsManager, ProjectService, 
AuthenticationService,$filter,ModelService,MetaModel,CubeDescModel,CubeList,TableModel,ProjectModel,ModelDescService,SweetAlert,cubesManager,StreamingService,CubeService)
 {
+KylinApp.controller('CubeSchemaCtrl', function ($scope, QueryService, 
UserService,modelsManager, ProjectService, 
AuthenticationService,$filter,ModelService,MetaModel,CubeDescModel,CubeList,TableModel,ProjectModel,ModelDescService,SweetAlert,cubesManager,StreamingService,CubeService,VdmUtil)
 {
     $scope.modelsManager = modelsManager;
     $scope.cubesManager = cubesManager;
     $scope.projects = [];
@@ -37,6 +37,98 @@ KylinApp.controller('CubeSchemaCtrl', function ($scope, 
QueryService, UserServic
 
     $scope.curStep = $scope.wizardSteps[0];
 
+  $scope.getTypeVersion=function(typename){
+    var searchResult=/\[v(\d+)\]/.exec(typename);
+    if(searchResult&&searchResult.length){
+      return searchResult.length&&searchResult[1]||1;
+    }else{
+      return 1;
+    }
+  }
+  $scope.removeVersion=function(typename){
+    if(typename){
+      return typename.replace(/\[v\d+\]/g,"").replace(/\s+/g,'');
+    }
+    return "";
+  }
+
+  //init encoding list
+  $scope.store = {
+    supportedEncoding:[],
+    encodingMaps:{}
+  }
+  TableModel.getColumnTypeEncodingMap().then(function(data){
+    $scope.store.encodingMaps=data;
+  });
+  CubeService.getValidEncodings({}, function (encodings) {
+    if(encodings){
+      for(var i in encodings)
+        if(VdmUtil.isNotExtraKey(encodings,i)){
+          var value = i
+          var name = value;
+          var typeVersion=+encodings[i]||1;
+          var suggest=false,selecttips='';
+          if(/\d+/.test(""+typeVersion)&&typeVersion>=1){
+            for(var s=1;s<=typeVersion;s++){
+              if(s==typeVersion){
+                suggest=true;
+              }
+              if(value=="int"){
+                name = "int (deprecated)";
+                suggest=false;
+              }
+              if(typeVersion>1){
+                selecttips="(v"+s;
+                if(s==typeVersion){
+                  selecttips=",suggest)"
+                }
+                selecttips=')';
+              }
+              $scope.store.supportedEncoding.push({
+                "name":name+selecttips,
+                "value":value+"[v"+s+"]",
+                "version":typeVersion,
+                "baseValue":value,
+                "suggest":suggest
+              });
+            }
+          }
+        }
+    }
+  },function(e){
+    $scope.store.supportedEncoding = $scope.cubeConfig.encodings;
+  })
+  $scope.getEncodings =function (name){
+    var filterName=name;
+    var columnType= $scope.modelsManager.getColumnTypeByColumnName(filterName);
+    var 
matchList=VdmUtil.getObjValFromLikeKey($scope.store.encodingMaps,columnType);
+    var encodings =$scope.store.supportedEncoding,filterEncoding;
+    if($scope.isEdit){
+      var rowkey_columns=$scope.cubeMetaFrame.rowkey.rowkey_columns;
+      if(rowkey_columns&&filterName){
+        for(var s=0;s<rowkey_columns.length;s++){
+          if(filterName==rowkey_columns[s].column){
+            var version=rowkey_columns[s].encoding_version;
+            var noLenEncoding=rowkey_columns[s].encoding.replace(/:\d+/,"");
+            
filterEncoding=VdmUtil.getFilterObjectListByOrFilterVal(encodings,'value',noLenEncoding+(version?"[v"+version+"]":"[v1]"),'suggest',true)
+            matchList.push(noLenEncoding);
+            
filterEncoding=VdmUtil.getObjectList(filterEncoding,'baseValue',matchList);
+            break;
+          }
+        }
+      }else{
+        
filterEncoding=VdmUtil.getFilterObjectListByOrFilterVal(encodings,'suggest',true);
+        
filterEncoding=VdmUtil.getObjectList(filterEncoding,'baseValue',matchList)
+      }
+    }else{
+      
filterEncoding=VdmUtil.getFilterObjectListByOrFilterVal(encodings,'suggest',true);
+      
filterEncoding=VdmUtil.getObjectList(filterEncoding,'baseValue',matchList)
+    }
+    return filterEncoding;
+  }
+
+
+
     $scope.allCubes = [];
 
     $scope.getTypeVersion=function(typename){

http://git-wip-us.apache.org/repos/asf/kylin/blob/ed413ee3/webapp/app/js/model/modelsManager.js
----------------------------------------------------------------------
diff --git a/webapp/app/js/model/modelsManager.js 
b/webapp/app/js/model/modelsManager.js
index f00f5cc..99a4646 100644
--- a/webapp/app/js/model/modelsManager.js
+++ b/webapp/app/js/model/modelsManager.js
@@ -101,6 +101,11 @@ 
KylinApp.service('modelsManager',function(ModelService,CubeService,$q,AccessServ
 
     this.initAliasMapByModelSchema=function(metaModel){
       var rootFactTable = VdmUtil.removeNameSpace(metaModel.model.fact_table);
+      this.tableAliasMap={};
+      this.aliasTableMap={};
+      this.availableFactTables=[];
+      this.availableLookupTables=[];
+      this.aliasName=[];
       this.availableFactTables.push(rootFactTable);
       this.aliasName.push(rootFactTable);
       this.aliasTableMap[rootFactTable]=metaModel.model.fact_table;
@@ -126,5 +131,8 @@ 
KylinApp.service('modelsManager',function(ModelService,CubeService,$q,AccessServ
     this.getColumnTypeByColumnName=function(column){
       return 
TableModel.columnNameTypeMap[this.aliasTableMap[VdmUtil.getNameSpaceTopName(column)]+'.'+VdmUtil.removeNameSpace(column)];
     }
+    this.getColumnsByAlias=function(alias){
+      return TableModel.getColumnsByTable(this.aliasTableMap[alias]);
+    }
 
 });

http://git-wip-us.apache.org/repos/asf/kylin/blob/ed413ee3/webapp/app/partials/cubeDesigner/dimensions.html
----------------------------------------------------------------------
diff --git a/webapp/app/partials/cubeDesigner/dimensions.html 
b/webapp/app/partials/cubeDesigner/dimensions.html
index b8bd05f..e1833d3 100644
--- a/webapp/app/partials/cubeDesigner/dimensions.html
+++ b/webapp/app/partials/cubeDesigner/dimensions.html
@@ -177,7 +177,7 @@
                             </div>
                         </div>
                     </div>
-                    <div  
ng-if="availableLookupTables.indexOf(newDimension.table)!=-1">
+                    <div  
ng-if="modelsManager.availableLookupTables.indexOf(newDimension.table)!=-1">
                         <div  class="row">
                             <label class="control-label col-xs-12 col-sm-3 
no-padding-right font-color-default">
                                 <b>Type</b>
@@ -217,7 +217,7 @@
                         <div class="box-body">
                           <ul class="list-unstyled columns-region">
                               <!--FactTable-->
-                              <div ng-repeat="table in availableFactTables 
track by $index"   class="panel-default " >
+                              <div ng-repeat="table in 
modelsManager.availableFactTables track by $index"   class="panel-default " >
                                 <h4>{{table}}&nbsp;[FactTable]</h4>
                                 <table class="table table-striped table-hover 
ng-scope">
                                   <tr >
@@ -243,7 +243,7 @@
                                 </table>
                               </div>
                               <!--LookUp Table-->
-                              <div ng-repeat="table in availableLookupTables 
track by $index"  class="panel-default" >
+                              <div ng-repeat="table in 
modelsManager.availableLookupTables track by $index"  class="panel-default" >
                                 <h4>{{table}}&nbsp;[LookupTable]</h4>
                                 <table class="table table-striped table-hover 
ng-scope">
                                   <tr class="row" >

Reply via email to