From bc5c10e902a3d8e99d0319854d5e26d53c7b2c5d Mon Sep 17 00:00:00 2001 From: gongna1 Date: Tue, 24 Sep 2024 17:00:48 +0800 Subject: [PATCH 01/11] feature:Setting up CodeQL analysis --- .github/workflows/codeql-analysis.yml | 58 +++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 00000000..7c4c31bf --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,58 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +name: CodeQL + +on: + pull_request: + # The branches below must be a subset of the branches above + branches: "*" + +permissions: + contents: read + +jobs: + analyse: + permissions: + actions: read # for github/codeql-action/init to get workflow details + contents: read # for actions/checkout to fetch code + security-events: write # for github/codeql-action/autobuild to send a status report + name: Analyse + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + # We must fetch at least the immediate parents so that if this is + # a pull request then we can checkout the head. + fetch-depth: 2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # Analysis + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 From b138ca7d104a6352de7e55b35531ec4a3cc1419b Mon Sep 17 00:00:00 2001 From: gongna1 Date: Tue, 24 Sep 2024 17:27:33 +0800 Subject: [PATCH 02/11] feat:add codecov.yml config file --- .github/workflows/codecov.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/codecov.yml diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml new file mode 100644 index 00000000..3d3228df --- /dev/null +++ b/.github/workflows/codecov.yml @@ -0,0 +1,27 @@ +name: Go + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + code_cov: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.16' + + - name: Run tests and generate coverage report + run: | + go test -coverprofile=coverage.out -gcflags="all=-l -N" $(go list ./...) -short + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + file: coverage.out From c5bee2ffcee6267e8ed510a64e0b5828866c6e0e Mon Sep 17 00:00:00 2001 From: gongna1 Date: Tue, 24 Sep 2024 17:35:05 +0800 Subject: [PATCH 03/11] feature:add codecov.yml --- .github/workflows/codecov.yml | 2 +- proxy/plan/plan_select_test.go | 180 +++++++++++++++++---------------- 2 files changed, 92 insertions(+), 90 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 3d3228df..a8a7a184 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -1,4 +1,4 @@ -name: Go +name: Codecov on: push: diff --git a/proxy/plan/plan_select_test.go b/proxy/plan/plan_select_test.go index 664de4ed..7a7e6b63 100644 --- a/proxy/plan/plan_select_test.go +++ b/proxy/plan/plan_select_test.go @@ -2740,117 +2740,119 @@ func TestSelectKingshardNumRangeReverse(t *testing.T) { } } -func TestSelectKingshardDateYear(t *testing.T) { - ns, err := preparePlanInfo() - if err != nil { - t.Fatalf("prepare namespace error: %v", err) - } +/* + func TestSelectKingshardDateYear(t *testing.T) { + ns, err := preparePlanInfo() + if err != nil { + t.Fatalf("prepare namespace error: %v", err) + } - tests := []SQLTestcase{ - { - db: "db_ks", - sql: "select * from tbl_ks_year where create_time > 1564070400", // 2019/07/26 00:00:00 - sqls: map[string]map[string][]string{ - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_year_2019` WHERE `create_time`>1564070400", + tests := []SQLTestcase{ + { + db: "db_ks", + sql: "select * from tbl_ks_year where create_time > 1564070400", // 2019/07/26 00:00:00 + sqls: map[string]map[string][]string{ + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_year_2019` WHERE `create_time`>1564070400", + }, }, }, }, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_year where create_time > 1406304000", // 2014/07/26 00:00:00 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_year_2014` WHERE `create_time`>1406304000", - "SELECT * FROM `tbl_ks_year_2015` WHERE `create_time`>1406304000", - "SELECT * FROM `tbl_ks_year_2016` WHERE `create_time`>1406304000", - "SELECT * FROM `tbl_ks_year_2017` WHERE `create_time`>1406304000", + { + db: "db_ks", + sql: "select * from tbl_ks_year where create_time > 1406304000", // 2014/07/26 00:00:00 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_year_2014` WHERE `create_time`>1406304000", + "SELECT * FROM `tbl_ks_year_2015` WHERE `create_time`>1406304000", + "SELECT * FROM `tbl_ks_year_2016` WHERE `create_time`>1406304000", + "SELECT * FROM `tbl_ks_year_2017` WHERE `create_time`>1406304000", + }, }, - }, - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_year_2018` WHERE `create_time`>1406304000", - "SELECT * FROM `tbl_ks_year_2019` WHERE `create_time`>1406304000", + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_year_2018` WHERE `create_time`>1406304000", + "SELECT * FROM `tbl_ks_year_2019` WHERE `create_time`>1406304000", + }, }, }, }, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_year where create_time < 1388505600", // 2014/01/01 00:00:00 - sqls: map[string]map[string][]string{}, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_year where create_time < 1385827200", // 2013/12/01 00:00:00 - sqls: map[string]map[string][]string{}, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_year where create_time <= 1388505600", // 2014/01/01 00:00:00 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_year_2014` WHERE `create_time`<=1388505600", + { + db: "db_ks", + sql: "select * from tbl_ks_year where create_time < 1388505600", // 2014/01/01 00:00:00 + sqls: map[string]map[string][]string{}, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_year where create_time < 1385827200", // 2013/12/01 00:00:00 + sqls: map[string]map[string][]string{}, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_year where create_time <= 1388505600", // 2014/01/01 00:00:00 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_year_2014` WHERE `create_time`<=1388505600", + }, }, }, }, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_year where create_time <= 1388505600", // 2014/01/01 00:00:00 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_year_2014` WHERE `create_time`<=1388505600", + { + db: "db_ks", + sql: "select * from tbl_ks_year where create_time <= 1388505600", // 2014/01/01 00:00:00 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_year_2014` WHERE `create_time`<=1388505600", + }, }, }, }, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_year where create_time > 1514735999", // 2017/12/31 23:59:59 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_year_2017` WHERE `create_time`>1514735999", + { + db: "db_ks", + sql: "select * from tbl_ks_year where create_time > 1514735999", // 2017/12/31 23:59:59 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_year_2017` WHERE `create_time`>1514735999", + }, }, - }, - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_year_2018` WHERE `create_time`>1514735999", - "SELECT * FROM `tbl_ks_year_2019` WHERE `create_time`>1514735999", + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_year_2018` WHERE `create_time`>1514735999", + "SELECT * FROM `tbl_ks_year_2019` WHERE `create_time`>1514735999", + }, }, }, }, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_year where create_time >= 1514736000", // 2018/01/01 00:00:00 - sqls: map[string]map[string][]string{ - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_year_2018` WHERE `create_time`>=1514736000", - "SELECT * FROM `tbl_ks_year_2019` WHERE `create_time`>=1514736000", + { + db: "db_ks", + sql: "select * from tbl_ks_year where create_time >= 1514736000", // 2018/01/01 00:00:00 + sqls: map[string]map[string][]string{ + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_year_2018` WHERE `create_time`>=1514736000", + "SELECT * FROM `tbl_ks_year_2019` WHERE `create_time`>=1514736000", + }, }, }, }, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_year where create_time >= 1577808000", // 2020/01/01 00:00:00 - sqls: map[string]map[string][]string{}, - }, - } + { + db: "db_ks", + sql: "select * from tbl_ks_year where create_time >= 1577808000", // 2020/01/01 00:00:00 + sqls: map[string]map[string][]string{}, + }, + } - for _, test := range tests { - t.Run(test.sql, getTestFunc(ns, test)) + for _, test := range tests { + t.Run(test.sql, getTestFunc(ns, test)) + } } -} - +*/ +/* func TestSelectKingshardDateMonth(t *testing.T) { ns, err := preparePlanInfo() if err != nil { @@ -2955,7 +2957,7 @@ func TestSelectKingshardDateMonth(t *testing.T) { t.Run(test.sql, getTestFunc(ns, test)) } } - +*/ func TestSelectKingshardDateDay(t *testing.T) { ns, err := preparePlanInfo() if err != nil { From b98254de98a0a4f9a900e73277c4032aada2a593 Mon Sep 17 00:00:00 2001 From: gongna1 Date: Tue, 24 Sep 2024 17:40:28 +0800 Subject: [PATCH 04/11] feat:deleted some test methods --- proxy/plan/plan_select_test.go | 375 ++++++++++++++++----------------- 1 file changed, 187 insertions(+), 188 deletions(-) diff --git a/proxy/plan/plan_select_test.go b/proxy/plan/plan_select_test.go index 7a7e6b63..312cd71a 100644 --- a/proxy/plan/plan_select_test.go +++ b/proxy/plan/plan_select_test.go @@ -2851,240 +2851,239 @@ func TestSelectKingshardNumRangeReverse(t *testing.T) { t.Run(test.sql, getTestFunc(ns, test)) } } -*/ -/* -func TestSelectKingshardDateMonth(t *testing.T) { - ns, err := preparePlanInfo() - if err != nil { - t.Fatalf("prepare namespace error: %v", err) - } - tests := []SQLTestcase{ - { - db: "db_ks", - sql: "select * from tbl_ks_month where create_time > 1398873600", // 2014/05/01 00:00:00 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_month_201405` WHERE `create_time`>1398873600", - "SELECT * FROM `tbl_ks_month_201406` WHERE `create_time`>1398873600", + func TestSelectKingshardDateMonth(t *testing.T) { + ns, err := preparePlanInfo() + if err != nil { + t.Fatalf("prepare namespace error: %v", err) + } + + tests := []SQLTestcase{ + { + db: "db_ks", + sql: "select * from tbl_ks_month where create_time > 1398873600", // 2014/05/01 00:00:00 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_month_201405` WHERE `create_time`>1398873600", + "SELECT * FROM `tbl_ks_month_201406` WHERE `create_time`>1398873600", + }, }, - }, - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_month_201408` WHERE `create_time`>1398873600", - "SELECT * FROM `tbl_ks_month_201409` WHERE `create_time`>1398873600", + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_month_201408` WHERE `create_time`>1398873600", + "SELECT * FROM `tbl_ks_month_201409` WHERE `create_time`>1398873600", + }, }, }, }, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_month where create_time > 1398614400", // 2014/04/28 00:00:00 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_month_201405` WHERE `create_time`>1398614400", - "SELECT * FROM `tbl_ks_month_201406` WHERE `create_time`>1398614400", + { + db: "db_ks", + sql: "select * from tbl_ks_month where create_time > 1398614400", // 2014/04/28 00:00:00 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_month_201405` WHERE `create_time`>1398614400", + "SELECT * FROM `tbl_ks_month_201406` WHERE `create_time`>1398614400", + }, }, - }, - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_month_201408` WHERE `create_time`>1398614400", - "SELECT * FROM `tbl_ks_month_201409` WHERE `create_time`>1398614400", + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_month_201408` WHERE `create_time`>1398614400", + "SELECT * FROM `tbl_ks_month_201409` WHERE `create_time`>1398614400", + }, }, }, }, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_month where create_time < 1398873600", // 2014/05/01 00:00:00 - sqls: map[string]map[string][]string{}, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_month where create_time < 1398614400", // 2014/04/28 00:00:00 - sqls: map[string]map[string][]string{}, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_month where create_time < 1404144000", // 2014/07/01 00:00:00 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_month_201405` WHERE `create_time`<1404144000", - "SELECT * FROM `tbl_ks_month_201406` WHERE `create_time`<1404144000", + { + db: "db_ks", + sql: "select * from tbl_ks_month where create_time < 1398873600", // 2014/05/01 00:00:00 + sqls: map[string]map[string][]string{}, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_month where create_time < 1398614400", // 2014/04/28 00:00:00 + sqls: map[string]map[string][]string{}, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_month where create_time < 1404144000", // 2014/07/01 00:00:00 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_month_201405` WHERE `create_time`<1404144000", + "SELECT * FROM `tbl_ks_month_201406` WHERE `create_time`<1404144000", + }, }, }, }, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_month where create_time >= 1404144000", // 2014/07/01 00:00:00 - sqls: map[string]map[string][]string{ - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_month_201408` WHERE `create_time`>=1404144000", - "SELECT * FROM `tbl_ks_month_201409` WHERE `create_time`>=1404144000", + { + db: "db_ks", + sql: "select * from tbl_ks_month where create_time >= 1404144000", // 2014/07/01 00:00:00 + sqls: map[string]map[string][]string{ + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_month_201408` WHERE `create_time`>=1404144000", + "SELECT * FROM `tbl_ks_month_201409` WHERE `create_time`>=1404144000", + }, }, }, }, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_month where create_time > 1412092799", // 2014/09/30 23:59:59 - sqls: map[string]map[string][]string{ - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_month_201409` WHERE `create_time`>1412092799", + { + db: "db_ks", + sql: "select * from tbl_ks_month where create_time > 1412092799", // 2014/09/30 23:59:59 + sqls: map[string]map[string][]string{ + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_month_201409` WHERE `create_time`>1412092799", + }, }, }, }, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_month where create_time >= 1412092800", // 2014/10/01 00:00:00 - sqls: map[string]map[string][]string{}, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_month where create_time >= 1412438400", // 2014/10/05 00:00:00 - sqls: map[string]map[string][]string{}, - }, - } + { + db: "db_ks", + sql: "select * from tbl_ks_month where create_time >= 1412092800", // 2014/10/01 00:00:00 + sqls: map[string]map[string][]string{}, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_month where create_time >= 1412438400", // 2014/10/05 00:00:00 + sqls: map[string]map[string][]string{}, + }, + } - for _, test := range tests { - t.Run(test.sql, getTestFunc(ns, test)) - } -} -*/ -func TestSelectKingshardDateDay(t *testing.T) { - ns, err := preparePlanInfo() - if err != nil { - t.Fatalf("prepare namespace error: %v", err) + for _, test := range tests { + t.Run(test.sql, getTestFunc(ns, test)) + } } - tests := []SQLTestcase{ - { - db: "db_ks", - sql: "select * from tbl_ks_day where create_time < 1409500800", // 2014/09/01 00:00:00 - sqls: map[string]map[string][]string{}, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_day where create_time <= 1409500800", // 2014/09/01 00:00:00 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_day_20140901` WHERE `create_time`<=1409500800", + func TestSelectKingshardDateDay(t *testing.T) { + ns, err := preparePlanInfo() + if err != nil { + t.Fatalf("prepare namespace error: %v", err) + } + + tests := []SQLTestcase{ + { + db: "db_ks", + sql: "select * from tbl_ks_day where create_time < 1409500800", // 2014/09/01 00:00:00 + sqls: map[string]map[string][]string{}, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_day where create_time <= 1409500800", // 2014/09/01 00:00:00 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_day_20140901` WHERE `create_time`<=1409500800", + }, }, }, }, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_day where create_time >= 1410278400", // 2014/09/10 00:00:00 - sqls: map[string]map[string][]string{}, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_day where create_time = 1409846400", // 2014/09/05 00:00:00 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_day_20140905` WHERE `create_time`=1409846400", + { + db: "db_ks", + sql: "select * from tbl_ks_day where create_time >= 1410278400", // 2014/09/10 00:00:00 + sqls: map[string]map[string][]string{}, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_day where create_time = 1409846400", // 2014/09/05 00:00:00 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_day_20140905` WHERE `create_time`=1409846400", + }, }, }, }, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_day where create_time = 1409932800", // 2014/09/06 00:00:00 - }, - { - db: "db_ks", - sql: "select * from tbl_ks_day where create_time = 1410019200", // 2014/09/07 00:00:00 - sqls: map[string]map[string][]string{ - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_day_20140907` WHERE `create_time`=1410019200", + { + db: "db_ks", + sql: "select * from tbl_ks_day where create_time = 1409932800", // 2014/09/06 00:00:00 + }, + { + db: "db_ks", + sql: "select * from tbl_ks_day where create_time = 1410019200", // 2014/09/07 00:00:00 + sqls: map[string]map[string][]string{ + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_day_20140907` WHERE `create_time`=1410019200", + }, }, }, }, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_day where create_time > 1410019200", // 2014/09/07 00:00:00 - sqls: map[string]map[string][]string{ - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_day_20140907` WHERE `create_time`>1410019200", - "SELECT * FROM `tbl_ks_day_20140908` WHERE `create_time`>1410019200", + { + db: "db_ks", + sql: "select * from tbl_ks_day where create_time > 1410019200", // 2014/09/07 00:00:00 + sqls: map[string]map[string][]string{ + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_day_20140907` WHERE `create_time`>1410019200", + "SELECT * FROM `tbl_ks_day_20140908` WHERE `create_time`>1410019200", + }, }, }, }, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_day where create_time > 1410019200", // 2014/09/07 00:00:00 - sqls: map[string]map[string][]string{ - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_day_20140907` WHERE `create_time`>1410019200", - "SELECT * FROM `tbl_ks_day_20140908` WHERE `create_time`>1410019200", + { + db: "db_ks", + sql: "select * from tbl_ks_day where create_time > 1410019200", // 2014/09/07 00:00:00 + sqls: map[string]map[string][]string{ + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_day_20140907` WHERE `create_time`>1410019200", + "SELECT * FROM `tbl_ks_day_20140908` WHERE `create_time`>1410019200", + }, }, }, }, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_day where create_time < 1410278400", // 2014/09/10 00:00:00 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_day_20140901` WHERE `create_time`<1410278400", - "SELECT * FROM `tbl_ks_day_20140902` WHERE `create_time`<1410278400", - "SELECT * FROM `tbl_ks_day_20140903` WHERE `create_time`<1410278400", - "SELECT * FROM `tbl_ks_day_20140904` WHERE `create_time`<1410278400", - "SELECT * FROM `tbl_ks_day_20140905` WHERE `create_time`<1410278400", + { + db: "db_ks", + sql: "select * from tbl_ks_day where create_time < 1410278400", // 2014/09/10 00:00:00 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_day_20140901` WHERE `create_time`<1410278400", + "SELECT * FROM `tbl_ks_day_20140902` WHERE `create_time`<1410278400", + "SELECT * FROM `tbl_ks_day_20140903` WHERE `create_time`<1410278400", + "SELECT * FROM `tbl_ks_day_20140904` WHERE `create_time`<1410278400", + "SELECT * FROM `tbl_ks_day_20140905` WHERE `create_time`<1410278400", + }, }, - }, - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_day_20140907` WHERE `create_time`<1410278400", - "SELECT * FROM `tbl_ks_day_20140908` WHERE `create_time`<1410278400", + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_day_20140907` WHERE `create_time`<1410278400", + "SELECT * FROM `tbl_ks_day_20140908` WHERE `create_time`<1410278400", + }, }, }, }, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_day where create_time >= 1408464000", // 2014/08/20 00:00:00 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_day_20140901` WHERE `create_time`>=1408464000", - "SELECT * FROM `tbl_ks_day_20140902` WHERE `create_time`>=1408464000", - "SELECT * FROM `tbl_ks_day_20140903` WHERE `create_time`>=1408464000", - "SELECT * FROM `tbl_ks_day_20140904` WHERE `create_time`>=1408464000", - "SELECT * FROM `tbl_ks_day_20140905` WHERE `create_time`>=1408464000", + { + db: "db_ks", + sql: "select * from tbl_ks_day where create_time >= 1408464000", // 2014/08/20 00:00:00 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_day_20140901` WHERE `create_time`>=1408464000", + "SELECT * FROM `tbl_ks_day_20140902` WHERE `create_time`>=1408464000", + "SELECT * FROM `tbl_ks_day_20140903` WHERE `create_time`>=1408464000", + "SELECT * FROM `tbl_ks_day_20140904` WHERE `create_time`>=1408464000", + "SELECT * FROM `tbl_ks_day_20140905` WHERE `create_time`>=1408464000", + }, }, - }, - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_day_20140907` WHERE `create_time`>=1408464000", - "SELECT * FROM `tbl_ks_day_20140908` WHERE `create_time`>=1408464000", + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_day_20140907` WHERE `create_time`>=1408464000", + "SELECT * FROM `tbl_ks_day_20140908` WHERE `create_time`>=1408464000", + }, }, }, }, - }, - } + } - for _, test := range tests { - t.Run(test.sql, getTestFunc(ns, test)) + for _, test := range tests { + t.Run(test.sql, getTestFunc(ns, test)) + } } -} - +*/ func TestSelectMultiTablesOnConditionKingshard(t *testing.T) { ns, err := preparePlanInfo() if err != nil { From 4eee568f38ce80ed1043ffbf4eccab55be7c02c3 Mon Sep 17 00:00:00 2001 From: gongna1 Date: Tue, 24 Sep 2024 17:53:26 +0800 Subject: [PATCH 05/11] feat: try to use codecov-action@v3 --- .github/workflows/codecov.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index a8a7a184..0951d1d5 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -20,8 +20,4 @@ jobs: - name: Run tests and generate coverage report run: | go test -coverprofile=coverage.out -gcflags="all=-l -N" $(go list ./...) -short - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 - with: - file: coverage.out + - uses: codecov/codecov-action@v3 From 6df3c995f0ee3764f187a2e39ced5b6a8ad274a5 Mon Sep 17 00:00:00 2001 From: gongna1 Date: Tue, 24 Sep 2024 19:09:58 +0800 Subject: [PATCH 06/11] feat:use CODECOV_TOKEN Implement codecov --- .github/workflows/codecov.yml | 36 +++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 0951d1d5..2f58dcd8 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -1,23 +1,35 @@ -name: Codecov +name: Example workflow for Codecov -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] +on: [push] jobs: - code_cov: - runs-on: ubuntu-latest + run: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + env: + OS: ${{ matrix.os }} + GO_VERSION: '1.16' # 选择你需要的 Go 版本 steps: - uses: actions/checkout@v3 - + - name: Set up Go uses: actions/setup-go@v4 with: - go-version: '1.16' - + go-version: ${{ env.GO_VERSION }} + - name: Run tests and generate coverage report run: | go test -coverprofile=coverage.out -gcflags="all=-l -N" $(go list ./...) -short - - uses: codecov/codecov-action@v3 + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + file: coverage.out + env_vars: OS,GO_VERSION + fail_ci_if_error: true + flags: unittests + name: codecov-umbrella + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true From 2debe08a0f0e535234491628baffd0e342f0e9ef Mon Sep 17 00:00:00 2001 From: gongna1 Date: Wed, 25 Sep 2024 19:26:45 +0800 Subject: [PATCH 07/11] feat:change codecov.yml --- .github/workflows/codecov.yml | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 2f58dcd8..3d3228df 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -1,35 +1,27 @@ -name: Example workflow for Codecov +name: Go -on: [push] +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] jobs: - run: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest] - env: - OS: ${{ matrix.os }} - GO_VERSION: '1.16' # 选择你需要的 Go 版本 + code_cov: + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - + - name: Set up Go uses: actions/setup-go@v4 with: - go-version: ${{ env.GO_VERSION }} - + go-version: '1.16' + - name: Run tests and generate coverage report run: | go test -coverprofile=coverage.out -gcflags="all=-l -N" $(go list ./...) -short - + - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 with: file: coverage.out - env_vars: OS,GO_VERSION - fail_ci_if_error: true - flags: unittests - name: codecov-umbrella - token: ${{ secrets.CODECOV_TOKEN }} - verbose: true From d3cac01bc3b02000cd66045df8f36c36282d63ce Mon Sep 17 00:00:00 2001 From: gongna1 Date: Wed, 25 Sep 2024 19:37:48 +0800 Subject: [PATCH 08/11] feat:add codecov --- .github/workflows/codecov.yml | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 3d3228df..e1fc8569 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -1,27 +1,27 @@ -name: Go +name: Run tests and upload coverage -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] +on: + push jobs: - code_cov: + test: + name: Run tests and collect coverage runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: - go-version: '1.16' - - - name: Run tests and generate coverage report - run: | - go test -coverprofile=coverage.out -gcflags="all=-l -N" $(go list ./...) -short + go-version: '1.16' + + - name: Run tests + run: go test $(go list ./...) -coverprofile=coverage.txt - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + - name: Upload results to Codecov + uses: codecov/codecov-action@v4 with: - file: coverage.out + token: ${{ secrets.CODECOV_TOKEN }} From 4052937553d2b526bcbe4f86a6813eb38bc9d74a Mon Sep 17 00:00:00 2001 From: gongna1 Date: Wed, 25 Sep 2024 19:47:21 +0800 Subject: [PATCH 09/11] feat:test -short --- .github/workflows/codecov.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index e1fc8569..7e7388a3 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -19,7 +19,7 @@ jobs: go-version: '1.16' - name: Run tests - run: go test $(go list ./...) -coverprofile=coverage.txt + run: go test $(go list ./...) -gcflags="all=-l -N" -short -coverprofile=coverage.txt - name: Upload results to Codecov uses: codecov/codecov-action@v4 From f11fe5738514c143172da47f82c2b9679a9d2b64 Mon Sep 17 00:00:00 2001 From: gongna1 Date: Wed, 25 Sep 2024 20:33:01 +0800 Subject: [PATCH 10/11] feat:delete codecov yml config --- .github/workflows/codecov.yml | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 .github/workflows/codecov.yml diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml deleted file mode 100644 index 7e7388a3..00000000 --- a/.github/workflows/codecov.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Run tests and upload coverage - -on: - push - -jobs: - test: - name: Run tests and collect coverage - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: '1.16' - - - name: Run tests - run: go test $(go list ./...) -gcflags="all=-l -N" -short -coverprofile=coverage.txt - - - name: Upload results to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} From a7a703f770b09e38764f7d1c1c3d86ee5a030bb6 Mon Sep 17 00:00:00 2001 From: gongna1 Date: Wed, 25 Sep 2024 20:36:12 +0800 Subject: [PATCH 11/11] feat:cancel comment out test func --- proxy/plan/plan_select_test.go | 545 ++++++++++++++++----------------- 1 file changed, 272 insertions(+), 273 deletions(-) diff --git a/proxy/plan/plan_select_test.go b/proxy/plan/plan_select_test.go index 312cd71a..664de4ed 100644 --- a/proxy/plan/plan_select_test.go +++ b/proxy/plan/plan_select_test.go @@ -2740,350 +2740,349 @@ func TestSelectKingshardNumRangeReverse(t *testing.T) { } } -/* - func TestSelectKingshardDateYear(t *testing.T) { - ns, err := preparePlanInfo() - if err != nil { - t.Fatalf("prepare namespace error: %v", err) - } +func TestSelectKingshardDateYear(t *testing.T) { + ns, err := preparePlanInfo() + if err != nil { + t.Fatalf("prepare namespace error: %v", err) + } - tests := []SQLTestcase{ - { - db: "db_ks", - sql: "select * from tbl_ks_year where create_time > 1564070400", // 2019/07/26 00:00:00 - sqls: map[string]map[string][]string{ - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_year_2019` WHERE `create_time`>1564070400", - }, + tests := []SQLTestcase{ + { + db: "db_ks", + sql: "select * from tbl_ks_year where create_time > 1564070400", // 2019/07/26 00:00:00 + sqls: map[string]map[string][]string{ + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_year_2019` WHERE `create_time`>1564070400", }, }, }, - { - db: "db_ks", - sql: "select * from tbl_ks_year where create_time > 1406304000", // 2014/07/26 00:00:00 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_year_2014` WHERE `create_time`>1406304000", - "SELECT * FROM `tbl_ks_year_2015` WHERE `create_time`>1406304000", - "SELECT * FROM `tbl_ks_year_2016` WHERE `create_time`>1406304000", - "SELECT * FROM `tbl_ks_year_2017` WHERE `create_time`>1406304000", - }, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_year where create_time > 1406304000", // 2014/07/26 00:00:00 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_year_2014` WHERE `create_time`>1406304000", + "SELECT * FROM `tbl_ks_year_2015` WHERE `create_time`>1406304000", + "SELECT * FROM `tbl_ks_year_2016` WHERE `create_time`>1406304000", + "SELECT * FROM `tbl_ks_year_2017` WHERE `create_time`>1406304000", }, - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_year_2018` WHERE `create_time`>1406304000", - "SELECT * FROM `tbl_ks_year_2019` WHERE `create_time`>1406304000", - }, + }, + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_year_2018` WHERE `create_time`>1406304000", + "SELECT * FROM `tbl_ks_year_2019` WHERE `create_time`>1406304000", }, }, }, - { - db: "db_ks", - sql: "select * from tbl_ks_year where create_time < 1388505600", // 2014/01/01 00:00:00 - sqls: map[string]map[string][]string{}, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_year where create_time < 1385827200", // 2013/12/01 00:00:00 - sqls: map[string]map[string][]string{}, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_year where create_time <= 1388505600", // 2014/01/01 00:00:00 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_year_2014` WHERE `create_time`<=1388505600", - }, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_year where create_time < 1388505600", // 2014/01/01 00:00:00 + sqls: map[string]map[string][]string{}, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_year where create_time < 1385827200", // 2013/12/01 00:00:00 + sqls: map[string]map[string][]string{}, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_year where create_time <= 1388505600", // 2014/01/01 00:00:00 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_year_2014` WHERE `create_time`<=1388505600", }, }, }, - { - db: "db_ks", - sql: "select * from tbl_ks_year where create_time <= 1388505600", // 2014/01/01 00:00:00 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_year_2014` WHERE `create_time`<=1388505600", - }, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_year where create_time <= 1388505600", // 2014/01/01 00:00:00 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_year_2014` WHERE `create_time`<=1388505600", }, }, }, - { - db: "db_ks", - sql: "select * from tbl_ks_year where create_time > 1514735999", // 2017/12/31 23:59:59 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_year_2017` WHERE `create_time`>1514735999", - }, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_year where create_time > 1514735999", // 2017/12/31 23:59:59 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_year_2017` WHERE `create_time`>1514735999", }, - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_year_2018` WHERE `create_time`>1514735999", - "SELECT * FROM `tbl_ks_year_2019` WHERE `create_time`>1514735999", - }, + }, + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_year_2018` WHERE `create_time`>1514735999", + "SELECT * FROM `tbl_ks_year_2019` WHERE `create_time`>1514735999", }, }, }, - { - db: "db_ks", - sql: "select * from tbl_ks_year where create_time >= 1514736000", // 2018/01/01 00:00:00 - sqls: map[string]map[string][]string{ - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_year_2018` WHERE `create_time`>=1514736000", - "SELECT * FROM `tbl_ks_year_2019` WHERE `create_time`>=1514736000", - }, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_year where create_time >= 1514736000", // 2018/01/01 00:00:00 + sqls: map[string]map[string][]string{ + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_year_2018` WHERE `create_time`>=1514736000", + "SELECT * FROM `tbl_ks_year_2019` WHERE `create_time`>=1514736000", }, }, }, - { - db: "db_ks", - sql: "select * from tbl_ks_year where create_time >= 1577808000", // 2020/01/01 00:00:00 - sqls: map[string]map[string][]string{}, - }, - } + }, + { + db: "db_ks", + sql: "select * from tbl_ks_year where create_time >= 1577808000", // 2020/01/01 00:00:00 + sqls: map[string]map[string][]string{}, + }, + } - for _, test := range tests { - t.Run(test.sql, getTestFunc(ns, test)) - } + for _, test := range tests { + t.Run(test.sql, getTestFunc(ns, test)) } +} - func TestSelectKingshardDateMonth(t *testing.T) { - ns, err := preparePlanInfo() - if err != nil { - t.Fatalf("prepare namespace error: %v", err) - } +func TestSelectKingshardDateMonth(t *testing.T) { + ns, err := preparePlanInfo() + if err != nil { + t.Fatalf("prepare namespace error: %v", err) + } - tests := []SQLTestcase{ - { - db: "db_ks", - sql: "select * from tbl_ks_month where create_time > 1398873600", // 2014/05/01 00:00:00 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_month_201405` WHERE `create_time`>1398873600", - "SELECT * FROM `tbl_ks_month_201406` WHERE `create_time`>1398873600", - }, + tests := []SQLTestcase{ + { + db: "db_ks", + sql: "select * from tbl_ks_month where create_time > 1398873600", // 2014/05/01 00:00:00 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_month_201405` WHERE `create_time`>1398873600", + "SELECT * FROM `tbl_ks_month_201406` WHERE `create_time`>1398873600", }, - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_month_201408` WHERE `create_time`>1398873600", - "SELECT * FROM `tbl_ks_month_201409` WHERE `create_time`>1398873600", - }, + }, + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_month_201408` WHERE `create_time`>1398873600", + "SELECT * FROM `tbl_ks_month_201409` WHERE `create_time`>1398873600", }, }, }, - { - db: "db_ks", - sql: "select * from tbl_ks_month where create_time > 1398614400", // 2014/04/28 00:00:00 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_month_201405` WHERE `create_time`>1398614400", - "SELECT * FROM `tbl_ks_month_201406` WHERE `create_time`>1398614400", - }, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_month where create_time > 1398614400", // 2014/04/28 00:00:00 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_month_201405` WHERE `create_time`>1398614400", + "SELECT * FROM `tbl_ks_month_201406` WHERE `create_time`>1398614400", }, - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_month_201408` WHERE `create_time`>1398614400", - "SELECT * FROM `tbl_ks_month_201409` WHERE `create_time`>1398614400", - }, + }, + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_month_201408` WHERE `create_time`>1398614400", + "SELECT * FROM `tbl_ks_month_201409` WHERE `create_time`>1398614400", }, }, }, - { - db: "db_ks", - sql: "select * from tbl_ks_month where create_time < 1398873600", // 2014/05/01 00:00:00 - sqls: map[string]map[string][]string{}, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_month where create_time < 1398614400", // 2014/04/28 00:00:00 - sqls: map[string]map[string][]string{}, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_month where create_time < 1404144000", // 2014/07/01 00:00:00 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_month_201405` WHERE `create_time`<1404144000", - "SELECT * FROM `tbl_ks_month_201406` WHERE `create_time`<1404144000", - }, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_month where create_time < 1398873600", // 2014/05/01 00:00:00 + sqls: map[string]map[string][]string{}, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_month where create_time < 1398614400", // 2014/04/28 00:00:00 + sqls: map[string]map[string][]string{}, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_month where create_time < 1404144000", // 2014/07/01 00:00:00 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_month_201405` WHERE `create_time`<1404144000", + "SELECT * FROM `tbl_ks_month_201406` WHERE `create_time`<1404144000", }, }, }, - { - db: "db_ks", - sql: "select * from tbl_ks_month where create_time >= 1404144000", // 2014/07/01 00:00:00 - sqls: map[string]map[string][]string{ - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_month_201408` WHERE `create_time`>=1404144000", - "SELECT * FROM `tbl_ks_month_201409` WHERE `create_time`>=1404144000", - }, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_month where create_time >= 1404144000", // 2014/07/01 00:00:00 + sqls: map[string]map[string][]string{ + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_month_201408` WHERE `create_time`>=1404144000", + "SELECT * FROM `tbl_ks_month_201409` WHERE `create_time`>=1404144000", }, }, }, - { - db: "db_ks", - sql: "select * from tbl_ks_month where create_time > 1412092799", // 2014/09/30 23:59:59 - sqls: map[string]map[string][]string{ - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_month_201409` WHERE `create_time`>1412092799", - }, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_month where create_time > 1412092799", // 2014/09/30 23:59:59 + sqls: map[string]map[string][]string{ + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_month_201409` WHERE `create_time`>1412092799", }, }, }, - { - db: "db_ks", - sql: "select * from tbl_ks_month where create_time >= 1412092800", // 2014/10/01 00:00:00 - sqls: map[string]map[string][]string{}, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_month where create_time >= 1412438400", // 2014/10/05 00:00:00 - sqls: map[string]map[string][]string{}, - }, - } + }, + { + db: "db_ks", + sql: "select * from tbl_ks_month where create_time >= 1412092800", // 2014/10/01 00:00:00 + sqls: map[string]map[string][]string{}, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_month where create_time >= 1412438400", // 2014/10/05 00:00:00 + sqls: map[string]map[string][]string{}, + }, + } - for _, test := range tests { - t.Run(test.sql, getTestFunc(ns, test)) - } + for _, test := range tests { + t.Run(test.sql, getTestFunc(ns, test)) } +} - func TestSelectKingshardDateDay(t *testing.T) { - ns, err := preparePlanInfo() - if err != nil { - t.Fatalf("prepare namespace error: %v", err) - } +func TestSelectKingshardDateDay(t *testing.T) { + ns, err := preparePlanInfo() + if err != nil { + t.Fatalf("prepare namespace error: %v", err) + } - tests := []SQLTestcase{ - { - db: "db_ks", - sql: "select * from tbl_ks_day where create_time < 1409500800", // 2014/09/01 00:00:00 - sqls: map[string]map[string][]string{}, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_day where create_time <= 1409500800", // 2014/09/01 00:00:00 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_day_20140901` WHERE `create_time`<=1409500800", - }, + tests := []SQLTestcase{ + { + db: "db_ks", + sql: "select * from tbl_ks_day where create_time < 1409500800", // 2014/09/01 00:00:00 + sqls: map[string]map[string][]string{}, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_day where create_time <= 1409500800", // 2014/09/01 00:00:00 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_day_20140901` WHERE `create_time`<=1409500800", }, }, }, - { - db: "db_ks", - sql: "select * from tbl_ks_day where create_time >= 1410278400", // 2014/09/10 00:00:00 - sqls: map[string]map[string][]string{}, - }, - { - db: "db_ks", - sql: "select * from tbl_ks_day where create_time = 1409846400", // 2014/09/05 00:00:00 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_day_20140905` WHERE `create_time`=1409846400", - }, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_day where create_time >= 1410278400", // 2014/09/10 00:00:00 + sqls: map[string]map[string][]string{}, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_day where create_time = 1409846400", // 2014/09/05 00:00:00 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_day_20140905` WHERE `create_time`=1409846400", }, }, }, - { - db: "db_ks", - sql: "select * from tbl_ks_day where create_time = 1409932800", // 2014/09/06 00:00:00 - }, - { - db: "db_ks", - sql: "select * from tbl_ks_day where create_time = 1410019200", // 2014/09/07 00:00:00 - sqls: map[string]map[string][]string{ - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_day_20140907` WHERE `create_time`=1410019200", - }, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_day where create_time = 1409932800", // 2014/09/06 00:00:00 + }, + { + db: "db_ks", + sql: "select * from tbl_ks_day where create_time = 1410019200", // 2014/09/07 00:00:00 + sqls: map[string]map[string][]string{ + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_day_20140907` WHERE `create_time`=1410019200", }, }, }, - { - db: "db_ks", - sql: "select * from tbl_ks_day where create_time > 1410019200", // 2014/09/07 00:00:00 - sqls: map[string]map[string][]string{ - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_day_20140907` WHERE `create_time`>1410019200", - "SELECT * FROM `tbl_ks_day_20140908` WHERE `create_time`>1410019200", - }, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_day where create_time > 1410019200", // 2014/09/07 00:00:00 + sqls: map[string]map[string][]string{ + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_day_20140907` WHERE `create_time`>1410019200", + "SELECT * FROM `tbl_ks_day_20140908` WHERE `create_time`>1410019200", }, }, }, - { - db: "db_ks", - sql: "select * from tbl_ks_day where create_time > 1410019200", // 2014/09/07 00:00:00 - sqls: map[string]map[string][]string{ - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_day_20140907` WHERE `create_time`>1410019200", - "SELECT * FROM `tbl_ks_day_20140908` WHERE `create_time`>1410019200", - }, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_day where create_time > 1410019200", // 2014/09/07 00:00:00 + sqls: map[string]map[string][]string{ + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_day_20140907` WHERE `create_time`>1410019200", + "SELECT * FROM `tbl_ks_day_20140908` WHERE `create_time`>1410019200", }, }, }, - { - db: "db_ks", - sql: "select * from tbl_ks_day where create_time < 1410278400", // 2014/09/10 00:00:00 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_day_20140901` WHERE `create_time`<1410278400", - "SELECT * FROM `tbl_ks_day_20140902` WHERE `create_time`<1410278400", - "SELECT * FROM `tbl_ks_day_20140903` WHERE `create_time`<1410278400", - "SELECT * FROM `tbl_ks_day_20140904` WHERE `create_time`<1410278400", - "SELECT * FROM `tbl_ks_day_20140905` WHERE `create_time`<1410278400", - }, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_day where create_time < 1410278400", // 2014/09/10 00:00:00 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_day_20140901` WHERE `create_time`<1410278400", + "SELECT * FROM `tbl_ks_day_20140902` WHERE `create_time`<1410278400", + "SELECT * FROM `tbl_ks_day_20140903` WHERE `create_time`<1410278400", + "SELECT * FROM `tbl_ks_day_20140904` WHERE `create_time`<1410278400", + "SELECT * FROM `tbl_ks_day_20140905` WHERE `create_time`<1410278400", }, - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_day_20140907` WHERE `create_time`<1410278400", - "SELECT * FROM `tbl_ks_day_20140908` WHERE `create_time`<1410278400", - }, + }, + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_day_20140907` WHERE `create_time`<1410278400", + "SELECT * FROM `tbl_ks_day_20140908` WHERE `create_time`<1410278400", }, }, }, - { - db: "db_ks", - sql: "select * from tbl_ks_day where create_time >= 1408464000", // 2014/08/20 00:00:00 - sqls: map[string]map[string][]string{ - "slice-0": { - "db_ks": { - "SELECT * FROM `tbl_ks_day_20140901` WHERE `create_time`>=1408464000", - "SELECT * FROM `tbl_ks_day_20140902` WHERE `create_time`>=1408464000", - "SELECT * FROM `tbl_ks_day_20140903` WHERE `create_time`>=1408464000", - "SELECT * FROM `tbl_ks_day_20140904` WHERE `create_time`>=1408464000", - "SELECT * FROM `tbl_ks_day_20140905` WHERE `create_time`>=1408464000", - }, + }, + { + db: "db_ks", + sql: "select * from tbl_ks_day where create_time >= 1408464000", // 2014/08/20 00:00:00 + sqls: map[string]map[string][]string{ + "slice-0": { + "db_ks": { + "SELECT * FROM `tbl_ks_day_20140901` WHERE `create_time`>=1408464000", + "SELECT * FROM `tbl_ks_day_20140902` WHERE `create_time`>=1408464000", + "SELECT * FROM `tbl_ks_day_20140903` WHERE `create_time`>=1408464000", + "SELECT * FROM `tbl_ks_day_20140904` WHERE `create_time`>=1408464000", + "SELECT * FROM `tbl_ks_day_20140905` WHERE `create_time`>=1408464000", }, - "slice-1": { - "db_ks": { - "SELECT * FROM `tbl_ks_day_20140907` WHERE `create_time`>=1408464000", - "SELECT * FROM `tbl_ks_day_20140908` WHERE `create_time`>=1408464000", - }, + }, + "slice-1": { + "db_ks": { + "SELECT * FROM `tbl_ks_day_20140907` WHERE `create_time`>=1408464000", + "SELECT * FROM `tbl_ks_day_20140908` WHERE `create_time`>=1408464000", }, }, }, - } + }, + } - for _, test := range tests { - t.Run(test.sql, getTestFunc(ns, test)) - } + for _, test := range tests { + t.Run(test.sql, getTestFunc(ns, test)) } -*/ +} + func TestSelectMultiTablesOnConditionKingshard(t *testing.T) { ns, err := preparePlanInfo() if err != nil {