Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

importccl: disable import with user defined schemas #52729

Merged
merged 1 commit into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/ccl/importccl/import_stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,14 @@ func importPlanHook(
}
}

// Due to how we generate and rewrite descriptor ID's for import, we run
// into problems when using user defined schemas.
if parentSchemaID != keys.PublicSchemaID {
err := errors.New("cannot use IMPORT with a user defined schema")
hint := errors.WithHint(err, "create the table with CREATE TABLE and use IMPORT INTO instead")
return hint
}

tableDetails = make([]jobspb.ImportDetails_Table, len(tableDescs))
for i := range tableDescs {
tableDetails[i] = jobspb.ImportDetails_Table{
Expand Down
16 changes: 2 additions & 14 deletions pkg/ccl/importccl/import_stmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1869,15 +1869,9 @@ IMPORT TABLE import_with_db_privs (a INT8 PRIMARY KEY, b STRING) CSV DATA (%s)`,
sqlDB.Exec(t, `USE uds`)
sqlDB.Exec(t, `CREATE SCHEMA sc`)
// Now import into a table under sc.
sqlDB.Exec(t, fmt.Sprintf(`IMPORT TABLE uds.sc.t (a INT8 PRIMARY KEY, b STRING) CSV DATA (%s)`, testFiles.files[0]))
// Verify that the table was created and has the right number of rows.
var result int
sqlDB.QueryRow(t, `SELECT count(*) FROM uds.sc.t`).Scan(&result)
require.Equal(t, rowsPerFile, result)
// Try the same thing, but with IMPORT INTO.
sqlDB.Exec(t, `DROP TABLE uds.sc.t`)
sqlDB.Exec(t, `CREATE TABLE uds.sc.t (a INT8 PRIMARY KEY, b STRING)`)
sqlDB.Exec(t, fmt.Sprintf(`IMPORT INTO uds.sc.t (a, b) CSV DATA (%s)`, testFiles.files[0]))
var result int
sqlDB.QueryRow(t, `SELECT count(*) FROM uds.sc.t`).Scan(&result)
require.Equal(t, rowsPerFile, result)
})
Expand Down Expand Up @@ -4843,15 +4837,9 @@ func TestImportAvro(t *testing.T) {
t.Run("user-defined-schemas", func(t *testing.T) {
sqlDB.Exec(t, `SET experimental_enable_user_defined_schemas = true`)
sqlDB.Exec(t, `CREATE SCHEMA myschema`)
// Test with normal IMPORT.
sqlDB.Exec(t, `IMPORT TABLE myschema.simple (i INT8 PRIMARY KEY, s text, b bytea) AVRO DATA ($1)`, simpleOcf)
var numRows int
sqlDB.QueryRow(t, `SELECT count(*) FROM myschema.simple`).Scan(&numRows)
require.True(t, numRows > 0)
// Test with IMPORT INTO.
sqlDB.Exec(t, `DROP TABLE myschema.simple`)
sqlDB.Exec(t, `CREATE TABLE myschema.simple (i INT8 PRIMARY KEY, s text, b bytea)`)
sqlDB.Exec(t, `IMPORT INTO myschema.simple (i, s, b) AVRO DATA ($1)`, simpleOcf)
var numRows int
sqlDB.QueryRow(t, `SELECT count(*) FROM myschema.simple`).Scan(&numRows)
require.True(t, numRows > 0)
})
Expand Down