MCPcopy Create free account
hub / github.com/apache/impala / ImpylaHS2ResultSet

Class ImpylaHS2ResultSet

tests/common/impala_connection.py:896–962  ·  view source on GitHub ↗

This emulates the interface of ImpalaBeeswaxResult so that it can be used in place of it. TODO: when we deprecate/remove Beeswax, clean this up.

Source from the content-addressed store, hash-verified

894
895
896class ImpylaHS2ResultSet(object):
897 """This emulates the interface of ImpalaBeeswaxResult so that it can be used in
898 place of it. TODO: when we deprecate/remove Beeswax, clean this up."""
899 def __init__(self, success, result_tuples, column_labels, column_types, query, log,
900 profile, query_id, exec_summary):
901 self.success = success
902 self.column_labels = column_labels
903 self.column_types = column_types
904 self.query = query
905 self.log = log
906 # ImpalaBeeswaxResult store profile at runtime_profile field
907 self.runtime_profile = profile
908 self.query_id = query_id
909 self.__result_tuples = result_tuples
910 # self.data is the data in the ImpalaBeeswaxResult format: a list of rows with each
911 # row represented as a tab-separated string.
912 self.data = None
913 if result_tuples is not None:
914 self.data = [self.__convert_result_row(tuple) for tuple in result_tuples]
915 self.exec_summary = exec_summary
916
917 def tuples(self):
918 """Return the raw HS2 result set, which is a list of tuples."""
919 return self.__result_tuples
920
921 def get_data(self):
922 if self.data:
923 return '\n'.join(self.data)
924 return ''
925
926 def __convert_result_row(self, result_tuple):
927 """Take primitive values from a result tuple and construct the tab-separated string
928 that would have been returned via beeswax."""
929 row = list()
930 for idx, val in enumerate(result_tuple):
931 row.append(self.__convert_result_value(val, self.column_types[idx]))
932 return '\t'.join(row)
933
934 def __convert_result_value(self, val, col_type):
935 """Take a primitive value from a result tuple and its type and construct the string
936 that would have been returned via beeswax."""
937 if val is None:
938 return 'NULL'
939 if isinstance(val, float):
940 # Same format as what Beeswax uses in the backend.
941 if math.isnan(val):
942 return 'NaN'
943 elif math.isinf(val):
944 if val < 0:
945 return '-Infinity'
946 else:
947 return 'Infinity'
948 else:
949 return "{:.16g}".format(val)
950 elif col_type == 'BOOLEAN':
951 # Beeswax return 'false' or 'true' for boolean column.
952 # HS2 return 'False' or 'True'.
953 return str(val).lower()

Callers 1

__fetch_resultsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected