cockroachdb / cockroachdb/cockroach

userfile: IMPORT doesn't correctly build a default 'host' for users with special characters in the username

Open
#99,971 2 comments 0 reactions 0 assignees View on GitHub
A-disaster-recovery A-import C-bug T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

**Describe the problem**

Create a user with a `.` in the username (or any other special character).

```
CREATE USER "my.user" WITH PASSWORD 'p';
```

Use this user to upload a small csv file for future import:

```
cockroach userfile upload data.csv data.csv -u my.user
```

Note that this creates the userfiles table with names in a hex format (`encode('my.user', 'hex')`):

```
public | userfilesx_6d792e75736572_upload_files | table | my.user | 0 | NULL
public | userfilesx_6d792e75736572_upload_payload | table | my.user | 0 | NULL
```

Now create a table and try to import that file:

```
my.user@localhost:26257/defaultdb> create table t(id uuid primary key);
CREATE TABLE

Time: 17ms total (execution 17ms / network 0ms)

my.user@localhost:26257/defaultdb> import into t (id) csv data ('userfile:///data.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_my.user"_upload_files (filename STRING PRIMARY KEY,
^
HINT: try \h CREATE TABLE
```

It looks like it's attempting to deal with a table called `"userfiles_my.user"_upload_files` instead of the hex-encoded version.

Running this as a user without a special character in the name works fine.

Jira issue: CRDB-26160

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with a username containing a dot, using `cockroach userfile upload` followed by `IMPORT INTO ... CSV DATA ('userfile:///data.csv')`. Trace the userfile upload and import entry points that construct the file-table name, then verify that the import uses the hex-encoded table name and succeeds for special-character usernames.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.