Skip to content

Commit 08bed4b

Browse files
authored
パーティションテーブル対応 (#46)
* パーティションテーブル対応 * テスト修正 * コメント追加
1 parent fdb4418 commit 08bed4b

File tree

4 files changed

+55
-17
lines changed

4 files changed

+55
-17
lines changed

compare.xlsx

8.13 KB
Binary file not shown.

exceltesting_test.go

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package exceltesting
22

33
import (
44
"database/sql"
5-
"github.com/future-architect/go-exceltesting/testonly"
65
"net"
76
"os"
87
"path/filepath"
98
"reflect"
109
"testing"
1110
"time"
1211

12+
"github.com/future-architect/go-exceltesting/testonly"
13+
1314
"github.com/google/go-cmp/cmp"
1415
"github.com/google/go-cmp/cmp/cmpopts"
1516
"github.com/jackc/pgtype"
@@ -176,10 +177,11 @@ func Test_exceltesing_Compare(t *testing.T) {
176177
mockT := new(testing.T)
177178

178179
tests := []struct {
179-
name string
180-
input func(t *testing.T)
181-
wantFile string
182-
equal bool
180+
name string
181+
input func(t *testing.T)
182+
wantFile string
183+
wantSheet string
184+
equal bool
183185
}{
184186
{
185187
name: "equal",
@@ -195,8 +197,9 @@ func Test_exceltesing_Compare(t *testing.T) {
195197
t.Fatal(err)
196198
}
197199
},
198-
wantFile: filepath.Join("testdata", "compare.xlsx"),
199-
equal: true,
200+
wantFile: filepath.Join("testdata", "compare.xlsx"),
201+
wantSheet: "会社",
202+
equal: true,
200203
},
201204
{
202205
name: "equal on exceltesing version 2.0 sheet",
@@ -212,8 +215,9 @@ func Test_exceltesing_Compare(t *testing.T) {
212215
t.Fatal(err)
213216
}
214217
},
215-
wantFile: filepath.Join("testdata", "compare_v2.xlsx"),
216-
equal: true,
218+
wantFile: filepath.Join("testdata", "compare_v2.xlsx"),
219+
wantSheet: "会社",
220+
equal: true,
217221
},
218222
{
219223
name: "diff",
@@ -229,8 +233,9 @@ func Test_exceltesing_Compare(t *testing.T) {
229233
t.Fatal(err)
230234
}
231235
},
232-
wantFile: filepath.Join("testdata", "compare.xlsx"),
233-
equal: false,
236+
wantFile: filepath.Join("testdata", "compare.xlsx"),
237+
wantSheet: "会社",
238+
equal: false,
234239
},
235240
{
236241
name: "fewer records of results",
@@ -246,8 +251,9 @@ func Test_exceltesing_Compare(t *testing.T) {
246251
t.Fatal(err)
247252
}
248253
},
249-
wantFile: filepath.Join("testdata", "compare.xlsx"),
250-
equal: false,
254+
wantFile: filepath.Join("testdata", "compare.xlsx"),
255+
wantSheet: "会社",
256+
equal: false,
251257
},
252258
{
253259
name: "many records of results",
@@ -263,8 +269,27 @@ func Test_exceltesing_Compare(t *testing.T) {
263269
t.Fatal(err)
264270
}
265271
},
266-
wantFile: filepath.Join("testdata", "compare.xlsx"),
267-
equal: false,
272+
wantFile: filepath.Join("testdata", "compare.xlsx"),
273+
wantSheet: "会社",
274+
equal: false,
275+
},
276+
{
277+
name: "partition table",
278+
input: func(t *testing.T) {
279+
t.Helper()
280+
tdb := testonly.OpenTestDB(t)
281+
defer tdb.Close()
282+
if _, err := tdb.Exec(`TRUNCATE temperature;`); err != nil {
283+
t.Fatal(err)
284+
}
285+
if _, err := tdb.Exec(`INSERT INTO temperature (ymd,value)
286+
VALUES ('20210228',-2.0),('20210831',38.5);`); err != nil {
287+
t.Fatal(err)
288+
}
289+
},
290+
wantFile: filepath.Join("testdata", "compare.xlsx"),
291+
wantSheet: "気温",
292+
equal: true,
268293
},
269294
}
270295
for _, tt := range tests {
@@ -274,7 +299,7 @@ func Test_exceltesing_Compare(t *testing.T) {
274299
e := New(conn)
275300
got := e.Compare(mockT, CompareRequest{
276301
TargetBookPath: filepath.Join("testdata", "compare.xlsx"),
277-
SheetPrefix: "",
302+
SheetPrefix: tt.wantSheet,
278303
IgnoreSheet: nil,
279304
IgnoreColumns: []string{"created_at", "updated_at"},
280305
})

query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ AND i.oid = ix.indexrelid
1616
AND ix.indisprimary = TRUE
1717
AND A.attrelid = T.oid
1818
AND A.attnum = ANY(ix.indkey)
19-
AND T.relkind = 'r'
19+
AND T.relkind IN ('r', 'p') -- TODO: 将来的には他の relkind にも対応する予定
2020
AND T.relname = ta.tablename
2121
AND ta.schemaname = CURRENT_SCHEMA()
2222
AND T.relname = $1

testdata/schema/ddl.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,16 @@ CREATE TABLE test_x(
4343
CONSTRAINT test_x_pkc PRIMARY KEY(id)
4444
)
4545
;
46+
47+
DROP TABLE IF EXISTS temperature
48+
;
49+
CREATE TABLE temperature(
50+
ymd varchar(8) NOT NULL,
51+
value numeric(4,1) NOT NULL,
52+
CONSTRAINT temperature_pkc PRIMARY KEY(ymd)
53+
) PARTITION BY RANGE (ymd)
54+
;
55+
DROP TABLE IF EXISTS temperature_2021_2022
56+
;
57+
CREATE TABLE temperature_2021_2022 PARTITION OF temperature FOR VALUES FROM ('20210101') TO ('20220101')
58+
;

0 commit comments

Comments
 (0)