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

Method format

shell/impala_shell/shell_output.py:54–80  ·  view source on GitHub ↗

Returns string containing representation of the table data.

(self, rows)

Source from the content-addressed store, hash-verified

52 self.prettytable = prettytable
53
54 def format(self, rows):
55 """Returns string containing representation of the table data."""
56
57 def decode_if_needed(row):
58 if sys.version_info.major >= 3:
59 return row
60 # prettytable will decode with 'strict' if the string is not already unicode,
61 # we should do it here to handle invalid characters.
62 return [entry.decode('UTF-8', 'replace') if isinstance(entry, str) else entry
63 for entry in row]
64
65 # Clear rows that already exist in the table.
66 self.prettytable.clear_rows()
67 try:
68 for row in rows:
69 self.prettytable.add_row(decode_if_needed(row))
70 return self.prettytable.get_string()
71 except Exception as e:
72 # beeswax returns each row as a tab separated string. If a string column
73 # value in a row has tabs, it will break the row split. Default to displaying
74 # raw results. This will change with a move to hiveserver2. Reference: IMPALA-116
75 error_msg = ("Prettytable cannot resolve string columns values that have "
76 "embedded tabs. Reverting to tab delimited text output")
77 print(error_msg, file=sys.stderr)
78 print('{0}: {1}'.format(type(e), str(e)), file=sys.stderr)
79
80 return '\n'.join(['\t'.join(decode_if_needed(row)) for row in rows])
81
82
83class DelimitedOutputFormatter(object):

Callers 15

Chart-2.9.4.min.jsFile · 0.45
ChFunction · 0.45
BhFunction · 0.45
JiFunction · 0.45
KiFunction · 0.45
d3.v3.min.jsFile · 0.45
c3.v7.min.jsFile · 0.45
exec_pip_installFunction · 0.45

Calls 2

typeEnum · 0.50
joinMethod · 0.45