瀏覽代碼

[hive] Support fetching logs with column level format

Romain Rigaux 10 年之前
父節點
當前提交
e797245c28
共有 2 個文件被更改,包括 17 次插入12 次删除
  1. 15 11
      apps/beeswax/src/beeswax/server/hive_server2_lib.py
  2. 2 1
      apps/beeswax/src/beeswax/tests.py

+ 15 - 11
apps/beeswax/src/beeswax/server/hive_server2_lib.py

@@ -222,11 +222,9 @@ class HiveServerTColumnValue2:
 
   @property
   def val(self):
-    # TODO get index from schema
-    if self.column_value.boolVal is not None:
-      return self.column_value.boolVal.values
-    elif self.column_value.byteVal is not None:
-      return self.column_value.byteVal.values
+    # Could directly get index from schema but would need to cache the schema
+    if self.column_value.stringVal:
+      return self.column_value.stringVal.values
     elif self.column_value.i16Val is not None:
       return self.column_value.i16Val.values
     elif self.column_value.i32Val is not None:
@@ -235,8 +233,12 @@ class HiveServerTColumnValue2:
       return self.column_value.i64Val.values
     elif self.column_value.doubleVal is not None:
       return self.column_value.doubleVal.values
-    elif self.column_value.stringVal != []:
-      return self.column_value.stringVal.values
+    elif self.column_value.boolVal is not None:
+      return self.column_value.boolVal.values
+    elif self.column_value.byteVal is not None:
+      return self.column_value.byteVal.values
+    elif self.column_value.binaryVal is not None:
+      return self.column_value.binaryVal.values
 
 
 class HiveServerDataTable(DataTable):
@@ -343,7 +345,6 @@ class HiveServerTColumnValue:
 
   @property
   def val(self):
-    # TODO get index from schema
     if self.column_value.boolVal is not None:
       return self.column_value.boolVal.value
     elif self.column_value.byteVal is not None:
@@ -697,11 +698,14 @@ class HiveServerClient:
 
 
   def fetch_log(self, operation_handle, orientation=TFetchOrientation.FETCH_NEXT, max_rows=1000):
-    req = TFetchResultsReq(operationHandle=operation_handle, orientation=orientation,
-                           maxRows=max_rows, fetchType=1)
+    req = TFetchResultsReq(operationHandle=operation_handle, orientation=orientation, maxRows=max_rows, fetchType=1)
     res = self.call(self._client.FetchResults, req)
 
-    lines = imap(lambda r: r.colVals[0].stringVal.value, res.results.rows)
+    if beeswax_conf.THRIFT_VERSION.get() >= 7:
+      lines = res.results.columns[0].stringVal.values
+    else:
+      lines = imap(lambda r: r.colVals[0].stringVal.value, res.results.rows)
+
     return '\n'.join(lines)
 
 

+ 2 - 1
apps/beeswax/src/beeswax/tests.py

@@ -1438,7 +1438,8 @@ for x in sys.stdin:
 
     resp = self.client.get("/beeswax/results/%s/0?format=json" % history_id)
     content = json.loads(resp.content)
-    assert_equal([[1.0], [2.0], [3.0], [u'NaN'], [u'NULL'], [u'NULL'], [u'NULL']], content['results'])
+    # assert_equal([[1.0], [2.0], [3.0], [u'NaN'], [u'NULL'], [u'NULL'], [u'NULL']], content['results']) # New Hive does not return NULL anymore
+    assert_equal([[1.0], [2.0], [3.0], [u'NaN'], [0.0], [0.0], [0.0]], content['results'])
 
 
   def test_create_database(self):