Skip to content

Commit a45a181

Browse files
authored
test: add tests for IMPORT INTO statement with Foreign Key (#56568)
close #56563
1 parent d1c476a commit a45a181

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/realtikvtest/importintotest/import_into_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,3 +1239,24 @@ func (s *mockGCSSuite) TestBadCases() {
12391239
err := s.tk.QueryToErr(sql)
12401240
require.ErrorContains(s.T(), err, "panic occurred during import, please check log")
12411241
}
1242+
1243+
func (s *mockGCSSuite) TestImportIntoWithFK() {
1244+
content := []byte(`1,1
1245+
2,2`)
1246+
s.server.CreateObject(fakestorage.Object{
1247+
ObjectAttrs: fakestorage.ObjectAttrs{
1248+
BucketName: "foreign-key-test",
1249+
Name: "child.csv",
1250+
},
1251+
Content: content,
1252+
})
1253+
s.prepareAndUseDB("import_into")
1254+
s.tk.MustExec("create table parent (id int primary key);")
1255+
s.tk.MustExec("create table child (id int primary key, fk int, foreign key (fk) references parent(id));")
1256+
sql := fmt.Sprintf(`IMPORT INTO import_into.child
1257+
FROM 'gs://foreign-key-test/child.csv?endpoint=%s'`, gcsEndpoint)
1258+
1259+
// it should success even if the parent table is empty
1260+
s.tk.MustQuery(sql)
1261+
s.tk.MustQuery("SELECT * FROM import_into.child;").Check(testkit.Rows("1 1", "2 2"))
1262+
}

0 commit comments

Comments
 (0)