Enhancements to athena-cli#36
Conversation
| row_count = len(results['ResultSet']['Rows']) | ||
| if headers and len(results['ResultSet']['Rows']) and results['ResultSet']['Rows'][0]['Data'][0].get('VarCharValue', None) == headers[0]: | ||
| row_count -= 1 # don't count header | ||
| #tabulate() only supports ascii |
There was a problem hiding this comment.
Is this true for Python 3?
There was a problem hiding this comment.
It seems to not be an issue in Python 3, I refactored this a little though and removed the comment
There was a problem hiding this comment.
I was going to suggest athena CLI completely drop support for Python 2.7 because cmd2, it's major dependency, has dropped support as of the end of last month. https://github.com/python-cmd2/cmd2#python-27-support-is-eol
So the charset problem might be resolved by just reverting the earlier hack. See #34
There was a problem hiding this comment.
We're using Python 3, so it's fine by us. I'll update the PR with some encoding cleanup and put in a python 3 shebang
There was a problem hiding this comment.
I went ahead and made the changes, let me know what you think.
|
|
||
| if status == 'SUCCEEDED': | ||
| output_results(self.athena, self.format, execution_id, sys.stdout) | ||
| output_results(self.athena, self.format, execution_id, sys.stdout, False) |
There was a problem hiding this comment.
For boolean parameters I would include the paramater name eg ..., is_shell=False).
| if status == 'SUCCEEDED': | ||
| process = subprocess.Popen(self.pager, stdin=subprocess.PIPE) | ||
| row_count = output_results(self.athena, self.format, self.execution_id, process.stdin) | ||
| row_count = output_results(self.athena, self.format, self.execution_id, process.stdin, True) |
satterly
left a comment
There was a problem hiding this comment.
Thanks for the PR. I don't work for the Guardian anymore but I'll see if I can get someone to merge this (with a few minor changes).
|
Cool, thanks for the feedback and consideration |
| @@ -1,3 +1,4 @@ | |||
| #!/usr/bin/env python3 | |||
There was a problem hiding this comment.
Instead of adding a shebang here you should add "python_requires" option to setup.py. See https://packaging.python.org/guides/distributing-packages-using-setuptools/#python-requires
There was a problem hiding this comment.
Agreed. I'll check that in in a few
There was a problem hiding this comment.
I set the python version requirement to 3.5 and also set a cmd2 version requirement
There was a problem hiding this comment.
This line can be removed. It's ignored anyway as this is a python console script not a shell script.
| self.athena = athena | ||
| self.dbname = db | ||
| self.format = format | ||
| self.format = 'CSV' if format is None else format |
There was a problem hiding this comment.
A more idiomatic way of writing this is ...
self.format = format or 'CSV'
However, why did you remove the default format from the method signature?
There was a problem hiding this comment.
The default wasn't being used anymore, it is always set, so it felt redundant having the default
There was a problem hiding this comment.
I updated the code as you suggested...
| class AthenaShell(cmd.Cmd, object): | ||
|
|
||
| multilineCommands = ['WITH', 'SELECT', 'ALTER', 'CREATE', 'DESCRIBE', 'DROP', 'MSCK', 'SHOW', 'USE', 'VALUES'] | ||
| multiline_commands = ['WITH', 'SELECT', 'ALTER', 'CREATE', 'DESCRIBE', 'DROP', 'MSCK', 'SHOW', 'USE', 'VALUES', 'with', 'select', 'alter', 'create', 'describe', 'drop', 'msck', 'show', 'use', 'values'] |
There was a problem hiding this comment.
Why is it necessary to repeat the list of valid commands as both upper- and lowercase?
There was a problem hiding this comment.
cmd2 seems to be case-sensitive with this feature, i.e. without the lower case commands in the list, then lower case statements aren't multiline
There was a problem hiding this comment.
This could be rewritten as ...
multiline_commands = ['WITH', 'SELECT', 'ALTER', 'CREATE', 'DESCRIBE', 'DROP', 'MSCK', 'SHOW', 'USE', 'VALUES']
multiline_commands.extend([c.lower() for c in multiline_commands])
... to avoid the possibility of missing the fact you need to add the command twice if new commands are added.
| help_output = """ | ||
| Supported commands: | ||
| QUIT | ||
| EXIT |
There was a problem hiding this comment.
Do EXIT and QUIT do exactly the same thing?
There was a problem hiding this comment.
yes, "exit" is supported by other CLIs (like the presto-cli) so some users liked to have it
There was a problem hiding this comment.
| if first_row == headers: | ||
| next(rows) | ||
|
|
||
| return (headers, rows) |
There was a problem hiding this comment.
This return has made the code after this try/exception block unreachable.
There was a problem hiding this comment.
Whoops. This should be fixed now
| 'Topic :: Utilities' | ||
| ] | ||
| ], | ||
| python_requires='>=3.5' |
There was a problem hiding this comment.
The tests are failing because they are being run against Python 2.7 and 3.4 but this python_requires restricts installation to Python 3.5+.
You need to update the .travis.yml file like so ...
python:
- "3.5"
- "3.6"
Hi, we are using athena-cli across our company, and made a few enhancements based on feedback from users. We'd love to get your feedback on these changes and hopefully merge them in.
Some changes include: