浏览代码

HUE-1776 [metastore] Support extended Unicode delimiter

Removing 255-possibility delimiter limit.
Romain Rigaux 12 年之前
父节点
当前提交
60d165e

+ 34 - 0
apps/beeswax/src/beeswax/create_table_tests.py

@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+
+from nose.tools import assert_equal, assert_true, assert_raises
+
+from django import forms
+from beeswax.forms import _clean_terminator
+
+
+LOG = logging.getLogger(__name__)
+
+
+class TestCreateTable():
+
+  def test_custom_delimiter(self):
+    # Any thing is good
+    assert_equal('\x01', _clean_terminator('\001'))
+    assert_raises(forms.ValidationError, _clean_terminator, '')

+ 4 - 4
apps/beeswax/src/beeswax/forms.py

@@ -261,8 +261,8 @@ def _clean_tablename(db, name, database='default'):
 
 
 def _clean_terminator(val):
-  if val is not None and len(val.decode('string_escape')) != 1:
-    raise forms.ValidationError(_('Terminator must be exactly one character.'))
+  if val is not None and val == '':
+    raise forms.ValidationError(_('Terminator must not be empty.'))
   return val
 
 
@@ -297,10 +297,10 @@ class CreateByImportDelimForm(forms.Form):
     delimiter = self.cleaned_data.get('delimiter')
     if delimiter.isdigit():
       try:
-        chr(int(delimiter))
+        unichr(int(delimiter))
         return int(delimiter)
       except ValueError:
-        raise forms.ValidationError(_('Delimiter value must be smaller than 256.'))
+        raise forms.ValidationError(_('Delimiter value must be smaller than 65533.'))
     if not delimiter:
       raise forms.ValidationError(_('Delimiter value is required.'))
     _clean_terminator(delimiter)

+ 6 - 6
apps/beeswax/src/beeswax/templates/create_table_manually.mako

@@ -158,7 +158,7 @@ ${ layout.metastore_menubar() }
                         ${comps.bootstrapLabel(table_form["field_terminator"])}
                         <div class="controls">
                             ${comps.field(table_form["field_terminator"], render_default=True)}
-                            <span  class="help-inline error-inline hide">${_('This field is required. Spaces are not allowed. Terminator must be exactly one character.')}</span>
+                            <span  class="help-inline error-inline hide">${_('This field is required. Spaces are not allowed.')}</span>
                             <span class="help-block">
                                 ${_('Enter the column delimiter. Must be a single character. Use syntax like "\\001" or "\\t" for special characters.')}
                             </span>
@@ -168,7 +168,7 @@ ${ layout.metastore_menubar() }
                         ${comps.bootstrapLabel(table_form["collection_terminator"])}
                         <div class="controls">
                             ${comps.field(table_form["collection_terminator"], render_default=True)}
-                            <span  class="help-inline error-inline hide">${_('This field is required. Spaces are not allowed. Terminator must be exactly one character.')}</span>
+                            <span  class="help-inline error-inline hide">${_('This field is required. Spaces are not allowed.')}</span>
                             <span class="help-block">
                                 ${_('Use for array types.')}
                             </span>
@@ -178,7 +178,7 @@ ${ layout.metastore_menubar() }
                         ${comps.bootstrapLabel(table_form["map_key_terminator"])}
                         <div class="controls">
                             ${comps.field(table_form["map_key_terminator"], render_default=True)}
-                            <span  class="help-inline error-inline hide">${_('This field is required. Spaces are not allowed. Terminator must be exactly one character.')}</span>
+                            <span  class="help-inline error-inline hide">${_('This field is required. Spaces are not allowed.')}</span>
                             <span class="help-block">
                                 ${_('Use for map types.')}
                             </span>
@@ -683,7 +683,7 @@ $(document).ready(function () {
     // step 3
     var step3Valid = true;
     var fieldTerminatorFld = $("#id_table-field_terminator_1");
-    if ($("#id_table-field_terminator_0").val() == "__other__" && (!isValid($.trim(fieldTerminatorFld.val())) || $.trim(fieldTerminatorFld.val()).length != 1)) {
+    if ($("#id_table-field_terminator_0").val() == "__other__" && ! isValid($.trim(fieldTerminatorFld.val()))) {
       showFieldError(fieldTerminatorFld);
       step3Valid = false;
     }
@@ -692,7 +692,7 @@ $(document).ready(function () {
     }
 
     var collectionTerminatorFld = $("#id_table-collection_terminator_1");
-    if ($("#id_table-collection_terminator_0").val() == "__other__" && (!isValid($.trim(collectionTerminatorFld.val())) || $.trim(collectionTerminatorFld.val()).length != 1)) {
+    if ($("#id_table-collection_terminator_0").val() == "__other__" && ! isValid($.trim(collectionTerminatorFld.val()))) {
       showFieldError(collectionTerminatorFld);
       step3Valid = false;
     }
@@ -701,7 +701,7 @@ $(document).ready(function () {
     }
 
     var mapKeyTerminatorFld = $("#id_table-map_key_terminator_1");
-    if ($("#id_table-map_key_terminator_0").val() == "__other__" && (!isValid($.trim(mapKeyTerminatorFld.val())) || $.trim(mapKeyTerminatorFld.val()).length != 1)) {
+    if ($("#id_table-map_key_terminator_0").val() == "__other__" && ! isValid($.trim(mapKeyTerminatorFld.val()))) {
       showFieldError(mapKeyTerminatorFld);
       step3Valid = false;
     }