diff --git a/output/clickhouse.go b/output/clickhouse.go index d7cdb889..a92bcd9d 100644 --- a/output/clickhouse.go +++ b/output/clickhouse.go @@ -580,8 +580,15 @@ func (c *ClickHouse) ChangeSchema(newKeys *sync.Map) (err error) { return } + var version string + if err = conn.QueryRow("SELECT Version()").Scan(&version); err != nil { + return + } alterTable := func(tbl, col string) error { - query := fmt.Sprintf("ALTER TABLE `%s`.`%s` %s %s SETTINGS alter_sync = 0;", c.dbName, tbl, onCluster, col) + query := fmt.Sprintf("ALTER TABLE `%s`.`%s` %s %s", c.dbName, tbl, onCluster, col) + if util.CompareClickHouseVersion(version, "23.3") >= 0 { + query += " SETTINGS alter_sync = 0" + } util.Logger.Info(fmt.Sprintf("executing sql=> %s", query), zap.String("task", taskCfg.Name)) return conn.Exec(query) } diff --git a/util/common.go b/util/common.go index 713308ee..c21be1d9 100644 --- a/util/common.go +++ b/util/common.go @@ -347,3 +347,24 @@ func TrySetValue(v1, v2 interface{}) bool { } return ok } + +func CompareClickHouseVersion(v1, v2 string) int { + s1 := strings.Split(v1, ".") + s2 := strings.Split(v2, ".") + for i := 0; i < len(s1); i++ { + if len(s2) <= i { + break + } + if s1[i] == "x" || s2[i] == "x" { + continue + } + f1, _ := strconv.Atoi(s1[i]) + f2, _ := strconv.Atoi(s2[i]) + if f1 > f2 { + return 1 + } else if f1 < f2 { + return -1 + } + } + return 0 +}