Skip to content

Conversation

@HarshMehta112
Copy link

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.sql

The 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:

…ests and options

Signed-off-by: Harsh Mehta <harshmehta010102@gmail.com>
@cla-bot cla-bot bot added the cla-signed label Dec 3, 2025
@ebyhr
Copy link
Member

ebyhr commented Dec 3, 2025

The commit title is too long. https://trino.io/development/process.html#pull-request-and-commit-guidelines-
Let's change to "Allow multiple input files for execution in CLI" or something.

@HarshMehta112 HarshMehta112 changed the title Allow multiple input files for execution in Console; update related tests and options Allow multiple input files for execution in CLI Dec 3, 2025

@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)")
Copy link
Member

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()));
Copy link
Member

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"));
Copy link
Member

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

Copy link
Author

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?

Copy link
Contributor

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>
@github-actions github-actions bot added the docs label Dec 3, 2025

@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)")
Copy link
Contributor

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();
Copy link
Contributor

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();
Copy link
Contributor

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

Copy link
Author

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.

Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

CLI: accept repeated --file option and run all the files sequentially

4 participants