fix: support column list before ENGINE in CREATE MATERIALIZED VIEW#1
Closed
sharadgaur wants to merge 1 commit into
Closed
fix: support column list before ENGINE in CREATE MATERIALIZED VIEW#1sharadgaur wants to merge 1 commit into
sharadgaur wants to merge 1 commit into
Conversation
ClickHouse SHOW CREATE TABLE for refreshable materialized views with
ENGINE (e.g. Memory) outputs the column list between REFRESH and ENGINE:
CREATE MATERIALIZED VIEW db1.mv_name
REFRESH EVERY 1 SECOND
(
col1 String,
col2 Int8
)
ENGINE = Memory
AS SELECT ...
The parser previously expected TO or ENGINE immediately after REFRESH
clauses. This adds support for the (columns) before ENGINE pattern by
parsing a TableSchemaClause when a left paren is encountered.
Added TableSchema field to CreateMaterializedView AST node and updated
FormatSQL to emit it before ENGINE.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The parser fails on
CREATE MATERIALIZED VIEWstatements where a column list appears between theREFRESHclause andENGINE. This is valid ClickHouse syntax produced bySHOW CREATE TABLEfor refreshable materialized views (RMVs) that use an engine likeMemoryinstead of aTOdestination table.Before (fails)
Error:
The parser expected either
TO <table>orENGINE = <engine>immediately after the REFRESH/SETTINGS/APPEND clauses, but ClickHouse places the column list(...)beforeENGINEin itsSHOW CREATE TABLEoutput.After (works)
The same SQL parses correctly. The column list is stored in the new
TableSchemafield onCreateMaterializedViewand preserved through format roundtrips.ClickHouse syntax reference
From the ClickHouse docs:
When no
TOclause is used (ENGINE-based MVs), ClickHouse'sSHOW CREATE TABLEoutputs the column definitions between REFRESH and ENGINE.Changes
parser/parser_view.go— Added acase p.matchTokenKind(TokenKindLParen)branch in the TO/ENGINE switch to parse the column list, then expect ENGINE after itparser/ast.go— AddedTableSchema *TableSchemaClausefield toCreateMaterializedViewfor column lists on ENGINE-based MVs (distinct fromDestination.TableSchemawhich is for TO-based MVs)parser/format.go— EmitTableSchemabeforeENGINEinFormatSQLTest
Added
create_materialized_view_rmv_engine_with_columns.sqlcovering the full syntax: REFRESH + column list + ENGINE + SETTINGS + DEFINER + COMMENT + subquery with window function. All existing tests pass.