-
Notifications
You must be signed in to change notification settings - Fork 563
Suggest columns for ORDER BY
and DISTINCT
(fixes #685)
#686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggest columns for ORDER BY
and DISTINCT
(fixes #685)
#686
Conversation
22b5dce
to
8bd2227
Compare
ORDER BY
and DISTINCT
(fix #685)ORDER BY
and DISTINCT
(fixes #685)
Codecov Report
@@ Coverage Diff @@
## master #686 +/- ##
=========================================
Coverage ? 79.05%
=========================================
Files ? 23
Lines ? 2535
Branches ? 0
=========================================
Hits ? 2004
Misses ? 531
Partials ? 0
Continue to review full report at Codecov.
|
Thanks for taking the time to make pgcli better. Sorry I haven't had time to look into this. I won't have time till end of this week, but if none of the other core devs have reviewed it by then, I'll take a look. Sorry about the delay. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, and seems to work as expected - I tried it out on a few cases. I don't think that def table_reference
is needed though.
tests/test_sqlcompletion.py
Outdated
@@ -4,10 +4,17 @@ | |||
from pgcli.packages.parseutils.tables import TableReference | |||
import pytest | |||
|
|||
# Returns the expected select-clause suggestions for a single-table select | |||
|
|||
def table_reference(table, schema=None, alias=None, is_function=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TableReference
instantiation is already a one-liner. What's the point of wrapping it into a function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On reflection, probably none, I think I added it before I did a bunch of line-wrapping. Of course, one can avoid passing a few parameters since table_reference
has default parameters, but I don't think the method pulls its weight, I'll remove it.
@@ -213,9 +220,62 @@ def test_truncate_suggests_qualified_tables(): | |||
]) | |||
def test_distinct_suggests_cols(text): | |||
suggestions = suggest_type(text, text) | |||
assert suggestions ==(Column(table_refs=(), qualifiable=True),) | |||
assert set(suggestions) == set([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done adding tests!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't be a good PR without them...!
8bd2227
to
e5b5b8b
Compare
@owst Also, the line in changelog:
is not very clear. I would suggest something like:
|
Yeah, fair enough, I'm certainly not wedded to the current wording. The only thing is "fixed" to me suggests it was "broken" before, when I think it was just a missing feature. Perhaps
? |
Having typed an alias name in an `ORDER BY` or (`SELECT`) `DISTINCT` clause, the alias was not taken account of, and the completion simply listed all columns. This change fixes that, and makes the autocompletion behave the same as in `SELECT` and `WHERE` clauses.
e5b5b8b
to
3d560ba
Compare
@owst Yes, that is better! |
Looks good. Merging. Thank you! 🌷 |
Description
Having typed an alias name in an
ORDER BY
or (SELECT
)DISTINCT
clause,the alias was not taken account of, and the completion simply listed all
columns. This change fixes that, and makes the autocompletion behave the
same as in
SELECT
andWHERE
clauses.Checklist
changelog.md
.AUTHORS
file (or it's already there).