zeppelin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cornead...@apache.org
Subject zeppelin git commit: [ZEPPELIN-1372]Automatically Detect the data type in table and sort the numbers correctly
Date Mon, 05 Sep 2016 06:30:44 GMT
Repository: zeppelin
Updated Branches:
  refs/heads/master d49734866 -> 6c6097a55


[ZEPPELIN-1372]Automatically Detect the data type in table and sort the numbers correctly

### What is this PR for?
Automatically detect the data type for the contents in the table.
This enables the sorting on numerical/date columns.
Please see https://issues.apache.org/jira/browse/ZEPPELIN-1372 for details.

### What type of PR is it?
[Bug Fix | Improvement]

### Todos
* [ ] - Task

### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-1372

### How should this be tested?
Click on the title of columns and see whether the numeric contents are correctly sorted.

### Screenshots (if appropriate)
#### For numbers
Before
![screen shot 2016-08-26 at 1 35 02 pm](https://cloud.githubusercontent.com/assets/3334391/18019657/f6669852-6b91-11e6-9ff6-6bbde68bce20.png)
After
![screen shot 2016-08-26 at 1 34 00 pm](https://cloud.githubusercontent.com/assets/3334391/18019661/fa6dcd8a-6b91-11e6-95ce-339218b53e5a.png)

#### For dates
Before
![screen shot 2016-08-30 at 3 24 02 pm](https://cloud.githubusercontent.com/assets/3334391/18109384/df615a7a-6ec5-11e6-9c8f-6f07f5f56bd4.png)
After
![screen shot 2016-08-30 at 3 11 14 pm](https://cloud.githubusercontent.com/assets/3334391/18109351/9f28c48e-6ec5-11e6-9184-87093fcac5fe.png)

### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No

Author: Peilin Yang <peiliny@twitter.com>

Closes #1371 from Peilin-Yang/ZEPPELIN-1372 and squashes the following commits:

72e470c [Peilin Yang] Merge branch 'master' into ZEPPELIN-1372
0333722 [Peilin Yang] refactor the logic
ab9713d [Peilin Yang] add more constraints to the number
c081f04 [Peilin Yang] switch the type detection of number/date to speed it up
461f00e [Peilin Yang] move the data type parsing at the same time when table data is loaded
7d62eb2 [Peilin Yang] automatic detect the type of the input in table for sorting purpose


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

Branch: refs/heads/master
Commit: 6c6097a55c0fedc7393af799868a9af1d699f46a
Parents: d497348
Author: Peilin Yang <peiliny@twitter.com>
Authored: Thu Sep 1 14:05:40 2016 -0700
Committer: Damien CORNEAU <corneadoug@gmail.com>
Committed: Mon Sep 5 15:30:26 2016 +0900

----------------------------------------------------------------------
 .../notebook/paragraph/paragraph.controller.js  | 24 +++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/6c6097a5/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
index 302d107..bd3b6b3 100644
--- a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
+++ b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
@@ -865,6 +865,21 @@ angular.module('zeppelinWebApp').controller('ParagraphCtrl', function($scope,
$r
     }
   };
 
+  $scope.parseTableCell = function(cell) {
+    if (!isNaN(cell)) {
+      if (cell.length === 0 || Number(cell) > Number.MAX_SAFE_INTEGER || Number(cell)
< Number.MIN_SAFE_INTEGER) {
+        return cell;
+      } else {
+        return Number(cell);
+      }
+    }
+    var d = moment(cell);
+    if (d.isValid()) {
+      return d;
+    }
+    return cell;
+  };
+
   $scope.loadTableData = function(result) {
     if (!result) {
       return;
@@ -898,8 +913,9 @@ angular.module('zeppelinWebApp').controller('ParagraphCtrl', function($scope,
$r
           if (i === 0) {
             columnNames.push({name: col, index: j, aggr: 'sum'});
           } else {
-            cols.push(col);
-            cols2.push({key: (columnNames[i]) ? columnNames[i].name : undefined, value: col});
+            var parsedCol = $scope.parseTableCell(col);
+            cols.push(parsedCol);
+            cols2.push({key: (columnNames[i]) ? columnNames[i].name : undefined, value: parsedCol});
           }
         }
         if (i !== 0) {
@@ -978,7 +994,9 @@ angular.module('zeppelinWebApp').controller('ParagraphCtrl', function($scope,
$r
         cells: function(row, col, prop) {
           var cellProperties = {};
           cellProperties.renderer = function(instance, td, row, col, prop, value, cellProperties)
{
-            if (!isNaN(value)) {
+            if (value instanceof moment) {
+              td.innerHTML = value._i;
+            } else if (!isNaN(value)) {
               cellProperties.format = '0,0.[00000]';
               td.style.textAlign = 'left';
               Handsontable.renderers.NumericRenderer.apply(this, arguments);


Mime
View raw message