Bläddra i källkod

[impala] Display message in Sample view in Impala if the table has complex column types

Jenny Kim 10 år sedan
förälder
incheckning
e1af716

+ 18 - 0
apps/beeswax/src/beeswax/server/hive_server2_lib.py

@@ -144,6 +144,24 @@ class HiveServerTable(Table):
     end_cols_index = map(itemgetter('data_type'), rows[col_row_index:]).index(None)
     return rows[col_row_index:][:end_cols_index]
 
+  @property
+  def has_complex(self):
+    has_complex = False
+    complex_types = ["struct", "array", "map", "uniontype"]
+    patterns = [re.compile(typ) for typ in complex_types]
+
+    for column in self.cols:
+      if isinstance(column, dict) and 'data_type' in column:
+        column_type = column['data_type']
+      else:  # Col object
+        column_type = column.type
+      if column_type and any(p.match(column_type.lower()) for p in patterns):
+        has_complex = True
+        break
+
+    return has_complex
+
+
 
 class HiveServerTRowSet2:
   def __init__(self, row_set, schema):

+ 10 - 0
apps/beeswax/src/beeswax/tests.py

@@ -2224,6 +2224,16 @@ class TestHiveServer2API():
                  ], table.partition_keys)
 
 
+  def test_hiveserver_has_complex(self):
+    # Test simple table with only scalars
+    table = MockHiveServerTable()
+    assert_false(table.has_complex, table.cols)
+
+    # Test complex table with array column
+    table.describe.insert(4, {'comment': '', 'col_name': 'fizz', 'data_type': 'array<string>'})
+    assert_true(table.has_complex, table.cols)
+
+
   def test_hiveserver_table_partition_keys(self):
     describe = [
         {'comment': None, 'col_name': '# Partition Information', 'data_type': None},

+ 3 - 0
apps/metastore/src/metastore/templates/sample.mako

@@ -25,6 +25,9 @@ from django.utils.translation import ugettext as _
       <pre>${ error_message | h }</pre>
     </div>
   % else:
+    % if app_name == 'impala' and table.has_complex:
+      <p class="alert">${ _('Impala does not support selecting complex types. These columns have been hidden from the sample results.') }</p>
+    % endif
   <table class="table table-striped table-condensed sampleTable">
     <thead>
       <tr>