Pārlūkot izejas kodu

HUE-7 [metastore] Create Hive json table

Romain Rigaux 9 gadi atpakaļ
vecāks
revīzija
abe9354

+ 17 - 3
desktop/libs/indexer/src/indexer/api3.py

@@ -180,7 +180,7 @@ def _create_table_from_a_file(request, source, destination):
 
   source_path = source['path']
   external = not destination['useDefaultLocation']
-  external_path = not destination['nonDefaultLocation']
+  external_path = destination['nonDefaultLocation']
 
   load_data = destination['importData']
   skip_header = destination['hasHeader']
@@ -198,11 +198,21 @@ def _create_table_from_a_file(request, source, destination):
     map_delimiter = r'\\003'
     regexp_delimiter = '.*'
 
-
   file_format = 'TextFile'
+  row_format = 'Delimited'
+  serde_name = ''
+  serde_properties = ''
   extra_create_properties = ''
   sql = ''
 
+  if table_format == 'json':
+    row_format = 'serde'
+    serde_name = 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
+    serde_properties = '''"separatorChar" = "\\t",
+   "quoteChar"     = "'",
+   "escapeChar"    = "\\\\"
+   '''
+
   if load_data:
     if table_format in ('parquet', 'kudu'):
       table_name, final_table_name = 'hue__tmp_%s' % table_name, table_name
@@ -225,8 +235,12 @@ def _create_table_from_a_file(request, source, destination):
       'table': {
           'name': table_name,
           'comment': comment,
-          'row_format': 'Delimited',
+          'row_format': row_format,
           'field_terminator': field_delimiter,
+          'collection_terminator': collection_delimiter,
+          'map_key_terminator': map_delimiter,
+          'serde_name': serde_name,
+          'serde_properties': serde_properties,
           'file_format': file_format,
           'external': external or load_data and table_format in ('parquet', 'kudu'),
           'path': external_path,

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

@@ -63,7 +63,7 @@ PARTITIONED BY ${column_list(partition_columns)|n}
 ## TODO: CLUSTERED BY here
 ## TODO: SORTED BY...INTO...BUCKETS here
 ROW FORMAT \
-% if table.has_key('row_format'):
+% if table.get('row_format'):
 %   if table["row_format"] == "Delimited":
   DELIMITED
 %     if table.has_key('field_terminator'):
@@ -76,9 +76,9 @@ ROW FORMAT \
     MAP KEYS TERMINATED BY '${table["map_key_terminator"] | n}'
 %     endif
 %   else:
-  SERDE ${table["serde_name"] | n}
+  SERDE '${table["serde_name"] | n}'
 %     if table["serde_properties"]:
-  WITH SERDEPROPERTIES ${table["serde_properties"] | n}
+  WITH SERDEPROPERTIES (${table["serde_properties"] | n})
 %     endif
 %   endif
 % endif