From a479671e646c28dfadb9976f70705393234564b6 Mon Sep 17 00:00:00 2001 From: awatercolorpen Date: Fri, 27 Mar 2026 14:58:07 +0800 Subject: [PATCH 1/3] refactor: modernize Go syntax with range over integers - Replace traditional for loops with Go 1.22+ range over integers syntax - Updated files: api/models/graph.go, dictionary_splitter.go, dependency_graph.go, dictionary_adapter.go, dictionary_column.go - Improves code readability and aligns with modern Go best practices --- api/models/graph.go | 2 +- dependency_graph.go | 2 +- dictionary_adapter.go | 2 +- dictionary_column.go | 2 +- dictionary_splitter.go | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/api/models/graph.go b/api/models/graph.go index fd034fb..40ae459 100644 --- a/api/models/graph.go +++ b/api/models/graph.go @@ -5,7 +5,7 @@ type Graph map[string][]string func (g Graph) GetTree(current string) Graph { graph := Graph{} queue := []string{current} - for i := 0; i < len(queue); i++ { + for i := range len(queue) { k := queue[i] for _, v := range g[k] { queue = append(queue, v) diff --git a/dependency_graph.go b/dependency_graph.go index eaa58b7..821dae9 100644 --- a/dependency_graph.go +++ b/dependency_graph.go @@ -215,7 +215,7 @@ func (g *DependencyGraphBuilder) sort(key []string, key2Model func(string) iDepe queue = append(queue, k) } } - for i := 0; i < len(queue); i++ { + for i := range len(queue) { node := queue[i] for _, v := range graph[node] { inDegree[v]-- diff --git a/dictionary_adapter.go b/dictionary_adapter.go index a565ede..2603aa3 100644 --- a/dictionary_adapter.go +++ b/dictionary_adapter.go @@ -51,7 +51,7 @@ func GetDependencyTree(adapter IAdapter, current string) (models.Graph, error) { visit := map[string]bool{current: true} graph := models.Graph{current: nil} queue := []string{current} - for i := 0; i < len(queue); i++ { + for i := range len(queue) { node, err := adapter.GetSourceByKey(queue[i]) if err != nil { return nil, err diff --git a/dictionary_column.go b/dictionary_column.go index 691745c..8769050 100644 --- a/dictionary_column.go +++ b/dictionary_column.go @@ -111,7 +111,7 @@ func isSameColumnTables(t1, t2 []string) error { sort.Strings(t1) sort.Strings(t2) // TODO linq - for i := 0; i < len(t1); i++ { + for i := range len(t1) { if t1[i] != t2[i] { return fmt.Errorf("table is not same t1=%v, t2=%v", t1, t2) } diff --git a/dictionary_splitter.go b/dictionary_splitter.go index fe14fdf..e0e0af0 100644 --- a/dictionary_splitter.go +++ b/dictionary_splitter.go @@ -290,7 +290,7 @@ func (n *NormalClauseSplitter) buildDimensionJoin() []*types.Join { } ds1, dl1, ds2, dl2 := v.Get1().DataSource, v.Get1().Dimension, v.Get2().DataSource, v.Get2().Dimension var on []*types.JoinOn - for i := 0; i < len(dl1); i++ { + for i := range len(dl1) { k1 := fmt.Sprintf("%v.%v", ds1, dl1[i]) k2 := fmt.Sprintf("%v.%v", ds2, dl2[i]) d1, _ := dGraph.GetDimension(k1) From f4e8c9a05b6b154a0102ea927b47508e19201617 Mon Sep 17 00:00:00 2001 From: awatercolorpen Date: Tue, 31 Mar 2026 14:56:39 +0800 Subject: [PATCH 2/3] fix: revert dynamic-queue loops to classic form to avoid range-len BFS bug The BFS/topological-sort loops in: - api/models/graph.go (GetTree) - dependency_graph.go (sort) - dictionary_adapter.go (GetDependencyTree) grow their queues inside the loop body, so 'for i := range len(queue)' is incorrect (range evaluates len once at entry). Restore these to 'for i := 0; i < len(queue); i++' which re-evaluates len each iteration. Static-length loops in dictionary_column.go and dictionary_splitter.go are safe to keep as 'for i := range len(...)'. All tests pass. --- api/models/graph.go | 3 ++- dependency_graph.go | 2 +- dictionary_adapter.go | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/api/models/graph.go b/api/models/graph.go index 40ae459..188ae5d 100644 --- a/api/models/graph.go +++ b/api/models/graph.go @@ -5,7 +5,7 @@ type Graph map[string][]string func (g Graph) GetTree(current string) Graph { graph := Graph{} queue := []string{current} - for i := range len(queue) { + for i := 0; i < len(queue); i++ { k := queue[i] for _, v := range g[k] { queue = append(queue, v) @@ -14,3 +14,4 @@ func (g Graph) GetTree(current string) Graph { } return graph } + diff --git a/dependency_graph.go b/dependency_graph.go index 821dae9..eaa58b7 100644 --- a/dependency_graph.go +++ b/dependency_graph.go @@ -215,7 +215,7 @@ func (g *DependencyGraphBuilder) sort(key []string, key2Model func(string) iDepe queue = append(queue, k) } } - for i := range len(queue) { + for i := 0; i < len(queue); i++ { node := queue[i] for _, v := range graph[node] { inDegree[v]-- diff --git a/dictionary_adapter.go b/dictionary_adapter.go index 2603aa3..a565ede 100644 --- a/dictionary_adapter.go +++ b/dictionary_adapter.go @@ -51,7 +51,7 @@ func GetDependencyTree(adapter IAdapter, current string) (models.Graph, error) { visit := map[string]bool{current: true} graph := models.Graph{current: nil} queue := []string{current} - for i := range len(queue) { + for i := 0; i < len(queue); i++ { node, err := adapter.GetSourceByKey(queue[i]) if err != nil { return nil, err From d6534fc174d3f831ae0d99694fb7809b7db5c957 Mon Sep 17 00:00:00 2001 From: awatercolorpen Date: Tue, 31 Mar 2026 15:00:04 +0800 Subject: [PATCH 3/3] ci: upgrade Go version in workflows from 1.18 to 1.24 The Go modernization syntax PR uses 'for i := range len(...)' (Go 1.22+), but the CI workflows still specified go-version: 1.18, causing build failures. Update both go.yml and clickhouse.yml to use Go 1.24 to match go.mod. --- .github/workflows/clickhouse.yml | 2 +- .github/workflows/go.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/clickhouse.yml b/.github/workflows/clickhouse.yml index 2efae3d..29b326e 100644 --- a/.github/workflows/clickhouse.yml +++ b/.github/workflows/clickhouse.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.18 + go-version: 1.24 - name: ClickHouse in GitHub Actions uses: EpicStep/clickhouse-github-action@v1.0.0 diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 9dab670..1cd6448 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.18 + go-version: 1.24 - name: Build run: go build -v ./...