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

SQL to DDlog compiler produces uncompilable DDlog for some illegal SQL program #1061

Open
amytai opened this issue Aug 26, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@amytai
Copy link
Contributor

amytai commented Aug 26, 2021

SQL queries with HAVING clauses can get parsed correctly by the ddlog-sql front-end SQL compiler (i.e. Presto for now), but the translated DDlog program will fail to compile with the following error message:

error: program.dl:22.69-22.70: Unknown variable: v
(Tagg{.c = count,.col = (not vec_contains(vec_push_imm(vec_empty(), v.column3), (count > 64'sd2)))})
                                                                    ^

SQL statement:

create view v0 as SELECT COUNT(column2) AS c
    FROM t1
   JOIN t2 ON (t1.column1 = t2.column1)
GROUP BY t1.column1
HAVING ((COUNT(column2) > 2) NOT IN (t1.column3))

The DDlog compiler error happens because the SQL statement is missing a column reference to t1.column3 in the GROUP BY clause that is subsequently used in the HAVING clause.

In particular, the following SQL statement will translate to and compile successfully in DDlog:

create view v0 as SELECT COUNT(column2) AS c
    FROM t1
   JOIN t2 ON (t1.column1 = t2.column1)
GROUP BY t1.column1, t1.column3
HAVING ((COUNT(column2) > 2) NOT IN (t1.column3))

This is a request to improve error handling in the ddlog-sql compiler when such SQL statements are encountered.

@amytai amytai changed the title ddlog-sql: unknown columns in HAVING clause result in cryptic DDlog compiler errors SQL to DDlog compiler produces uncompilable DDlog for some illegal SQL program Aug 26, 2021
@mihaibudiu mihaibudiu added the enhancement New feature or request label Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants