Skip to content
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

trdsql: add page #14896

Merged
merged 14 commits into from
Nov 26, 2024
Merged

trdsql: add page #14896

merged 14 commits into from
Nov 26, 2024

Conversation

vanvuvuong
Copy link
Contributor

  • The page(s) are in the correct platform directories: common, linux, osx, windows, sunos, android, etc.
  • The page(s) have at most 8 examples.
  • The page description(s) have links to documentation or a homepage.
  • The page(s) follow the content guidelines.
  • The page(s) follow the style guide.
  • The PR title conforms to the recommended templates.
  • Version of the command being documented (if known):

@github-actions github-actions bot added the new command Issues requesting creation of a new page. label Nov 18, 2024
@vanvuvuong vanvuvuong mentioned this pull request Nov 18, 2024
6 tasks
Comment on lines 4 to 5
> More information: <https://noborus.github.io/trdsql/>.
> See also: `yq`, `jq`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> More information: <https://noborus.github.io/trdsql/>.
> See also: `yq`, `jq`
> See also: `yq`, and `jq`.
> More information: <https://noborus.github.io/trdsql/>.


- Convert array data from a JSON file to a CSV file (with double quote):

`trdsql -ocsv "SELECT * FROM example.json" | sed 's/\([^,]*\)/"&"/g' > example.csv`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`trdsql -ocsv "SELECT * FROM example.json" | sed 's/\([^,]*\)/"&"/g' > example.csv`
`trdsql -ocsv "SELECT * FROM example.json" | sed 's/\([^,]*\)/"&"/g' > {{path/to/file.csv}}`


- Convert object data from multiple JSON files to a CSV file (with double quote):

`trdsql -ocsv "SELECT * FROM example/*.json" | sed 's/\([^,]*\)/"&"/g' > example.csv`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`trdsql -ocsv "SELECT * FROM example/*.json" | sed 's/\([^,]*\)/"&"/g' > example.csv`
`trdsql -ocsv "SELECT * FROM example/*.json" | sed 's/\([^,]*\)/"&"/g' > {{path/to/file.csv}}`


- Cross join 2 csv files:

`trdsql "SELECT * FROM a.csv CROSS JOIN b.csv"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`trdsql "SELECT * FROM a.csv CROSS JOIN b.csv"`
`trdsql "SELECT * FROM {{path/to/file1.csv}} CROSS JOIN {{path/to/file2.csv}}"`


- Create table data to MySQL database from CSV file:

`trdsql -driver mysql -dsn "noborus:noborus@/trdsql_test" -ih "CREATE TABLE fruits (num int, name varchar(20)) AS SELECT id AS num,name FROM header.csv"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`trdsql -driver mysql -dsn "noborus:noborus@/trdsql_test" -ih "CREATE TABLE fruits (num int, name varchar(20)) AS SELECT id AS num,name FROM header.csv"`
`trdsql -driver mysql -dsn "noborus:noborus@/trdsql_test" -ih "CREATE TABLE fruits (num int, name varchar(20)) AS SELECT id AS num,name FROM {{path/to/file.csv}}"`


- Simple showing data from compress log files:

`trdsql -iltsv "SELECT * FROM access.log.2.gz"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`trdsql -iltsv "SELECT * FROM access.log.2.gz"`
`trdsql -iltsv "SELECT * FROM {{path/to/access.log.gz}}"`

@kbdharun kbdharun changed the title trdsql: add trdsql page trdsql: add page Nov 18, 2024
@vanvuvuong
Copy link
Contributor Author

Updated all the suggestions

@tldr-bot
Copy link

The build for this PR failed with the following error(s):

pages/common/trdsql.md:
Error: Parse error on line 28:
.../header_file.csv}}"`"`- Simple showing
-----------------------^
Expecting 'NEWLINE', 'TEXT', 'DASH', 'BACKTICK', got 'COMMAND_TEXT'

Please fix the error(s) and push again.

@@ -0,0 +1,32 @@
# trdsql

> CLI tool that executes SQL on CSV, LTSV, JSON, YAML, TBLN files.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> CLI tool that executes SQL on CSV, LTSV, JSON, YAML, TBLN files.
> CLI tool that executes SQL on CSV, LTSV, JSON, YAML, and TBLN files.


- Convert object data from multiple JSON files to a CSV file with header (`-oh`) & double quote:

`trdsql -ocsv -oh "SELECT * FROM {{path/to/file/*.json}}" | sed 's/\([^,]*\)/"&"/g' > {{path/to/file.csv}}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`trdsql -ocsv -oh "SELECT * FROM {{path/to/file/*.json}}" | sed 's/\([^,]*\)/"&"/g' > {{path/to/file.csv}}`
`trdsql -ocsv -oh "SELECT * FROM {{path/to/file/*.json}}" | sed 's/\([^,]*\)/"&"/g' > {{path/to/file.csv}}`


- Merge content of 2 CSV files to one CSV file:

`trdsql "SELECT column1, colum2 FROM {{path/to/file1.csv}} UNION SELECT column1,column2 FROM {{path/to/file2.csv}}"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`trdsql "SELECT column1, colum2 FROM {{path/to/file1.csv}} UNION SELECT column1,column2 FROM {{path/to/file2.csv}}"`
`trdsql "SELECT {{column1,colum2}} FROM {{path/to/file1.csv}} UNION SELECT {{column1,column2}} FROM {{path/to/file2.csv}}"`


- Complex SQL data manipulation with multiple CSV files with first line is header (`-ih`):

`trdsql -icsv -ih "SELECT id,name,phone_number FROM {{path/to/file*.csv}} WHERE phone_number != '' ORDER BY id GROUP BY field1"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`trdsql -icsv -ih "SELECT id,name,phone_number FROM {{path/to/file*.csv}} WHERE phone_number != '' ORDER BY id GROUP BY field1"`
`trdsql -icsv -ih "{{SELECT id,name,phone_number FROM {{path/to/file*.csv}} WHERE phone_number != '' ORDER BY id GROUP BY field1}}"`

pages/common/trdsql.md Outdated Show resolved Hide resolved
@spageektti
Copy link
Member

Can you please convert all examples to be in imperative mood? See style guide

@vanvuvuong
Copy link
Contributor Author

I just updated, please review


`trdsql "SELECT * FROM {{path/to/file.json}}::.list`

- Complex SQL data manipulation with multiple CSV files with first line is header (`-ih`):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Complex SQL data manipulation with multiple CSV files with first line is header (`-ih`):
- Manipulate Complex SQL data with multiple CSV files with first line is header (`-ih`):


`trdsql "SELECT {{column1,colum2}} FROM {{path/to/file1.csv}} UNION SELECT {{column1,column2}} FROM {{path/to/file2.csv}}"`

- Simple connection to PostgreSQL database:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Simple connection to PostgreSQL database:
- Connect to PostgreSQL database:


`trdsql -driver mysql -dsn "noborus:noborus@/trdsql_test" -ih "CREATE TABLE {{table}} ({{column1}} int, {{colum2}} varchar(20)) AS SELECT {{column3}} AS {{column1}},{{column2}} FROM {{path/to/header_file.csv}}"`

- Simple showing data from compress log files:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Simple showing data from compress log files:
- Show data from compress log files:


- Create table data to MySQL database from CSV file:

`trdsql -driver mysql -dsn "noborus:noborus@/trdsql_test" -ih "CREATE TABLE {{table}} ({{column1}} int, {{colum2}} varchar(20)) AS SELECT {{column3}} AS {{column1}},{{column2}} FROM {{path/to/header_file.csv}}"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the -dsn parameter is a placeholder.

Copy link
Member

@gutjuri gutjuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, two sggestions

> Execute SQL on CSV, LTSV, JSON, YAML, and TBLN files.
> More information: <https://noborus.github.io/trdsql/>.

- Convert object data from multiple JSON files to a CSV file with header (`-oh`) & double quote:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Convert object data from multiple JSON files to a CSV file with header (`-oh`) & double quote:
- Convert object data from multiple JSON files to a CSV file with header (`-oh`) and double quote:


`trdsql -ocsv -oh "SELECT * FROM {{path/to/file/*.json}}" | sed 's/\([^,]*\)/"&"/g' > {{path/to/file.csv}}`

- Interpret JSON list as a table & put object inside as columns (path/to/file.json: `{"list":[{"age":"26","name":"Tanaka"}]}`):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Interpret JSON list as a table & put object inside as columns (path/to/file.json: `{"list":[{"age":"26","name":"Tanaka"}]}`):
- Interpret JSON list as a table and put objects inside as columns (path/to/file.json: `{"list":[{"age":"26","name":"Tanaka"}]}`):

@vanvuvuong
Copy link
Contributor Author

Thank you for your comments, I just fixed, please tag me if there are somethings that need to change.

@spageektti spageektti merged commit d52d4ce into tldr-pages:main Nov 26, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new command Issues requesting creation of a new page.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants