浏览代码

[impala] Move get_sample logic back into HiveServer2Dbms

Jenny Kim 10 年之前
父节点
当前提交
70b51c0f30
共有 2 个文件被更改,包括 9 次插入30 次删除
  1. 9 3
      apps/beeswax/src/beeswax/server/dbms.py
  2. 0 27
      apps/impala/src/impala/dbms.py

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

@@ -306,10 +306,16 @@ class HiveServer2Dbms(object):
     if not table.is_view:
       limit = min(100, BROWSE_PARTITIONED_TABLE_LIMIT.get())
 
-      if table.partition_keys:  # Filter on max # of partitions for partitioned tables
-        hql = self._get_sample_partition_query(database, table, limit)
+      if column or nested: # Could do column for any type, then nested with partitions
+        if self.server_name == 'impala':
+          from impala.dbms import ImpalaDbms
+          select_clause, from_clause = ImpalaDbms.get_nested_select(database, table.name, column, nested)
+          hql = 'SELECT %s FROM %s LIMIT %s' % (select_clause, from_clause, limit)
       else:
-        hql = "SELECT * FROM `%s`.`%s` LIMIT %s" % (database, table.name, limit)
+        if table.partition_keys:  # Filter on max # of partitions for partitioned tables
+          hql = self._get_sample_partition_query(database, table, limit)
+        else:
+          hql = "SELECT * FROM `%s`.`%s` LIMIT %s" % (database, table.name, limit)
 
       if hql:
         query = hql_query(hql)

+ 0 - 27
apps/impala/src/impala/dbms.py

@@ -126,33 +126,6 @@ class ImpalaDbms(HiveServer2Dbms):
         self.close(handle)
 
 
-  def get_sample(self, database, table, column=None, nested=None):
-    result = None
-    hql = None
-
-    if not table.is_view:
-      limit = min(100, BROWSE_PARTITIONED_TABLE_LIMIT.get())
-
-      if column or nested: # Could do column for any type, then nested with partitions
-        select_clause, from_clause = ImpalaDbms.get_nested_select(database, table.name, column, nested)
-        hql = 'SELECT %s FROM %s LIMIT %s' % (select_clause, from_clause, limit)
-      else:
-        if table.partition_keys:  # Filter on max # of partitions for partitioned tables
-          hql = self._get_sample_partition_query(database, table, limit)
-        else:
-          hql = "SELECT * FROM `%s`.`%s` LIMIT %s" % (database, table.name, limit)
-
-      if hql:
-        query = hql_query(hql)
-        handle = self.execute_and_wait(query, timeout_sec=5.0)
-
-        if handle:
-          result = self.fetch(handle, rows=100)
-          self.close(handle)
-
-    return result
-
-
   def get_histogram(self, database, table, column, nested=None):
     """
     Returns the results of an Impala SELECT histogram() FROM query for a given column or nested type.