PRQL / prql

PRQL is a modern language for transforming data — a simple, powerful, pipelined SQL replacement
https://prql-lang.org
Apache License 2.0
9.58k stars 208 forks source link

Comment migration support #4650

Closed PorcoRosso85 closed 1 week ago

PorcoRosso85 commented 1 week ago

What's up?

Summary: Currently prql removes comments when compiling. It would be nice to be able to choose whether to remove them as before when compiling or to migrate comments to the SQL being compiled.

Motivation: Some web application developers like myself might use comments in the SQL when migrating or integrating code with applications prql may not be primarily targeted at oltp, but I get the impression that there is a lot of demand for the above features.

max-sixty commented 1 week ago

I think the concept would be v useful.

How coud it work?

We have a nascent concept of doc comments with #! (for example https://github.com/PRQL/prql/blob/e4a7ded60f0d3b53a8d8c9475d4222df76f8c4c9/prqlc/prqlc-parser/src/lexer/test.rs#L108). Would it be reasonable to just take those and paste them at the top of the output?

I think it might be really hard to follow every single item through the compilation, since there's not always a 1:1 mapping — or at least it would be too big a first step.

PorcoRosso85 commented 1 week ago

I am not familiar enough with lexers to know if I am getting the intent,

but I think a 1:1 mapping like 1 query 1 comment would be useful enough.

richb-hanover commented 1 week ago

I have always wondered whether it might be possible to retain comments in the generated SQL. (I tend to write mini-essays at the top of my queries and then sprinkle comments through the query to remind myself of what I'm doing/where I'm going. See for example: https://github.com/TaxFairness/TaxFairness/blob/main/PRQL_Queries/CleanScrapedDataView.prql )

But I have also always had trouble understanding how to tie any comments from the PRQL query above to the intermediate table_0 and table_1 and the associated machinery in the resulting SQL statements.

Do you have any suggestions how those comments could be mapped into the SQL? Thanks

aljazerzen commented 1 week ago

This is a duplicate of #2942. I'm closing this issue, but please do continue the conversation there.