Skip to content

Commit

Permalink
Hi, The regex group capture for matching the TO database is missing i…
Browse files Browse the repository at this point in the history
…n case the table names are enclosed in a "`". This further leads to wrong restore of materialized views(the TO still point to default database!).

Restore command used:
clickhouse-backup restore_remote --rm -m praveen:default <backup-name>

For example:- If we run the following restore command, the resulting materialized view will be the following.

CREATE MATERIALIZED VIEW praveen.`32da477b_0eb9_4aa6_bcbb_7f511649861e_v0_5_min_mv_shard` TO default.`32da477b_0eb9_4aa6_bcbb_7f511649861e_v0_5_min_mv_inner_shard`
(

    `__created_at` AggregateFunction(max,
 DateTime),

    `__occurred_at` DateTime,

    `environment_id` UUID,

    `aggregation` String,

    `value` AggregateFunction(sum,
 Float64)
) AS
SELECT
    maxState(__created_at) AS __created_at,

    toStartOfFiveMinute(__occurred_at) AS __occurred_at,

    environment_id,

    aggregation,

    sumState(value) AS value
FROM praveen.`32da477b_0eb9_4aa6_bcbb_7f511649861e_v0_5_min_shard`
GROUP BY
    environment_id,

    aggregation,

    __occurred_at
ORDER BY
    environment_id ASC,

    aggregation ASC,

    __occurred_at ASC;

The expected one:-

CREATE MATERIALIZED VIEW praveen.`32da477b_0eb9_4aa6_bcbb_7f511649861e_v0_5_min_mv_shard` TO praveen.`32da477b_0eb9_4aa6_bcbb_7f511649861e_v0_5_min_mv_inner_shard`
(

    `__created_at` AggregateFunction(max,
 DateTime),

    `__occurred_at` DateTime,

    `environment_id` UUID,

    `aggregation` String,

    `value` AggregateFunction(sum,
 Float64)
) AS
SELECT
    maxState(__created_at) AS __created_at,

    toStartOfFiveMinute(__occurred_at) AS __occurred_at,

    environment_id,

    aggregation,

    sumState(value) AS value
FROM praveen.`32da477b_0eb9_4aa6_bcbb_7f511649861e_v0_5_min_shard`
GROUP BY
    environment_id,

    aggregation,

    __occurred_at
ORDER BY
    environment_id ASC,

    aggregation ASC,

    __occurred_at ASC;
  • Loading branch information
praveenthuwat committed Jun 30, 2024
1 parent 100d30a commit 3e87f21
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/backup/table_pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (b *Backuper) enrichTablePatternsByInnerDependencies(metadataPath string, t
return tablePatterns, nil
}

var queryRE = regexp.MustCompile(`(?m)^(CREATE|ATTACH) (TABLE|VIEW|LIVE VIEW|MATERIALIZED VIEW|DICTIONARY|FUNCTION) (\x60?)([^\s\x60.]*)(\x60?)\.([^\s\x60.]*)(?:( UUID '[^']+'))?(?:( TO )(\x60?)([^\s\x60.]*)(\x60?)(\.))?(?:(.+FROM )(\x60?)([^\s\x60.]*)(\x60?)(\.))?`)
var queryRE = regexp.MustCompile(`(?m)^(CREATE|ATTACH) (TABLE|VIEW|LIVE VIEW|MATERIALIZED VIEW|DICTIONARY|FUNCTION) (\x60?)([^\s\x60.]*)(\x60?)\.\x60?([^\s\x60.]*)\x60?( UUID '[^']+')?(?:( TO )(\x60?)([^\s\x60.]*)(\x60?)(\.))?(?:(.+FROM )(\x60?)([^\s\x60.]*)(\x60?)(\.))?`)
var createOrAttachRE = regexp.MustCompile(`(?m)^(CREATE|ATTACH)`)
var uuidRE = regexp.MustCompile(`UUID '([a-f\d\-]+)'`)

Expand Down

0 comments on commit 3e87f21

Please sign in to comment.