Skip to content

Commit

Permalink
--partitions=(v1,'v2') could calculate wrong partition expression i…
Browse files Browse the repository at this point in the history
…f `system.columns` will return fields in different order than they described in PARTITION BY clause, fix #791 for embedded BACKUP
  • Loading branch information
Slach committed Nov 24, 2023
1 parent b66908c commit 53893c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion pkg/backup/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,15 @@ func (b *Backuper) createBackupEmbedded(ctx context.Context, backupName, tablePa
tablesSQL += "TABLE `" + table.Database + "`.`" + table.Name + "`"
tableSizeSQL += "'" + table.Database + "." + table.Name + "'"
if nameList, exists := partitionsNameList[metadata.TableTitle{Database: table.Database, Table: table.Name}]; exists && len(nameList) > 0 {
tablesSQL += fmt.Sprintf(" PARTITIONS '%s'", strings.Join(nameList, "','"))
partitionsSQL := ""
for _, partitionName := range nameList {
if strings.HasPrefix(partitionName, "(") {
partitionsSQL += partitionName + ","
} else {
partitionsSQL += "'" + partitionName + "',"
}
}
tablesSQL += fmt.Sprintf(" PARTITIONS %s", partitionsSQL[:len(partitionsSQL)-1])
}
if i < l {
tablesSQL += ", "
Expand Down
2 changes: 1 addition & 1 deletion test/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2032,7 +2032,7 @@ func testBackupSpecifiedPartitions(t *testing.T, r *require.Assertions, ch *Test
r.NoError(dockerExec("clickhouse-backup", "clickhouse-backup", "-c", "/etc/clickhouse-backup/"+backupConfig, "delete", "local", fullBackupName))

// check create + partitions
r.NoError(dockerExec("clickhouse-backup", "clickhouse-backup", "-c", "/etc/clickhouse-backup/"+backupConfig, "create", "--tables="+dbName+".t1", "--partitions=0-20220102,0-20220103", partitionBackupName))
r.NoError(dockerExec("clickhouse-backup", "clickhouse-backup", "-c", "/etc/clickhouse-backup/"+backupConfig, "create", "--tables="+dbName+".t1", "--partitions=(0,'2022-01-02'),(0,'2022-01-03')", partitionBackupName))
partitionBackupDir := "/var/lib/clickhouse/backup/" + partitionBackupName + "/shadow/" + dbName + "/t1/default/"
if strings.HasPrefix(remoteStorageType, "EMBEDDED") {
partitionBackupDir = "/var/lib/clickhouse/disks/backups" + strings.ToLower(strings.TrimPrefix(remoteStorageType, "EMBEDDED")) + "/" + partitionBackupName + "/data/" + dbName + "/t1"
Expand Down

0 comments on commit 53893c1

Please sign in to comment.