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

[WIP] Add baseline infrastructure for emulating materialized views #56

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

amotl
Copy link
Member

@amotl amotl commented Oct 10, 2023

What the title says. Description will be expanded while we go.

Comment on lines +52 to +55
# FIXME: SQLParseException[Target table name must not include a schema]
sql_ddl = f"ALTER TABLE {mview.staging_table_fullname} RENAME TO {mview.table_name}"
logger.info(f"Activating materialized view: {sql_ddl}")
self.store.execute(sa.text(sql_ddl))
Copy link
Member Author

@amotl amotl Oct 10, 2023

Choose a reason for hiding this comment

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

This needs a ticket in crate/crate, about that currently, you can't rename a table "into a different schema", i.e. it will always be doc.

Copy link
Member Author

@amotl amotl Oct 10, 2023

Choose a reason for hiding this comment

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

It looks like resolving this issue might not be too difficult. If someone has the capacity to file a corresponding issue at crate/crate, I will appreciate it. /cc @hammerhead, @hlcianfagna 🌻

// we do not support renaming to a different schema, thus the target table identifier must not include a schema
// this is an artificial limitation, technically it can be done
List<String> newIdentParts = node.newName().getParts();
if (newIdentParts.size() > 1) {
    throw new IllegalArgumentException("Target table name must not include a schema");
}

-- https://github.com/crate/crate/blob/5.4.3/server/src/main/java/io/crate/analyze/AlterTableAnalyzer.java#L96C1-L102C10

Copy link
Member Author

Choose a reason for hiding this comment

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

@hlcianfagna suggested to use ALTER CLUSTER SWAP TABLE as a workaround at crate/crate#14833 (comment). Thank you.

Comment on lines +41 to +44
# TODO: IF NOT EXISTS
sql_ddl = f"CREATE TABLE {mview.staging_table_fullname} AS (\n{mview.sql}\n)"
logger.info(f"Creating materialized view (staging): {sql_ddl}")
self.store.execute(sa.text(sql_ddl))
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 is another spot where I discovered a shortcoming in SQL syntax: CREATE TABLE ... AS ... does not support the IF NOT EXISTS infix.

Copy link
Member Author

Choose a reason for hiding this comment

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

We filed a database issue about it.

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.

1 participant