-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Introduce \i
command to execute from a file
#3136
Conversation
\i
command to include files\i
command to execute from a file
Codecov Report
@@ Coverage Diff @@
## master #3136 +/- ##
==========================================
- Coverage 85.95% 85.88% -0.08%
==========================================
Files 291 291
Lines 52382 52758 +376
==========================================
+ Hits 45025 45309 +284
- Misses 7357 7449 +92
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Thanks for the contribution @turbo1912. It would be good if we could merge #3133 first then update this PR with the documentation changes. |
datafusion-cli/src/command.rs
Outdated
@@ -72,6 +76,22 @@ impl Command { | |||
.print_batches(&batches, now) | |||
.map_err(|e| DataFusionError::Execution(e.to_string())) | |||
} | |||
Self::Include(filename) => { | |||
if let Some(filename) = filename { | |||
let file = match File::open(filename) { |
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 we either use ?
or map_err
here rather than this match?
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.
I tried it out and it works great! Thanks @turbo1912
❯ \i /tmp/bar.sql
+---------------------+
| Int64(1) + Int64(2) |
+---------------------+
| 3 |
+---------------------+
(arrow_dev) alamb@MacBook-Pro-8:~/Software/arrow-datafusion/datafusion-cli$ cat /tmp/bar.sql
select 1+2;
@andygrove not sure if you think we need to update the docs in this PR or if we could do it as a follow on PR
datafusion-cli/src/command.rs
Outdated
let file = match File::open(filename) { | ||
Ok(file) => file, | ||
Err(error) => { | ||
return Err(DataFusionError::Execution(error.to_string())) | ||
} |
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.
Yeah, something like this perhaps?
let file = match File::open(filename) { | |
Ok(file) => file, | |
Err(error) => { | |
return Err(DataFusionError::Execution(error.to_string())) | |
} | |
let file = File::open(filename) | |
.map_err(|e| { | |
DataFusionError::Execution(format!("Error opening {:?} {}", filename, e)) | |
})?; |
As the e
doesn't contain the filename
This gives something like:
❯ \i /tmp/foo.dd
Execution error: Error opening "/tmp/foo.dd" No such file or directory (os error 2)
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.
thanks! yup of course, happy to add the documentation change as well :)
Either way is fine with me. |
Benchmark runs are scheduled for baseline = 23866cd and contender = 2aa0a98. 2aa0a98 is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
Which issue does this PR close?
Closes #1906.
Rationale for this change
(from the original issue):
Taking inspiration frompsql , it implements a \i command (not a command line argument) for this usecase. It includes a file:
https://www.postgresql.org/docs/13/app-psql.html