From 77317154be6cc63476386d22bba86df201460714 Mon Sep 17 00:00:00 2001 From: Miles Maddox Date: Thu, 18 Feb 2021 16:25:24 -0600 Subject: [PATCH] documentation --- README.md | 20 ++++++++++---------- cmd/query.go | 2 +- lib/query.go | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 40f42eb..581cbb1 100644 --- a/README.md +++ b/README.md @@ -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--") - --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--") + --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 @@ -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 ` flag that will just download the results of a previous query if it is older than N minutes -- [ ] \ No newline at end of file +- [ ] Support a `--cached ` flag that will just download the results of a previous query if it is older than N minutes \ No newline at end of file diff --git a/cmd/query.go b/cmd/query.go index 0d24aa2..aa9018e 100644 --- a/cmd/query.go +++ b/cmd/query.go @@ -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.") } diff --git a/lib/query.go b/lib/query.go index 80c39e0..ef93f2f 100644 --- a/lib/query.go +++ b/lib/query.go @@ -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) @@ -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) @@ -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) @@ -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" }