Skip to content

How to structure different dialects #367

Closed

Description

@max-sixty

Continuing from #347

What's the best approach here? I'd propose we have a Trait in translator.rs which is implemented by each dialect — any thoughts?

Activity

  1. max-sixty commented on Apr 17, 2022

    @max-sixty
    MemberAuthor

    I had a quick go at including a struct in the definition of a Query, but got some rust type errors around object safety which I didn't take the time to figure out. Here's where I paused (but is maybe not even helpful to start from) https://github.com/prql/prql/compare/dialect

    One naive approach would be to keep the Enum we currently have, and then have a lookup to find the respective struct. Then the appropriate functions in translator.rs could part of a Trait which structs would implement. That seems worse than implementing them on the object which is a field of Query though.

  2. max-sixty commented on Apr 18, 2022

    @max-sixty
    MemberAuthor

    This also applies to versions.

    Are there approaches that won't lead to nD x nV implementations, where nD is the number of dialects and nV is the number of versions? Are there other libraries that do this well?

    The rust language manages editions — I haven't looked into the mechanics, but the basics are here. And sqlparser-rs has a nice simple way of handling dialects

  3. aljazerzen commented on Apr 18, 2022

    @aljazerzen
    Member

    Having dyn Dialect in AST will be quite painful because of serialization and de-serialization.

    What about having:

    trait DialectHandler {
       ...
    }
    
    enum Dialect { ... }
    
    impl DialectEnum {
      fn handler() -> Box<dyn DialectHandler> {
      }
    }

    so Dialect enum can be in AST, and DialectHandler trait is used for nice polymorphic behavior?

    I'm pushing such commit now, feel free to revert it.

  4. max-sixty commented on Apr 25, 2022

    @max-sixty
    MemberAuthor

    Closed by #398, thanks to @aljazerzen ; I'll open a new issue for versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions