-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Allow multiple input files for execution in CLI #27544
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
base: master
Are you sure you want to change the base?
Conversation
…ests and options Signed-off-by: Harsh Mehta <harshmehta010102@gmail.com>
|
The commit title is too long. https://trino.io/development/process.html#pull-request-and-commit-guidelines- |
|
|
||
| @Option(names = {"-f", "--file"}, paramLabel = "<file>", description = "Execute statements from file and exit") | ||
| public String file; | ||
| @Option(names = {"-f", "--file"}, paramLabel = "<file>", description = "Execute statements from file and exit (can be used multiple times)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update cli.md file too?
| } | ||
| catch (IOException e) { | ||
| throw new RuntimeException(format("Error reading from file %s: %s", clientOptions.file, e.getMessage())); | ||
| throw new RuntimeException(format("Error reading from file: %s", e.getMessage())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to report the failed file name.
| { | ||
| Console console = createConsole("--file", "file1.sql", "--file", "file2.sql", "--file", "file3.sql"); | ||
| ClientOptions options = console.clientOptions; | ||
| assertThat(options.files).isEqualTo(ImmutableList.of("file1.sql", "file2.sql", "file3.sql")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add another 2 test cases?
- file1.sql, file3.sql, file2.sql - to ensure the specified order - not alphabetical
- file1.sql, file1.sql - repeated files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your feedback, Could you please advise on If duplicate files are identified, we will append both files accordingly am I right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HarshMehta112 I think you are right, each specified time of file should be treated independently
Signed-off-by: Harsh Mehta <harshmehta010102@gmail.com>
|
|
||
| @Option(names = {"-f", "--file"}, paramLabel = "<file>", description = "Execute statements from file and exit") | ||
| public String file; | ||
| @Option(names = {"-f", "--file"}, paramLabel = "<file>", description = "Execute statements from file and exit (can be used multiple times)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(can be used multiple times) is not needed. I'd change paramLabel to <files> and description Execute statements from files and exit
| ClientSession session = clientOptions.toClientSession(uri); | ||
| boolean hasQuery = clientOptions.execute != null; | ||
| boolean isFromFile = !isNullOrEmpty(clientOptions.file); | ||
| boolean isFromFile = !clientOptions.files.isEmpty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isFromFiles
| } | ||
| try { | ||
| query = asCharSource(new File(clientOptions.file), UTF_8).read(); | ||
| StringBuilder fileContents = new StringBuilder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect - we don't want to concatenate queries together
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wendigo I’m having trouble understanding what you meant. Could you please explain it in a bit more detail? Are you suggesting that I should execute the files one by one instead of appending them into a single string?
I’m new to open-source contributions, so I want to make sure I understand correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Files should be executed without concatenation
Fixes : #27532
Description
I've successfully implemented the feature to accept repeated --file options in the Trino CLI to run all files sequentially, as requested in issue.
Additional context and related issues
trino --catalog iceberg --schema default --file ddls.sql --file inserts.sqlThe CLI will:
Read the contents of ddls.sql
Read the contents of inserts.sql
Concatenate them with newlines
Execute all statements sequentially
The files are processed in the order they are specified on the command line, which is exactly what was requested in the issue.
Release notes
( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text: