Skip to content

Commit

Permalink
documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
justmiles committed Feb 18, 2021
1 parent 20fb14b commit 7731715
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ Run SQL statements against Amazon Athena and return results to stdout
athena query --help
Flags:
-d, --database string Athena database to query (default "default")
-f, --format string format the output as either json, csv, or table (default "csv")
-h, --help help for query
--output-bucket string S3 bucket for Athena query results (default "aws-athena-query-results-<account>-<region>")
--output-prefix string S3 key prefix for Athena query results
-s, --sql string SQL query to execute. Can be a file or raw query
--statistics print query statistics to stderr
-d, --database string Athena database to query (default "default")
-f, --format string format the output as either json, csv, or table (default "csv")
-h, --help help for query
-o, --output string file name to write this content to. If empty, will write to stdout (default "")
--query-results-bucket string S3 bucket for Athena query results (default "aws-athena-query-results-<account>-<region>")
--query-results-prefix string S3 key prefix for Athena query results
-s, --sql string SQL query to execute. Can be a file or raw query
--statistics print query statistics to stderr
```

## Examples
Expand Down Expand Up @@ -118,10 +119,9 @@ EOF
## Roadmap

- [x] Support CSV, JSON, and ASCII table
- [ ] Add common partition-by-date feature
- [x] Add common partition-by-date feature
- [ ] Add `--workgroup` flag
- [ ] Support most flags as environment variables (workgroup, output location, output format)
- [x] Don't choke if query doesn't return results (MSCK REPAIR TABLE)
- [ ] SIGTERM or CTRL+C should cancel the query
- [ ] Support a `--cached <n minutes>` flag that will just download the results of a previous query if it is older than N minutes
- [ ]
- [ ] Support a `--cached <n minutes>` flag that will just download the results of a previous query if it is older than N minutes
2 changes: 1 addition & 1 deletion cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func init() {
QueryCmd.PersistentFlags().StringVarP(&q.Database, "database", "d", "default", "Athena database to query")
QueryCmd.PersistentFlags().StringVarP(&q.SQL, "sql", "s", "", "SQL query to execute. Can be a file or raw query")
QueryCmd.PersistentFlags().StringVarP(&q.Format, "format", "f", "csv", "format the output as either json, csv, or table")
QueryCmd.PersistentFlags().StringVarP(&q.OutputFile, "output", "o", "stdout", "(optional) file name to write this content to")
QueryCmd.PersistentFlags().StringVarP(&q.OutputFile, "output", "o", "", "(optional) file name to write this content to (defaults to standard output)")
QueryCmd.PersistentFlags().BoolVar(&q.Statistics, "statistics", false, "print query statistics to stderr")
// QueryCmd.PersistentFlags().StringVar(&q.JMESPath, "jmespath", "", "optional JMESPath to further filter or format results. See jmespath.org for more.")
}
8 changes: 4 additions & 4 deletions lib/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (q *Query) RenderQueryResults(file *os.File) error {

output, _ := json.MarshalIndent(records, "", " ")

if q.OutputFile == "stdout" {
if q.OutputFile == "" {
fmt.Println(string(output))
} else {
return ioutil.WriteFile(q.OutputFile, output, 0644)
Expand All @@ -172,7 +172,7 @@ func (q *Query) RenderQueryResults(file *os.File) error {

var f *os.File

if q.OutputFile == "stdout" {
if q.OutputFile == "" {
f = os.Stdout
} else {
f, err = os.Create(q.OutputFile)
Expand Down Expand Up @@ -201,7 +201,7 @@ func (q *Query) RenderQueryResults(file *os.File) error {
return fmt.Errorf("Unable to read query results from %q, %v", file.Name(), err)
}

if q.OutputFile == "stdout" {
if q.OutputFile == "" {
fmt.Println(string(sb))
} else {
return ioutil.WriteFile(q.OutputFile, sb, 0644)
Expand Down Expand Up @@ -248,7 +248,7 @@ func (q *Query) RenderQueryResults(file *os.File) error {
f.SetCellStyle(sheetName, "A1", fmt.Sprintf("%s%d", lastColumn, 1), headerStyle)

// Ensure we write a .xlsx file
if q.OutputFile == "stdout" {
if q.OutputFile == "" {
q.OutputFile = "athena-query-results.xlsx"
}

Expand Down

0 comments on commit 7731715

Please sign in to comment.