-
Notifications
You must be signed in to change notification settings - Fork 222
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
feat: CLI command to autogenerate JSON Schema for PL, RQ and lineage #4698
Conversation
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 looks good!
Could we add a small test? A bit like the one in the PR description. There are examples of CLI insta tests by searching for prqlc_command()
.
We could also add a changelog entry as it's user-facing
Thanks @kgutwin!
prqlc/prqlc/src/cli/mod.rs
Outdated
@@ -266,6 +274,13 @@ enum Format { | |||
Yaml, | |||
} | |||
|
|||
#[derive(clap::ValueEnum, Clone, Debug)] | |||
enum SchemaType { |
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.
Not super important but I wonder if there's a better name for this — it's essentially each intermediate representation — maybe --ir
for intermediate representation, or --repr
? Or fine to leave and we can change in the future
Great feedback! I put together a small test and renamed the flag to As a related question (towards the underlying purpose of this PR) I am wondering what you think about adding automated code generation to this repo, for the purposes of keeping type hints for the bindings in sync with the gradual evolution of PRQL's IRs. In my main project now, we use Pre-commit hooks to trigger a re-run of client code generation whenever our backend's OpenAPI spec is updated. This works really well, as the hooks ensure that a commit with changes to the backend will also include the corresponding changes to the frontend and other client libraries. If PRQL were to adopt the same general practice, it would involve adding one or two pre-commit hooks:
If you think this approach would work for PRQL, I can put it together as a PR for review. If you have other opinions or thoughts, I'm happy to accommodate. Thanks! |
(forgive the delay; just got back from vacation)
Storing them in the repo is a great idea (one of the reasons we like snapshots a lot!)
This sounds interesting. I don't have much experience with these so don't know how well they work. IIUC most folks using bindings aren't going deep in the AST (vs. just compiling to SQL), but if this would be helpful + the tools are good — in particular if they don't impose a cost on those just compiling to SQL, would be very open to it. Thanks @kgutwin ! |
This PR adds the command
prqlc debug json-schema --schema-type TYPE
. When run, this dumps a JSON Schema document for the provided type (currentlypl
,rq
, andlineage
).Example:
The longer-term goal behind adding this as a feature is to find a way to auto-generate type hints for library integrations (Python, TypeScript, etc.) However, this may also be useful as a debugging or documentation tool.