Browse Source

HUE-2684 [metastore] Support for new datatypes when creating tables

Added varchar, char, date type support for creating tables
fixed column-spec forms are not showing after adding/deleting columns.
Daehan Kim 10 years ago
parent
commit
c7d64b6ef0

+ 17 - 2
apps/beeswax/src/beeswax/forms.py

@@ -17,6 +17,8 @@
 
 from django import forms
 from django.utils.translation import ugettext as _, ugettext_lazy as _t
+from django.core.validators import MinValueValidator, MaxValueValidator
+from django.forms import NumberInput
 
 from desktop.lib.django_forms import simple_formset_factory, DependencyAwareForm
 from desktop.lib.django_forms import ChoiceOrOtherField, MultiForm, SubmitButton
@@ -332,9 +334,11 @@ class CreateByImportDelimForm(forms.Form):
 # Note, struct is not currently supported.  (Because it's recursive, for example.)
 HIVE_TYPES = \
     ( "string", "tinyint", "smallint", "int", "bigint", "boolean",
-      "float", "double", "array", "map", "timestamp")
+      "float", "double", "array", "map", "timestamp", "date",
+      "char", "varchar")
 HIVE_PRIMITIVE_TYPES = \
-    ("string", "tinyint", "smallint", "int", "bigint", "boolean", "float", "double", "timestamp")
+    ("string", "tinyint", "smallint", "int", "bigint", "boolean",
+      "float", "double", "timestamp", "date", "char", "varchar")
 
 class PartitionTypeForm(forms.Form):
   column_name = common.HiveIdentifierField(required=True)
@@ -348,6 +352,8 @@ class ColumnTypeForm(DependencyAwareForm):
     ("column_type", "array", "array_type"),
     ("column_type", "map", "map_key_type"),
     ("column_type", "map", "map_value_type"),
+    ("column_type", "char", "char_length"),
+    ("column_type", "varchar", "varchar_length")
   ]
   column_name = common.HiveIdentifierField(label=_t('Column Name'), required=True)
   column_type = forms.ChoiceField(label=_t('Column Type'), required=True,
@@ -360,6 +366,15 @@ class ColumnTypeForm(DependencyAwareForm):
   map_value_type = forms.ChoiceField(required=False,
                                      choices=common.to_choices(HIVE_PRIMITIVE_TYPES),
                                      help_text=_t("Specify if column_type is map."))
+  char_length = forms.IntegerField(required=False, initial=1,
+                                   widget=NumberInput(attrs={'min': 1, 'max': 255}),
+                                   validators=[MinValueValidator(1), MaxValueValidator(255)],
+                                   help_text=_t("Specify if column_type is char"))
+  varchar_length = forms.IntegerField(required=False, initial=1,
+                                      widget=NumberInput(attrs={'min': 1, 'max': 65355}),
+                                      validators=[MinValueValidator(1), MaxValueValidator(65355)],
+                                      help_text=_t("Specify if column_is varchar"))
+
 
 ColumnTypeFormSet = simple_formset_factory(ColumnTypeForm, initial=[{}], add_label=_t("Add a column"))
 # Default to no partitions

+ 34 - 0
apps/beeswax/src/beeswax/templates/create_table_manually.mako

@@ -413,6 +413,29 @@ ${ layout.metastore_menubar() }
                     </div>
                 </div>
         % endif
+        <div class="charSpec hide">
+            <div class="control-group">
+                <label class="control-label">${_('Size')}</label>
+                <div class="controls">
+                ${comps.field(form["char_length"], render_default=True)}
+                    <span class="help-block">
+                    ${_("Length of char value (1~255)")}
+                    </span>
+                </div>
+            </div>
+        </div>
+        <div class="varcharSpec hide">
+            <div class="control-group">
+                <label class="control-label">${_('Size')}</label>
+                <div class="controls">
+                ${comps.field(form["varchar_length"], render_default=True)}
+                    <span class="help-block">
+                    ${_("Length of varchar value (1~65355)")}
+                    </span>
+                </div>
+            </div>
+        </div>
+
     ${unicode(form["_exists"]) | n}
 
     </div>
@@ -615,13 +638,24 @@ $(document).ready(function () {
   $(".columnType").find("select").change(function () {
     $(this).parents(".cnt").find(".arraySpec").hide();
     $(this).parents(".cnt").find(".mapSpec").hide();
+    $(this).parents(".cnt").find(".charSpec").hide();
+    $(this).parents(".cnt").find(".varcharSpec").hide();
+
     if ($(this).val() == "array") {
       $(this).parents(".cnt").find(".arraySpec").show();
     }
     if ($(this).val() == "map") {
       $(this).parents(".cnt").find(".mapSpec").show();
     }
+    if ($(this).val() == "char") {
+      $(this).parents(".cnt").find(".charSpec").show();
+    }
+    if ($(this).val() == "varchar") {
+      $(this).parents(".cnt").find(".varcharSpec").show();
+    }
   });
+  // to show spec forms after clicking "Add a column" button
+  $(".columnType").find("select").trigger("change");
 
   $("#step4").find("ul").addClass("inputs-list");
 

+ 4 - 0
apps/beeswax/src/beeswax/templates/create_table_statement.mako

@@ -26,6 +26,10 @@ def col_type(col):
     return "array <%s>" % col["array_type"]
   elif col["column_type"] == "map":
     return "map <%s, %s>" % (col["map_key_type"], col["map_value_type"])
+  elif col["column_type"] == "char":
+    return "char(%d)" % col["char_length"]
+  elif col["column_type"] == "varchar":
+    return "varchar(%d)" % col["varchar_length"]
   return col["column_type"]
 %>\
 <%def name="column_list(columns)">\