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

Examples from the current playground do not parse in vscode extension v0.8.1 #273

Closed
kriswuollett opened this issue Jul 25, 2023 · 3 comments

Comments

@kriswuollett
Copy link
Contributor

kriswuollett commented Jul 25, 2023

Is the library used in the plugin v0.8.1 out of date, or is this another issue like #128?

Example:

from invoices                        # A PRQL query begins with a table
                                     # Subsequent lines "transform" (modify) it
derive {                             # "derive" adds columns to the result
  transaction_fee = 0.8,             # "=" sets a column name
  income = total - transaction_fee   # Calculations can use other column names
}
# starts a comment; commenting out a line leaves a valid query
filter income > 5                    # "filter" replaces both of SQL's WHERE & HAVING
filter invoice_date >= @2010-01-16   # Clear date syntax
group customer_id (                  # "group" performs the pipeline in (...) on each group
  aggregate {                        # "aggregate" reduces each group to a single row
    sum_income = sum income,         # ... using SQL SUM(), COUNT(), etc. functions
    ct = count customer_id,          #
  }
)
join c=customers (==customer_id)     # join on "customer_id" from both tables
derive name = f"{c.last_name}, {c.first_name}" # F-strings like Python
derive db_version = s"version()"     # S-string offers escape hatch to SQL
select {                             # "select" passes along only the named columns
  c.customer_id, name, sum_income, ct, db_version,
}                                    # trailing commas always ignored
sort {-sum_income}                   # "sort" sorts the result; "-" is decreasing order
take 1..10                           # Limit to a range - could also be "take 10"
#
# The "output.sql" tab at right shows the SQL generated from this PRQL query
# The "output.arrow" tab shows the result of the query

Preview SQL output:

Waiting for a PRQL file...
Error: 
   ╭─[:3:8]
   │
 3 │ derive {                             # "derive" adds columns to the result
   │        ┬  
   │        ╰── unexpected {
───╯

Expected SQL output:

WITH table_1 AS (
  SELECT
    customer_id,
    total - 0.8 AS _expr_0,
    invoice_date
  FROM
    invoices
),
table_0 AS (
  SELECT
    COALESCE(SUM(_expr_0), 0) AS sum_income,
    COUNT(*) AS ct,
    customer_id
  FROM
    table_1
  WHERE
    _expr_0 > 5
    AND invoice_date >= DATE '2010-01-16'
  GROUP BY
    customer_id
)
SELECT
  c.customer_id,
  CONCAT(c.last_name, ', ', c.first_name) AS name,
  table_0.sum_income,
  table_0.ct,
  version() AS db_version
FROM
  table_0
  JOIN customers AS c ON table_0.customer_id = c.customer_id
ORDER BY
  table_0.sum_income DESC
LIMIT
  10

-- Generated by PRQL compiler version:0.9.1 (https://prql-lang.org)
@kriswuollett
Copy link
Contributor Author

It seems like a major release is in progress for v0.9.x, e.g., v0.9.2. So I am assuming updated plugins and prqlc hasn't been published yet.

@max-sixty
Copy link
Member

Yes — unfortunately we hit HackerNews at the one time we had a major syntax change while some tools hadn't been upgraded.

I just put #274 in, which should fix this

@max-sixty
Copy link
Member

Closed by #274!

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

No branches or pull requests

2 participants