Preserve the order of keys in the output table
- Dominant language
- Python
- Stars
- 17.3k
- Forks
- 4.6k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 13
Description
### Describe the feature
Currently, when performing a query and setting the output format to 'table', the order of the query keys is not preserved. For example, we can see in this example that the order the query keys (`Name`, `ImageId`, `CreationDate`) differs from the order of the column headers in the output table (`CreationDate`, `ImageId`, `Name`).
```
$ 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 |
+---------------------------+------------------------+------------------------------------------------+
```
The feature would add support for preserving the order of keys specified in a query in the output table. For example, if the keys in the query are specified in order of `Name`, `ImageId`, and `CreationDate`, the order of the columns in the output table would be `Name`, `ImageId`, and `CreationDate`.
```
$ 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 |
+-----------------------------------------------+------------------------+----------------------------+
```
### Use Case
When running commands with `--output table`, the output should be easier to read. Having the output columns rendered in the order that I've specified in the query would help readability.
### Proposed Solution
#5581
### Other Information
_No response_
### Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### CLI version used
any
### Environment details (OS name and version, etc.)
any
Contributor guide
Assessment
This issue has not been assessed yet.