Browse Source

[beeswax] Fix ANALYZE TABLE call for partitioned tables and raise error on COMPUTE..FOR COLUMNS

Jenny Kim 10 years ago
parent
commit
9754876a7e
1 changed files with 13 additions and 2 deletions
  1. 13 2
      apps/beeswax/src/beeswax/server/dbms.py

+ 13 - 2
apps/beeswax/src/beeswax/server/dbms.py

@@ -346,7 +346,14 @@ class HiveServer2Dbms(object):
     if self.server_name == 'impala':
       hql = 'COMPUTE STATS `%(database)s`.`%(table)s`' % {'database': database, 'table': table}
     else:
-      hql = 'ANALYZE TABLE `%(database)s`.`%(table)s` COMPUTE STATISTICS' % {'database': database, 'table': table}
+      table_obj = self.get_table(database, table)
+      partition_spec = ''
+      if table_obj.partition_keys:
+        partition_keys = ','.join([part.name for part in table_obj.partition_keys])
+        partition_spec = 'PARTITION(%(partition_keys)s)' % {'partition_keys': partition_keys}
+
+      hql = 'ANALYZE TABLE `%(database)s`.`%(table)s` %(partition_spec)s COMPUTE STATISTICS' % \
+            {'database': database, 'table': table, 'partition_spec': partition_spec}
 
     return self.execute_statement(hql)
 
@@ -355,7 +362,11 @@ class HiveServer2Dbms(object):
     if self.server_name == 'impala':
       hql = 'COMPUTE STATS `%(database)s`.`%(table)s`' % {'database': database, 'table': table}
     else:
-      hql = 'ANALYZE TABLE `%(database)s`.`%(table)s` COMPUTE STATISTICS FOR COLUMNS' % {'database': database, 'table': table}
+      table_obj = self.get_table(database, table)
+      if table_obj.partition_keys:
+        raise NotImplementedError('HIVE-4861: COMPUTE STATISTICS FOR COLUMNS not supported for partitioned-tables.')
+      else:
+        hql = 'ANALYZE TABLE `%(database)s`.`%(table)s` COMPUTE STATISTICS FOR COLUMNS' % {'database': database, 'table': table}
 
     return self.execute_statement(hql)