Ver Fonte

HUE-1303 [metastore] Create a new table wizard uses CTRL+A

The bad js selector was the cause
Cleanup a bit the view
Romain Rigaux há 12 anos atrás
pai
commit
c4d3023c6d

+ 28 - 49
apps/beeswax/src/beeswax/create_table.py

@@ -110,31 +110,27 @@ def import_wizard(request, database='default'):
   app_name = get_app_name(request)
 
   if request.method == 'POST':
-    # Have a while loop to allow an easy way to break
-    for _ in range(1):
-      #
-      # General processing logic:
-      # - We have 3 steps. Each requires the previous.
-      #   * Step 1      : Table name and file location
-      #   * Step 2a     : Display sample with auto chosen delim
-      #   * Step 2b     : Display sample with user chosen delim (if user chooses one)
-      #   * Step 3      : Display sample, and define columns
-      # - Each step is represented by a different form. The form of an earlier step
-      #   should be present when submitting to a later step.
-      # - To preserve the data from the earlier steps, we send the forms back as
-      #   hidden fields. This way, when users revisit a previous step, the data would
-      #   be there as well.
-      #
-      delim_is_auto = False
-      fields_list, n_cols = [ [] ], 0
-      s3_col_formset = None
-
-      # Everything requires a valid file form
-      db = dbms.get(request.user)
-      s1_file_form = CreateByImportFileForm(request.POST, db=db)
-      if not s1_file_form.is_valid():
-        break
-
+    #
+    # General processing logic:
+    # - We have 3 steps. Each requires the previous.
+    #   * Step 1      : Table name and file location
+    #   * Step 2a     : Display sample with auto chosen delim
+    #   * Step 2b     : Display sample with user chosen delim (if user chooses one)
+    #   * Step 3      : Display sample, and define columns
+    # - Each step is represented by a different form. The form of an earlier step
+    #   should be present when submitting to a later step.
+    # - To preserve the data from the earlier steps, we send the forms back as
+    #   hidden fields. This way, when users revisit a previous step, the data would
+    #   be there as well.
+    #
+    delim_is_auto = False
+    fields_list, n_cols = [[]], 0
+    s3_col_formset = None
+
+    db = dbms.get(request.user)
+    s1_file_form = CreateByImportFileForm(request.POST, db=db)
+
+    if s1_file_form.is_valid():
       do_s2_auto_delim = request.POST.get('submit_file')        # Step 1 -> 2
       do_s2_user_delim = request.POST.get('submit_preview')     # Step 2 -> 2
       do_s3_column_def = request.POST.get('submit_delim')       # Step 2 -> 3
@@ -144,23 +140,15 @@ def import_wizard(request, database='default'):
       cancel_s3_column_def = request.POST.get('cancel_create')  # Step 3 -> 2
 
       # Exactly one of these should be True
-      assert len(filter(None, (do_s2_auto_delim,
-                               do_s2_user_delim,
-                               do_s3_column_def,
-                               do_hive_create,
-                               cancel_s2_user_delim,
-                               cancel_s3_column_def))) == 1, 'Invalid form submission'
+      if len(filter(None, (do_s2_auto_delim, do_s2_user_delim, do_s3_column_def, do_hive_create, cancel_s2_user_delim, cancel_s3_column_def))) != 1:
+        raise PopupException(_('Invalid form submission'))
 
-      #
-      # Fix up what we should do in case any form is invalid
-      #
       if not do_s2_auto_delim:
         # We should have a valid delim form
         s2_delim_form = CreateByImportDelimForm(request.POST)
         if not s2_delim_form.is_valid():
           # Go back to picking delimiter
           do_s2_user_delim, do_s3_column_def, do_hive_create = True, False, False
-
       if do_hive_create:
         # We should have a valid columns formset
         s3_col_formset = ColumnTypeFormSet(prefix='cols', data=request.POST)
@@ -173,21 +161,12 @@ def import_wizard(request, database='default'):
       #
       if do_s2_auto_delim:
         delim_is_auto = True
