Skip to content

Commit

Permalink
Merge pull request #720 from Altinity/less_strict_check_parts_columns
Browse files Browse the repository at this point in the history
fix too strict `system.parts_columns` check when backup create,
  • Loading branch information
Slach authored Aug 9, 2023
2 parents 0a2c71a + 6a223a0 commit 1c28c97
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ IMPROVEMENTS

BUG FIXES
- fix possible create backup failures during UNFREEZE not exists tables, affected 2.2.7+ version, fix [704](https://github.com/Altinity/clickhouse-backup/issues/704)
- fix too strict `system.parts_columns` check when backup create, exclude Enum and Tuple (JSON) and Nullable(Type) vs Type corner cases, fix [685](https://github.com/Altinity/clickhouse-backup/issues/685), fix [699](https://github.com/Altinity/clickhouse-backup/issues/699)

# v2.3.2
BUG FIXES
Expand Down
29 changes: 22 additions & 7 deletions pkg/clickhouse/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -1161,22 +1161,37 @@ func (ch *ClickHouse) CheckSystemPartsColumns(ctx context.Context, table *Table)
}
}
ch.isPartsColumnPresent = 1
isPartsColumnsInconsistent := make([]struct {
partColumnsDataTypes := make([]struct {
Column string `ch:"column"`
Types []string `ch:"uniq_types"`
}, 0)
partsColumnsSQL := "SELECT column, groupUniqArray(type) AS uniq_types " +
"FROM system.parts_columns " +
"WHERE active AND database=? AND table=? " +
"WHERE active AND database=? AND table=? AND type NOT LIKE 'Enum%' AND type NOT LIKE 'Tuple(%' " +
"GROUP BY column HAVING length(uniq_types) > 1"
if err := ch.SelectContext(ctx, &isPartsColumnsInconsistent, partsColumnsSQL, table.Database, table.Name); err != nil {
if err := ch.SelectContext(ctx, &partColumnsDataTypes, partsColumnsSQL, table.Database, table.Name); err != nil {
return err
}
if len(isPartsColumnsInconsistent) > 0 {
for i := range isPartsColumnsInconsistent {
ch.Log.Errorf("`%s`.`%s` have inconsistent data types %#v for \"%s\" column", table.Database, table.Name, isPartsColumnsInconsistent[i].Types, isPartsColumnsInconsistent[i].Column)
isPartColumnsInconsistentDataTypes := false
if len(partColumnsDataTypes) > 0 {
for i := range partColumnsDataTypes {
isNullablePresent := false
isNotNullablePresent := false
for _, dataType := range partColumnsDataTypes[i].Types {
if strings.Contains(dataType, "Nullable") {
isNullablePresent = true
} else {
isNotNullablePresent = true
}
}
if !isNullablePresent && isNotNullablePresent {
ch.Log.Errorf("`%s`.`%s` have inconsistent data types %#v for \"%s\" column", table.Database, table.Name, partColumnsDataTypes[i].Types, partColumnsDataTypes[i].Column)
isPartColumnsInconsistentDataTypes = true
}
}
if isPartColumnsInconsistentDataTypes {
return fmt.Errorf("`%s`.`%s` have inconsistent data types for active data part in system.parts_columns", table.Database, table.Name)
}
return fmt.Errorf("`%s`.`%s` have inconsistent data types for active data part in system.parts_columns", table.Database, table.Name)
}
return nil
}
Expand Down

0 comments on commit 1c28c97

Please sign in to comment.