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

fix(prqlc): allow prqlc compile | duckdb #2594

Merged
merged 8 commits into from
May 22, 2023
Merged

Conversation

eitsupi
Copy link
Member

@eitsupi eitsupi commented May 21, 2023

Fix comments displayed in interactive mode and make interactive mode output valid SQL output.
(It also fixes #2569)

This PR allows PRQL to be executed interactively by piping prqlc compile to duckdb, sqlite3, etc.

I have also added a note to the prqlc README on how to use the prqlc compile command, which I believe is the minimum required to try prqlc.
And this README also has been changed to appear in the book.

web/book/src/SUMMARY.md Outdated Show resolved Hide resolved
@eitsupi
Copy link
Member Author

eitsupi commented May 21, 2023

(By the way, I think a combination of prqlc and the DuckDB CLI seems more Unix-like and a better path than using the prql-query CLI with DuckDB built in......) (Related to PRQL/prql-query#22)

prqlc compile --target sql.duckdb | duckdb --json >output.json

Copy link
Member

@max-sixty max-sixty left a comment

Choose a reason for hiding this comment

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

Excellent, thanks a lot!

I added a couple of comments & suggestions, but otherwise good to go

prql-compiler/prqlc/README.md Outdated Show resolved Hide resolved
prql-compiler/prqlc/README.md Outdated Show resolved Hide resolved
prql-compiler/prqlc/README.md Show resolved Hide resolved
```sh
$ prqlc compile | duckdb
from `penguins.csv`
take 3
Copy link
Member

Choose a reason for hiding this comment

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

Hmmm, this doesn't work so well on mine — does it for you?

I think maybe we write the Ctrl-d to stdout?

prqlc compile | duckdb
from `penguins.csv`
take 3
Error: near line 1: Parser Error: syntax error at or near "Enter"
LINE 1: Enter PRQL, then ctrl-d:
        ^

(Is there a way of retaining the query? I worry this approach is OK but loses the query on each run. But it's still reasonable to show the example)

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems that the prqlc you are using was not built from this PR. (the prompt message is different)

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a way of retaining the query?

I believe the query will remain visible in the terminal as shown in this README, and I have verified that it works with bash and fish on Linux and PowerShell on Windows.

Copy link
Member

Choose a reason for hiding this comment

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

It seems that the prqlc you are using was not built from this PR. (the prompt message is different)

Sorry, you're correct, apologies

Copy link
Member

Choose a reason for hiding this comment

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

I believe the query will remain visible in the terminal as shown in this README, and I have verified that it works with bash and fish on Linux and PowerShell on Windows.

Yes!

A total aside — something @snth and I discussed on the dev call was building a TUI, similar to the playground, where typing a query would pipe through to duckdb on each keystroke, could be a good way of exploring a dataset from the terminal

@@ -292,7 +292,7 @@ impl Command {
// it's confusing whether it's waiting for input or not. This
// offers the prompt.
if input.is_stdin() && atty::is(atty::Stream::Stdin) {
println!("Enter PRQL, then ctrl-d:\n");
println!("# Enter PRQL, then press ctrl-d or ctrl-z (windows) to compile:\n");
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
println!("# Enter PRQL, then press ctrl-d or ctrl-z (windows) to compile:\n");
eprintln!("# Enter PRQL, then press ctrl-d or ctrl-z (windows) to compile:\n");

...I think this will solve the issue above

Copy link
Member

Choose a reason for hiding this comment

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

FYI we could use this approach to print the correct string:

#[cfg(not(unix))]

web/book/src/SUMMARY.md Outdated Show resolved Hide resolved
@max-sixty
Copy link
Member

(By the way, I think a combination of prqlc and the DuckDB CLI seems more Unix-like and a better path than using the prql-query CLI with DuckDB built in......)

I do think this is a great pattern, agree.

Copy link
Member

@aljazerzen aljazerzen left a comment

Choose a reason for hiding this comment

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

Looks good.

@eitsupi
Copy link
Member Author

eitsupi commented May 22, 2023

Thanks for your reviews!

I think I have addressed most of the comments, so I will merge this.
If additional updates are needed, I will open another PR.

@eitsupi eitsupi enabled auto-merge (squash) May 22, 2023 11:20
@eitsupi eitsupi merged commit 07d83ca into PRQL:main May 22, 2023
@eitsupi eitsupi deleted the prqlc-usage branch May 22, 2023 11:22
max-sixty added a commit to max-sixty/prql that referenced this pull request May 22, 2023
Thanks to @eitsupi for PRQL#2594. Here are a couple of suggestions for small improvements to the prompt to flup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

On Windows, I can't get out with ctrl-d from the input screen opened via prqlc compile
3 participants