-        fields_list, n_cols, s2_delim_form = _delim_preview(
-                                              request.fs,
-                                              s1_file_form,
-                                              encoding,
-                                              [ reader.TYPE for reader in FILE_READERS ],
-                                              DELIMITERS)
+        fields_list, n_cols, s2_delim_form = _delim_preview(request.fs, s1_file_form, encoding, [reader.TYPE for reader in FILE_READERS], DELIMITERS)
 
       if (do_s2_user_delim or do_s3_column_def or cancel_s3_column_def) and s2_delim_form.is_valid():
         # Delimit based on input
-        fields_list, n_cols, s2_delim_form = _delim_preview(
-                                              request.fs,
-                                              s1_file_form,
-                                              encoding,
-                                              (s2_delim_form.cleaned_data['file_type'],),
-                                              (s2_delim_form.cleaned_data['delimiter'],))
+        fields_list, n_cols, s2_delim_form = _delim_preview(request.fs, s1_file_form, encoding, (s2_delim_form.cleaned_data['file_type'],),
+                                                            (s2_delim_form.cleaned_data['delimiter'],))
 
       if do_s2_auto_delim or do_s2_user_delim or cancel_s3_column_def:
         return render('choose_delimiter.mako', request, {
@@ -221,11 +200,11 @@ def import_wizard(request, database='default'):
           'column_formset': s3_col_formset,
           'fields_list': fields_list,
           'n_cols': n_cols,
-           'database': database,
+          'database': database,
         })
 
       #
-      # Finale: Execute
+      # Final: Execute
       #
       if do_hive_create:
         delim = s2_delim_form.cleaned_data['delimiter']

+ 8 - 4
apps/beeswax/src/beeswax/templates/define_columns.mako

@@ -46,8 +46,8 @@ ${layout.menubar(section='tables')}
             <form action="${action}" method="POST" class="form-stacked">
                 <div class="hide">
                     ${util.render_form(file_form)}
-                ${util.render_form(delim_form)}
-                ${unicode(column_formset.management_form) | n}
+                    ${util.render_form(delim_form)}
+                    ${unicode(column_formset.management_form) | n}
                 </div>
                 <%
                     n_rows = len(fields_list)
@@ -146,14 +146,17 @@ ${layout.menubar(section='tables')}
     $("[rel='tooltip']").tooltip();
 
     $(".scrollable").width($(".form-actions").width());
+
     $("#step1").click(function (e) {
       e.preventDefault();
       $("input[name='cancel_create']").attr("name", "cancel_delim").click();
     });
+
     $("#step2").click(function (e) {
       e.preventDefault();
       $("input[name='cancel_create']").click();
     });
+
     $("body").keypress(function (e) {
       if (e.which == 13) {
         e.preventDefault();
@@ -205,7 +208,7 @@ ${layout.menubar(section='tables')}
 
     $(".dataSample").each(function () {
       var _val = $.trim($(this).text());
-      var _field = $(this).siblings().find("select");
+      var _field = $(this).siblings().find("select#id_cols-0-column_type");
       var _foundType = "string";
       if ($.isNumeric(_val)) {
         _val = _val * 1;
@@ -236,7 +239,7 @@ ${layout.menubar(section='tables')}
       }
     });
 
-    $("select").each(function () {
+    $("select#id_cols-0-column_type").each(function () {
       $(this).val($(this).data("possibleType"));
     });
 
@@ -266,4 +269,5 @@ ${layout.menubar(section='tables')}
     }
   });
 </script>
+
 ${ commonfooter(messages) | n,unicode }

+ 2 - 2
apps/beeswax/src/beeswax/tests.py

@@ -867,7 +867,7 @@ for x in sys.stdin:
       'table-name': 'my_table',
       'table-comment': 'Yo>>>>dude',  # Make sure escaping is sort of ok.
       'table-row_format': 'Delimited',
-      'table-field_terminator_0': r'\001',
+      'table-field_terminator_0': r',',
       'table-collection_terminator_0': r'\002',
       'table-map_key_terminator_0': r'\003',
       'table-file_format': 'TextFile',
@@ -888,7 +888,7 @@ for x in sys.stdin:
         )
         COMMENT "Yo>>>>dude"
         ROW FORMAT DELIMITED
-          FIELDS TERMINATED BY '\\001'
+          FIELDS TERMINATED BY ','
           COLLECTION ITEMS TERMINATED BY '\\002'
           MAP KEYS TERMINATED BY '\\003'
           STORED AS TextFile LOCATION "/tmp/foo"