Sfoglia il codice sorgente

HUE-2767 [impala] Issue showing sample data for a table

Fix: Table does not exist: default.default.sample_08
Romain Rigaux 10 anni fa
parent
commit
abfc1bb
2 ha cambiato i file con 19 aggiunte e 9 eliminazioni
  1. 9 9
      apps/beeswax/src/beeswax/server/dbms.py
  2. 10 0
      apps/impala/src/impala/tests.py

+ 9 - 9
apps/beeswax/src/beeswax/server/dbms.py

@@ -143,7 +143,7 @@ class HiveServer2Dbms(object):
 
 
   def select_star_from(self, database, table):
-    hql = "SELECT * FROM `%s.%s` %s" % (database, table.name, self._get_browse_limit_clause(table))
+    hql = "SELECT * FROM `%s`.`%s` %s" % (database, table.name, self._get_browse_limit_clause(table))
     return self.execute_statement(hql)
 
 
@@ -189,7 +189,7 @@ class HiveServer2Dbms(object):
       if table.partition_keys:
         partitions = self.get_partitions(database, table, 1)
         partition_query = 'WHERE ' + ' AND '.join(["%s='%s'" % (table.partition_keys[idx].name, key) for idx, key in enumerate(partitions[0].values)])
-      hql = "SELECT * FROM `%s.%s` %s LIMIT %s" % (database, table.name, partition_query, limit)
+      hql = "SELECT * FROM `%s`.`%s` %s LIMIT %s" % (database, table.name, partition_query, limit)
       query = hql_query(hql)
       handle = self.execute_and_wait(query, timeout_sec=5.0)
 
@@ -301,9 +301,9 @@ class HiveServer2Dbms(object):
 
   def drop_table(self, database, table):
     if table.is_view:
-      hql = "DROP VIEW `%s.%s`" % (database, table.name,)
+      hql = "DROP VIEW `%s`.`%s`" % (database, table.name,)
     else:
-      hql = "DROP TABLE `%s.%s`" % (database, table.name,)
+      hql = "DROP TABLE `%s`.`%s`" % (database, table.name,)
 
     return self.execute_statement(hql)
 
@@ -314,7 +314,7 @@ class HiveServer2Dbms(object):
     if form.cleaned_data['overwrite']:
       hql += " OVERWRITE"
     hql += " INTO TABLE "
-    hql += "`%s.%s`" % (database, table.name,)
+    hql += "`%s`.`%s`" % (database, table.name,)
     if form.partition_columns:
       hql += " PARTITION ("
       vals = []
@@ -335,9 +335,9 @@ class HiveServer2Dbms(object):
 
     for table in tables:
       if table.is_view:
-        hql.append("DROP VIEW `%s.%s`" % (database, table.name,))
+        hql.append("DROP VIEW `%s`.`%s`" % (database, table.name,))
       else:
-        hql.append("DROP TABLE `%s.%s`" % (database, table.name,))
+        hql.append("DROP TABLE `%s`.`%s`" % (database, table.name,))
     query = hql_query(';'.join(hql), database)
     design.data = query.dumps()
     design.save()
@@ -350,7 +350,7 @@ class HiveServer2Dbms(object):
 
     for table in tables:
       try:
-        hql = "INVALIDATE METADATA %s.%s" % (database, table,)
+        hql = "INVALIDATE METADATA `%s`.`%s`" % (database, table,)
         query = hql_query(hql, database, query_type=QUERY_TYPES[1])
 
         handle = self.execute_and_wait(query, timeout_sec=10.0)
@@ -586,7 +586,7 @@ class HiveServer2Dbms(object):
     for idx, key in enumerate(partitions[partition_id].values):
       partition_query += (idx > 0 and " AND " or "") + table.partition_keys[idx].name + "='%s'" % key
 
-    hql = "SELECT * FROM `%s.%s` WHERE %s" % (db_name, table_name, partition_query)
+    hql = "SELECT * FROM `%s`.`%s` WHERE %s" % (db_name, table_name, partition_query)
 
     return self.execute_statement(hql)
 

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

@@ -24,6 +24,7 @@ from nose.plugins.skip import SkipTest
 from nose.tools import assert_true, assert_equal, assert_false
 
 from django.contrib.auth.models import User
+from django.core.urlresolvers import reverse
 
 from desktop.lib.django_test_util import make_logged_in_client
 from desktop.lib.test_utils import grant_access, add_to_group
@@ -183,6 +184,15 @@ class TestImpalaIntegration:
     assert_true('MERGING-EXCHANGE' in json_response['explanation'], json_response)
     assert_true('SCAN HDFS' in json_response['explanation'], json_response)
 
+  def test_get_table_sample(self):
+    client = make_logged_in_client()
+
+    resp = client.get(reverse('impala:describe_table', kwargs={'database': self.DATABASE, 'table': 'tweets'}) + '?sample=true')
+
+    assert_equal(resp.status_code, 200)
+    assert_true('531091827' in resp.content, resp.content) # We are getting one or two random rows
+    assert_true(len(resp.context['sample']) > 0, resp.context['sample'])
+
 
 # Could be refactored with SavedQuery.create_empty()
 def create_saved_query(app_name, owner):