Skip to content

Transpiling from SQL to PRQL #130

Open

Description

@max-sixty

This is a longer-term idea — but now we're using sqlparser to write SQL, we could also use it to read SQL and produce PRQL.

We'd need to write:

  1. a fairly simple compiler from sqlparser AST to PRQL AST
  2. Display implementations which convert PRQL AST to PRQL code

This would be useful for people transitioning from SQL. At least initially, the main users are likely to be engineers who are frustrated by SQL because they've written a lot of it.

We wouldn't need to support all of SQL for it to be useful — there's a fairly small subset that's used a lot — and possibly a larger subset which we could implement with s-strings.

We also wouldn't need to automatically do things like variable "creation" (e.g. replacing salary + payroll_tax + benefits_cost with gross_cost), which would be much more difficult (but great if we could!).

Activity

  1. added this to the 0.3 milestone on May 14, 2022
  2. aljazerzen commented on Jun 29, 2022

    @aljazerzen
    Member

    Update: this is currently not possible yet, but we are not far off.

    The Display trait for prql's AST Node is done, we just need to parse SQL and convert it to AST, which should't be a major problem.

  3. ryanrussell commented on Jun 29, 2022

    @ryanrussell
    Contributor

    A SQL -> PRQL transpiler would REALLY ease adoption for PRQL.

    Even if it had some disclaimers, it lowers a lot of barriers if a new user is trying to learn/adopt PRQL and could copy/paste a bunch of SQL queries.

  4. florent-martineau commented on Jul 4, 2022

    @florent-martineau

    Using Apache Calcite for parsing queries and turning them into an AST could be an idea.

    Calcite is written in Java, though, and not in Rust.

  5. max-sixty commented on Jul 4, 2022

    @max-sixty
    MemberAuthor

    We'd likely use sqlparser-rs, which we currently use to represent SQL AST, and it builds the SQL string.

  6. modified the milestones: 0.3, 0.5 on Dec 21, 2022
  7. removed this from the 0.9 milestone on Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions