aws-cli
aws-cli copied to clipboard
Preserve the order of keys in the output table
Issue #, if available: #6941
Description of changes: Preserve the order of keys specified in query in the output table.
Before this change,
$ aws ec2 describe-images --owner amazon --filters 'Name=name,Values=amzn-ami-*-x86_64-gp2' --query "Images[?CreationDate > \`$(date --date='2 month ago' +%Y-%m-%d)\`].{Name:Name,ImageId:ImageId,CreationDate:CreationDate}" --output table --color off
-------------------------------------------------------------------------------------------------------
| DescribeImages |
+---------------------------+------------------------+------------------------------------------------+
| CreationDate | ImageId | Name |
+---------------------------+------------------------+------------------------------------------------+
| 2020-09-04T02:10:36.000Z | ami-021234069a5506633 | amzn-ami-hvm-2018.03.0.20200904.0-x86_64-gp2 |
| 2020-08-11T20:09:50.000Z | ami-034dad9bdb65ec34b | amzn-ami-hvm-2018.03.0.20200729.0-x86_64-gp2 |
+---------------------------+------------------------+------------------------------------------------+
after this change,
$ aws ec2 describe-images --owner amazon --filters 'Name=name,Values=amzn-ami-*-x86_64-gp2' --query "Images[?CreationDate > \`$(date --date='2 month ago' +%Y-%m-%d)\`].{Name:Name,ImageId:ImageId,CreationDate:CreationDate}" --output table --color off
-------------------------------------------------------------------------------------------------------
| DescribeImages |
+-----------------------------------------------+------------------------+----------------------------+
| Name | ImageId | CreationDate |
+-----------------------------------------------+------------------------+----------------------------+
| amzn-ami-hvm-2018.03.0.20200904.0-x86_64-gp2 | ami-021234069a5506633 | 2020-09-04T02:10:36.000Z |
| amzn-ami-hvm-2018.03.0.20200729.0-x86_64-gp2 | ami-034dad9bdb65ec34b | 2020-08-11T20:09:50.000Z |
+-----------------------------------------------+------------------------+----------------------------+
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Codecov Report
Merging #5581 into v2 will increase coverage by
0.00%. The diff coverage is100.00%.
@@ Coverage Diff @@
## v2 #5581 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 240 240
Lines 19025 19033 +8
=======================================
+ Hits 17725 17733 +8
Misses 1300 1300
| Impacted Files | Coverage Δ | |
|---|---|---|
| awscli/formatter.py | 95.90% <100.00%> (+0.15%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 9a88539...44f82b1. Read the comment docs.
Hi @kit494way, thanks for the PR. Is there a specific use case you have that requires this change?
I have no specific case. It is easier to read if the columns are in the same order as the query.
That makes sense. Though unlikely, we may need to consider if this will break any existing customers that expect the column headers to be in a certain order. Perhaps we may consider adding an additional flag (maybe something like --preserve-query-key-order).
Our team just put out a contribution guide detailing improvements to the contribution process. I have created issue #6941 for this PR to track customer demand for this feature. We will take another look at this once the issue receives 10 upvotes before moving this PR into the ready-for-review stage on our project board. The rationale for this can be found in the rationale section of the contribution guide. In the meantime, I'll mark this PR as a draft.
@justindho your link for #6941 is wrong and targets #6918 instead mistakenly.
@justindho your link for #6941 is wrong and targets #6918 instead mistakenly.
@adamency Thanks! I've fixed the link.
we may need to consider if this will break any existing customers that expect the column headers to be in a certain order
Any such use cases are arguably broken, as the current order is determined by whatever iteration order Python happens to use for whichever data structure boto happens to use. At the moment, it's alphabetical in English because it happens to be. One of the biggest rules we have to teach C and C++ programmers is not to depend on undefined or implementation-defined behavior, because then your code falls over when changing compilers. This is no different.
If you have customers with code that breaks with this patch, then they need to fix their code to stop assuming alphabetical-in-English order of columns. (Ideally, they would reorder the --query keys.)