Преглед на файлове

HUE-2070 [metastore] Improve guess of numeric data types

Added support for all kinds of ints and doubles too
Enrico Berti преди 11 години
родител
ревизия
4196369294
променени са 1 файла, в които са добавени 33 реда и са изтрити 2 реда
  1. 33 2
      apps/beeswax/src/beeswax/templates/define_columns.mako

+ 33 - 2
apps/beeswax/src/beeswax/templates/define_columns.mako

@@ -323,11 +323,42 @@ ${ layout.metastore_menubar() }
         if ($.isNumeric(_val)) {
           if (isInt(_val)) {
             // it's an int
-            _foundType = "int";
+            try {
+              // try to detect the size of the int
+              var _bytes = Math.ceil((Math.log(_val)/Math.log(2))/8);
+              switch (_bytes){
+                case 1:
+                  _foundType = "tinyint";
+                  break;
+                case 2:
+                  _foundType = "smallint";
+                  break;
+                case 3:
+                case 4:
+                  _foundType = "int";
+                  break;
+                default:
+                  _foundType = "bigint";
+                  break;
+              }
+            }
+            catch (e){
+              _foundType = "int";
+            }
           }
           else {
             // it's possibly a float
-            _foundType = "float";
+            try {
+              _foundType = "float";
+              // try to detect the size of the int
+              var _bytes = Math.ceil((Math.log(_val)/Math.log(2))/8);
+              if (_bytes > 4){
+                _foundType = "double";
+              }
+            }
+            catch (e){
+              _foundType = "float";
+            }
           }
         }
         else {