Skip to content

Commit

Permalink
パーティションテーブル対応 (#46)
Browse files Browse the repository at this point in the history
* パーティションテーブル対応

* テスト修正

* コメント追加
  • Loading branch information
tamiyamoto authored Oct 12, 2022
1 parent fdb4418 commit 08bed4b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 17 deletions.
Binary file added compare.xlsx
Binary file not shown.
57 changes: 41 additions & 16 deletions exceltesting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package exceltesting

import (
"database/sql"
"github.com/future-architect/go-exceltesting/testonly"
"net"
"os"
"path/filepath"
"reflect"
"testing"
"time"

"github.com/future-architect/go-exceltesting/testonly"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/jackc/pgtype"
Expand Down Expand Up @@ -176,10 +177,11 @@ func Test_exceltesing_Compare(t *testing.T) {
mockT := new(testing.T)

tests := []struct {
name string
input func(t *testing.T)
wantFile string
equal bool
name string
input func(t *testing.T)
wantFile string
wantSheet string
equal bool
}{
{
name: "equal",
Expand All @@ -195,8 +197,9 @@ func Test_exceltesing_Compare(t *testing.T) {
t.Fatal(err)
}
},
wantFile: filepath.Join("testdata", "compare.xlsx"),
equal: true,
wantFile: filepath.Join("testdata", "compare.xlsx"),
wantSheet: "会社",
equal: true,
},
{
name: "equal on exceltesing version 2.0 sheet",
Expand All @@ -212,8 +215,9 @@ func Test_exceltesing_Compare(t *testing.T) {
t.Fatal(err)
}
},
wantFile: filepath.Join("testdata", "compare_v2.xlsx"),
equal: true,
wantFile: filepath.Join("testdata", "compare_v2.xlsx"),
wantSheet: "会社",
equal: true,
},
{
name: "diff",
Expand All @@ -229,8 +233,9 @@ func Test_exceltesing_Compare(t *testing.T) {
t.Fatal(err)
}
},
wantFile: filepath.Join("testdata", "compare.xlsx"),
equal: false,
wantFile: filepath.Join("testdata", "compare.xlsx"),
wantSheet: "会社",
equal: false,
},
{
name: "fewer records of results",
Expand All @@ -246,8 +251,9 @@ func Test_exceltesing_Compare(t *testing.T) {
t.Fatal(err)
}
},
wantFile: filepath.Join("testdata", "compare.xlsx"),
equal: false,
wantFile: filepath.Join("testdata", "compare.xlsx"),
wantSheet: "会社",
equal: false,
},
{
name: "many records of results",
Expand All @@ -263,8 +269,27 @@ func Test_exceltesing_Compare(t *testing.T) {
t.Fatal(err)
}
},
wantFile: filepath.Join("testdata", "compare.xlsx"),
equal: false,
wantFile: filepath.Join("testdata", "compare.xlsx"),
wantSheet: "会社",
equal: false,
},
{
name: "partition table",
input: func(t *testing.T) {
t.Helper()
tdb := testonly.OpenTestDB(t)
defer tdb.Close()
if _, err := tdb.Exec(`TRUNCATE temperature;`); err != nil {
t.Fatal(err)
}
if _, err := tdb.Exec(`INSERT INTO temperature (ymd,value)
VALUES ('20210228',-2.0),('20210831',38.5);`); err != nil {
t.Fatal(err)
}
},
wantFile: filepath.Join("testdata", "compare.xlsx"),
wantSheet: "気温",
equal: true,
},
}
for _, tt := range tests {
Expand All @@ -274,7 +299,7 @@ func Test_exceltesing_Compare(t *testing.T) {
e := New(conn)
got := e.Compare(mockT, CompareRequest{
TargetBookPath: filepath.Join("testdata", "compare.xlsx"),
SheetPrefix: "",
SheetPrefix: tt.wantSheet,
IgnoreSheet: nil,
IgnoreColumns: []string{"created_at", "updated_at"},
})
Expand Down
2 changes: 1 addition & 1 deletion query.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ AND i.oid = ix.indexrelid
AND ix.indisprimary = TRUE
AND A.attrelid = T.oid
AND A.attnum = ANY(ix.indkey)
AND T.relkind = 'r'
AND T.relkind IN ('r', 'p') -- TODO: 将来的には他の relkind にも対応する予定
AND T.relname = ta.tablename
AND ta.schemaname = CURRENT_SCHEMA()
AND T.relname = $1
Expand Down
13 changes: 13 additions & 0 deletions testdata/schema/ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,16 @@ CREATE TABLE test_x(
CONSTRAINT test_x_pkc PRIMARY KEY(id)
)
;

DROP TABLE IF EXISTS temperature
;
CREATE TABLE temperature(
ymd varchar(8) NOT NULL,
value numeric(4,1) NOT NULL,
CONSTRAINT temperature_pkc PRIMARY KEY(ymd)
) PARTITION BY RANGE (ymd)
;
DROP TABLE IF EXISTS temperature_2021_2022
;
CREATE TABLE temperature_2021_2022 PARTITION OF temperature FOR VALUES FROM ('20210101') TO ('20220101')
;

0 comments on commit 08bed4b

Please sign in to comment.