Skip to content

Commit

Permalink
test: add tests for IMPORT INTO statement with Foreign Key (pingcap…
Browse files Browse the repository at this point in the history
  • Loading branch information
YangKeao authored Oct 14, 2024
1 parent d1c476a commit a45a181
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/realtikvtest/importintotest/import_into_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1239,3 +1239,24 @@ func (s *mockGCSSuite) TestBadCases() {
err := s.tk.QueryToErr(sql)
require.ErrorContains(s.T(), err, "panic occurred during import, please check log")
}

func (s *mockGCSSuite) TestImportIntoWithFK() {
content := []byte(`1,1
2,2`)
s.server.CreateObject(fakestorage.Object{
ObjectAttrs: fakestorage.ObjectAttrs{
BucketName: "foreign-key-test",
Name: "child.csv",
},
Content: content,
})
s.prepareAndUseDB("import_into")
s.tk.MustExec("create table parent (id int primary key);")
s.tk.MustExec("create table child (id int primary key, fk int, foreign key (fk) references parent(id));")
sql := fmt.Sprintf(`IMPORT INTO import_into.child
FROM 'gs://foreign-key-test/child.csv?endpoint=%s'`, gcsEndpoint)

// it should success even if the parent table is empty
s.tk.MustQuery(sql)
s.tk.MustQuery("SELECT * FROM import_into.child;").Check(testkit.Rows("1 1", "2 2"))
}

0 comments on commit a45a181

Please sign in to comment.