KYLIN-2081 support embeded streaming message Signed-off-by: Jason <jiat...@163.com>
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/b4329a66 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/b4329a66 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/b4329a66 Branch: refs/heads/KYLIN-1971 Commit: b4329a66a4d368c653cd95e9a859305e6a77fc33 Parents: 37ad942 Author: luguosheng <550175...@qq.com> Authored: Wed Oct 19 16:52:41 2016 +0800 Committer: Jason <jiat...@163.com> Committed: Thu Oct 20 14:12:14 2016 +0800 ---------------------------------------------------------------------- webapp/app/js/controllers/sourceMeta.js | 90 ++++++++++++++++++---------- 1 file changed, 57 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/b4329a66/webapp/app/js/controllers/sourceMeta.js ---------------------------------------------------------------------- diff --git a/webapp/app/js/controllers/sourceMeta.js b/webapp/app/js/controllers/sourceMeta.js index 3bbdfc0..dc3c421 100755 --- a/webapp/app/js/controllers/sourceMeta.js +++ b/webapp/app/js/controllers/sourceMeta.js @@ -660,47 +660,71 @@ KylinApp return; } $scope.table.sourceValid = true; - var columnList = []; - for (var key in $scope.streaming.parseResult) { - var defaultType="varchar(256)"; - var _value = $scope.streaming.parseResult[key]; - var defaultChecked = "Y"; - if(typeof _value ==="string"){ - defaultType="varchar(256)"; - }else if(typeof _value ==="number"){ - if(_value <= 2147483647){ - if(_value.toString().indexOf(".")!=-1){ - defaultType="decimal"; - }else{ + + //streaming table data change structure + var columnList=[] + function changeObjTree(obj,base){ + base=base?base+"_":""; + for(var i in obj){ + if(Object.prototype.toString.call(obj[i])=="[object Object]"){ + changeObjTree(obj[i],base+i); + continue; + } + columnList.push(createNewObj(base+i,obj[i])); + } + } + + function checkValType(val,key){ + var defaultType; + if(typeof val ==="number"){ + if(/id/i.test(key)&&val.toString().indexOf(".")==-1){ defaultType="int"; + }else if(val <= 2147483647){ + if(val.toString().indexOf(".")!=-1){ + defaultType="decimal"; + }else{ + defaultType="int"; + } + }else{ + defaultType="timestamp"; } - }else{ - defaultType="timestamp"; - } + }else if(typeof val ==="string"){ + if(!isNaN((new Date(val)).getFullYear())&&typeof ((new Date(val)).getFullYear())==="number"){ + defaultType="date"; + }else{ + defaultType="varchar(256)"; + } + }else if(Object.prototype.toString.call(val)=="[object Array]"){ + defaultType="varchar(256)"; + }else if (typeof val ==="boolean"){ + defaultType="boolean"; } - if(defaultType=="timestamp"){ - defaultChecked = "N"; + return defaultType; + } + + function createNewObj(key,val){ + var obj={}; + obj.name=key; + obj.type=checkValType(val,key); + obj.fromSource="Y"; + obj.checked="Y"; + if(Object.prototype.toString.call(val)=="[object Array]"){ + obj.checked="N"; } + return obj; + } + changeObjTree($scope.streaming.parseResult); + var timeMeasure = $scope.cubeConfig.streamingAutoGenerateMeasure; + for(var i = 0;i<timeMeasure.length;i++){ + var defaultCheck = 'Y'; columnList.push({ - 'name': key, - 'checked': defaultChecked, - 'type': defaultType, - 'fromSource':'Y' + 'name': timeMeasure[i].name, + 'checked': defaultCheck, + 'type': timeMeasure[i].type, + 'fromSource':'N' }); - } - var timeMeasure = $scope.cubeConfig.streamingAutoGenerateMeasure; - for(var i = 0;i<timeMeasure.length;i++){ - var defaultCheck = 'Y'; - columnList.push({ - 'name': timeMeasure[i].name, - 'checked': defaultCheck, - 'type': timeMeasure[i].type, - 'fromSource':'N' - }); - } - var firstCommit = false; if($scope.columnList.length==0){ firstCommit = true;