فهرست منبع

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 {