cockroachdb / cockroachdb/cockroach

import: create-file-table should use valid table name for user with special characters

Open
#112,420 0 comments 0 reactions 0 assignees View on GitHub
A-import C-bug E-quick-win O-support P-3 T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

When a user/role contains special characters, like a `.`, uploaded userfiles are stored in a directory with a hex-encoding of the user/role name. For example:

1. Start a cockroach demo server: `cockroach demo --empty`.
2. Create a role with a special character name and a table owned by that role:

```sql
CREATE ROLE "a.b" LOGIN PASSWORD 'foo';
SET ROLE "a.b";
CREATE TABLE t (a int);
```

3. From another terminal session, upload a file (just a simple csv with one column), to the server: `cockroach userfile upload tmp.csv -u a.b --certs-dir=[path to certs dir printed in step 1]`.

Notice that the file is uploaded to `userfile://defaultdb.public.userfilesx_612e62/tmp.csv`. Importing this file into `t` works:

```sql
IMPORT INTO t CSV DATA ('userfile://defaultdb.public.userfilesx_612e62/tmp.csv');
```

But the short-hand import of the same file does not:

```sql
import into t csv data ('userfile:///tmp.csv');
-- ERROR: failed to create file table to store uploaded file names: create-file-table: at or near "_upload_files": syntax error
-- SQLSTATE: 42601
-- DETAIL: source SQL:
-- CREATE TABLE defaultdb.public."userfiles_a.b"_upload_files (filename STRING PRIMARY KEY,
-- ^
-- HINT: try \h CREATE TABLE
```

The problem is that it attempts to create a table with an invalid name. It should use the hex-encoded user name instead, like the directory does.

Jira issue: CRDB-32413

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.