Эх сурвалжийг харах

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

Romain Rigaux 9 жил өмнө
parent
commit
1808d8e748

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

@@ -17,18 +17,28 @@
 <%!
 def col_type(col):
   if col["type"] == "array":
-    return "array <%s>" % col_type(col["nested"])
+    return "array <%s>" % col_type(col["nested"][0])
   if col["type"] == "struct":
-    return "struct <%s>" % ', '.join(column_list(col["nested"]))
+    return "struct <%s>" % ', '.join(struct_column_list({}, col["nested"]))
   elif col["type"] == "map":
-    return "map <%s, %s>" % (col["keyType"], '<%s>' % col_type(col["nested"]) if col["type"] in ('array', 'struct', 'map') else col["type"])
+    return "map <%s, %s>" % (col["nested"][0]["keyType"], '%s' % col_type(col["nested"][0]) if col["type"] in ('array', 'struct', 'map') else col["type"])
   elif col["type"] == "char":
     return "char(%d)" % col["length"]
   elif col["type"] == "varchar":
     return "varchar(%d)" % col["length"]
   return col["type"]
-%>\
 
+%>
+
+<%!
+def struct_column_list(table, columns):
+  col_sql = []
+  for col in columns:
+    comment = ' COMMENT "%(comment)s"' % col if col.get("comment") else ''
+    col_sql.append('`%s`:%s%s' % (col["name"], col_type(col), comment))
+
+  return col_sql
+%>
 
 <%def name="column_list(table, columns)">\
 (

+ 0 - 14
desktop/libs/indexer/src/indexer/templates/importer.mako

@@ -474,7 +474,6 @@ ${ 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 -->
 
@@ -582,19 +581,6 @@ ${ assist.assistPanel() }
 </script>
 
 
-<script type="text/html" id="display-table-nested-field">
-  <!-- ko: if type() != 'array' -->
-    <select class="input-small" data-bind="options: $root.createWizard.hiveFieldTypes, value: type"></select>
-  <!-- /ko -->
-
-  <!-- ko: if type() == 'array' -->
-    <div data-bind="template: { name: 'display-table-nested-field', foreach: nested }">
-    </div>
-    <a data-bind="click: function() { nested.push('aa'); }"><i class="fa fa-plus"></i></a>
-  <!-- /ko -->
-</script>
-
-
 <script type="text/html" id="index-field-template">
   <label>${ _('Name') }
     <input type="text" class="input-large" placeholder="${ _('Field name') }" data-bind="value: name">