Browse Source

HUE-7 [metastore] Nested types SQL logic in the frontend

Romain Rigaux 9 years ago
parent
commit
0e3f617

+ 2 - 0
desktop/libs/indexer/src/indexer/fields.py

@@ -63,6 +63,8 @@ class Field(object):
       'showProperties': self.show_properties,
       'nested': [],
       'level': 0,
+      'length': 100,
+      'keyType': ''
     }
 
 FIELD_TYPES = [

+ 6 - 4
desktop/libs/indexer/src/indexer/templates/gen/create_table_statement.mako

@@ -17,13 +17,15 @@
 <%!
 def col_type(col):
   if col["type"] == "array":
-    return "array <%s>" % col["array_type"]
+    return "array <%s>" % col_type(col["nested"])
+  if col["type"] == "struct":
+    return "struct <%s>" % ', '.join(column_list(col["nested"]))
   elif col["type"] == "map":
-    return "map <%s, %s>" % (col["map_key_type"], col["map_value_type"])
+    return "map <%s, %s>" % (col["keyType"], '<%s>' % col_type(col["nested"]) if col["type"] in ('array', 'struct', 'map') else col["type"])
   elif col["type"] == "char":
-    return "char(%d)" % col["char_length"]
+    return "char(%d)" % col["length"]
   elif col["type"] == "varchar":
-    return "varchar(%d)" % col["varchar_length"]
+    return "varchar(%d)" % col["length"]
   return col["type"]
 %>\
 

+ 24 - 10
desktop/libs/indexer/src/indexer/templates/importer.mako

@@ -416,8 +416,8 @@ ${ assist.assistPanel() }
 
             <!-- ko if: tableFormat() != 'kudu' -->
             <div class="form-inline" data-bind="foreach: partitionColumns">
-                <div data-bind="template: { name: 'table-field-template', data: $data }" class="margin-top-10 field"></div>
-                <a data-bind="click: function() { $parent.partitionColumns.remove($data); }"><i class="fa fa-minus"></i></a>
+              <div data-bind="template: { name: 'table-field-template', data: $data }" class="margin-top-10 field"></div>
+              <a data-bind="click: function() { $parent.partitionColumns.remove($data); }"><i class="fa fa-minus"></i></a>
             </div>
             <a data-bind="click: function() { partitionColumns.push($root.loadField({operations: [], nested: [], name: '', level: 0, type: '', showProperties: false, isPartition: true})); }" class="pointer margin-left-20" title="${_('Add Operation')}"><i class="fa fa-plus"></i> ${_('Add partition')}</a>
             <!-- /ko -->
@@ -474,6 +474,7 @@ ${ assist.assistPanel() }
         <h3 class="card-heading simple">${_('Fields')}</h3>
         <form class="form-inline" data-bind="foreach: columns">
           <!-- ko if: $parent.ouputFormat() == 'table' -->
+            <span data-bind="text: ko.mapping.toJSON($data)"></span>
             <div data-bind="template: { name: 'table-field-template', data: $data }" class="margin-top-10 field"></div>
           <!-- /ko -->
 
@@ -544,23 +545,33 @@ ${ assist.assistPanel() }
 
 
 <script type="text/html" id="table-field-template">
-  <label>${ _('Name') }
+  <label data-bind="visible: level() == 0 || ($parent.type() != 'array' && $parent.type() != 'map')">${ _('Name') }
     <input type="text" class="input-large" placeholder="${ _('Field name') }" data-bind="value: name">
   </label>
 
   <label>${ _('Type') }
-  <select class="input-small" data-bind="options: $root.createWizard.hiveFieldTypes, value: type"></select>
+  <!-- ko if: ! (level() > 0 && $parent.type() == 'map') -->
+    <select class="input-small" data-bind="options: $root.createWizard.hiveFieldTypes, value: type"></select>
+  <!-- /ko -->
+  <!-- ko if: level() > 0 && $parent.type() == 'map' -->
+    <select class="input-small" data-bind="options: $root.createWizard.hivePrimitiveFieldTypes, value: keyType"></select>
+    <select class="input-small" data-bind="options: $root.createWizard.hiveFieldTypes, value: type"></select>
+
+  <!-- /ko -->
+  <input type="number" class="input-small" placeholder="${ _('Length') }" data-bind="value: length, visible: type() == 'varchar' || type() == 'char'">
 
   <!-- ko if: type() == 'array' || type() == 'map' || type() == 'struct' -->
     <div data-bind="template: { name: 'table-field-template', foreach: nested }">
     </div>
-    <a data-bind="click: function() { nested.push(ko.mapping.fromJS({operations: [], nested: [], name: '', type: '', level: level() + 1})); }"><i class="fa fa-plus"></i></a>
+    <a data-bind="click: function() { nested.push($root.loadField({operations: [], nested: [], name: '', type: '', 'keyType': '', level: level() + 1})); }, visible: type() == 'struct'"><i class="fa fa-plus"></i></a>
   <!-- /ko -->
   </label>
 
-  ${_('Comment')}
+  <span data-bind="visible: level() == 0 || ($parent.type() != 'array' && $parent.type() != 'map')">
+    ${_('Comment')}
+  </span>
 
-  <!-- ko if: level() > 0 -->
+  <!-- ko if: level() > 0 && $parent.type() == 'struct' && $parent.nested().length > 1 -->
     <a data-bind="click: function() { $parent.nested.remove($data); }"><i class="fa fa-minus"></i></a>
   <!-- /ko -->
 
@@ -1061,6 +1072,7 @@ ${ assist.assistPanel() }
       self.operationTypes = ${operators_json | n};
 
       self.fieldTypes = ${fields_json | n}.solr;
+      self.hivePrimitiveFieldTypes = ${fields_json | n}.hivePrimitive;
       self.hiveFieldTypes = ${fields_json | n}.hive;
       self.fileTypes = ${file_types_json | n};
       self.prefill = ko.mapping.fromJS(${prefill | n});
@@ -1279,11 +1291,13 @@ ${ assist.assistPanel() }
         koField.operations.push(operation);
       });
 
-      koField.type.subscribe(function(newVal) {
+      var autoExpand = function(newVal) {
         if ((newVal == 'array' || newVal == 'map' || newVal == 'struct') && koField.nested().length == 0) {
-          koField.nested.push(ko.mapping.fromJS({operations: [], nested: [], name: '', type: '', level: koField.level() + 1}));
+          koField.nested.push(loadField({operations: [], nested: [], name: '', type: '', keyType: '', level: koField.level() + 1}));
         }
-      });
+      };
+      koField.type.subscribe(autoExpand);
+      koField.keyType.subscribe(autoExpand);
 
       return koField;
     }

+ 1 - 1
desktop/libs/indexer/src/indexer/views.py

@@ -92,7 +92,7 @@ def _importer(request, prefill):
 
   return render('importer.mako', request, {
       'is_embeddable': request.GET.get('is_embeddable', False),
-      'fields_json' : json.dumps({'solr': [field.name for field in FIELD_TYPES], 'hive': HIVE_TYPES}),
+      'fields_json' : json.dumps({'solr': [field.name for field in FIELD_TYPES], 'hive': HIVE_TYPES, 'hivePrimitive': HIVE_PRIMITIVE_TYPES}),
       'operators_json' : json.dumps([operator.to_dict() for operator in OPERATORS]),
       'file_types_json' : json.dumps([format_.format_info() for format_ in get_file_indexable_format_types()]),
       'default_field_type' : json.dumps(Field().to_dict()),