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

feat: table declarations #4126

Merged
merged 8 commits into from
Jan 25, 2024
Merged

feat: table declarations #4126

merged 8 commits into from
Jan 25, 2024

Conversation

aljazerzen
Copy link
Member

@aljazerzen aljazerzen commented Jan 24, 2024

Closes #2646 with adding support for:

    module my_schema {
      let my_table <[{ id = int, a = text }]>
    }

    let another_table <[{ id = int, b = text }]>

    my_schema.my_table
    join another_table (==id)
    take 10

The rule is that any variable declaration with relational type and without an assigned value will be treated as a table in the database.

Fully qualified name is used to refer to that table. This will be changed soon.

@aljazerzen aljazerzen changed the title feat param vars feat: table declarations Jan 24, 2024
Comment on lines +28 to +33
/// All table references must reside within module at `database_module_path`.
/// They are compiled to table identifiers, using their path relative to the database module.
/// For example, with `database_module_path=my_database`:
/// - `my_database.my_table` will compile to `"my_table"`,
/// - `my_database.my_schema.my_table` will compile to `"my_schema.my_table"`,
/// - `my_table` will error out saying that this table does not reside in current database.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the utility of this? Relative to leaving them as they're specified in the query? (not claiming confidently that there isn't an advantage!)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or this will obviate the need for this?

Fully qualified name is used to refer to that table. This will be changed soon.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds an ability to specify a module as a "database module":

module my_database {
    module my_schema {
        let my_table <[{}]>   # this will be `my_schema.my_table`
    }
}

module another_database {
    let another_table <[{}]>  # this will be `another_database`
}

The problem is that these two tables are defined in two different databases, so they cannot be present in the same query. That's why "current database" is a compiler parameter, so it knows for which database it is compiling for.

Idea being that in the future, we could support querying multiple databases, so PRQL source would compile into multiple queries that would be sent to each of the databases.

prqlc/prqlc-ast/src/error.rs Outdated Show resolved Hide resolved
@aljazerzen aljazerzen enabled auto-merge (squash) January 25, 2024 09:30
@aljazerzen aljazerzen merged commit 461741a into main Jan 25, 2024
35 checks passed
@aljazerzen aljazerzen deleted the feat-param-vars branch January 25, 2024 10:39
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

Successfully merging this pull request may close these issues.

Table types
2 participants