Skip to content

Commit

Permalink
Merge #29006
Browse files Browse the repository at this point in the history
29006: backport-2.1: fix the handling of SQL types r=knz a=knz

Backport 1/1 commits from #28937.
Backport 1/1 commits from #28942.
Backport 17/17 commits from #28943.
Backport 1/1 commits from #28944.
Backport 1/1 commits from #28945.
Backport 1/1 commits from #28949.
Backport 2/2 commits from #28950.
Backport 1/1 commits from #28951 (#28959).
Backport 1/1 commits from #28952 (#28959).
Backport 1/1 commits from #28955 (#28959).
Backport 1/1 commits from #28959.
Backport 1/1 commits from #28959.
Backport 1/1 commits from #28690.

cc @cockroachdb/release 

Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
  • Loading branch information
craig[bot] and knz committed Aug 24, 2018
2 parents eed302c + 4f27ce0 commit 295375f
Show file tree
Hide file tree
Showing 199 changed files with 5,362 additions and 4,501 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.pb.* -diff
*.golden -diff
2 changes: 1 addition & 1 deletion docs/RFCS/20170317_settings_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ A new system.settings table, keyed by string settings names would be created.
CREATE TABLE system.settings (
name STRING PRIMARY KEY,
value STRING,
updated TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
updated TIMESTAMPTZ DEFAULT NOW() NOT NULL,
valueType char NOT NULL DEFAULT 's',
)
```
Expand Down
14 changes: 7 additions & 7 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -1793,12 +1793,12 @@ reference_actions ::=

numeric ::=
'INT'
| 'INTEGER'
| 'INT2'
| 'SMALLINT'
| 'INT4'
| 'INT8'
| 'INT64'
| 'INTEGER'
| 'SMALLINT'
| 'BIGINT'
| 'REAL'
| 'FLOAT4'
Expand Down Expand Up @@ -1887,8 +1887,8 @@ when_clause ::=
'WHEN' a_expr 'THEN' a_expr

character_base ::=
'CHARACTER' opt_varying
| 'CHAR' opt_varying
char_aliases
| char_aliases 'VARYING'
| 'VARCHAR'
| 'STRING'

Expand Down Expand Up @@ -2040,9 +2040,9 @@ tuple1_unambiguous_values ::=
a_expr ','
| a_expr ',' expr_list

opt_varying ::=
'VARYING'
|
char_aliases ::=
'CHAR'
| 'CHARACTER'

window_definition ::=
window_name 'AS' window_specification
Expand Down
4 changes: 2 additions & 2 deletions pkg/ccl/backupccl/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ func TestBackupRestoreResume(t *testing.T) {
t.Run("backup", func(t *testing.T) {
sqlDB := sqlutils.MakeSQLRunner(outerDB.DB)
backupStartKey := backupTableDesc.PrimaryIndexSpan().Key
backupEndKey, err := sqlbase.MakePrimaryIndexKey(backupTableDesc, numAccounts/2)
backupEndKey, err := sqlbase.TestingMakePrimaryIndexKey(backupTableDesc, numAccounts/2)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -798,7 +798,7 @@ func TestBackupRestoreResume(t *testing.T) {
if err != nil {
t.Fatal(err)
}
restoreHighWaterMark, err := sqlbase.MakePrimaryIndexKey(backupTableDesc, numAccounts/2)
restoreHighWaterMark, err := sqlbase.TestingMakePrimaryIndexKey(backupTableDesc, numAccounts/2)
if err != nil {
t.Fatal(err)
}
Expand Down
22 changes: 11 additions & 11 deletions pkg/ccl/importccl/import_stmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,16 +483,16 @@ COPY t (a, b, c) FROM stdin;
ORDER BY descriptor_name
`: {{
`CREATE TABLE a (
i INTEGER NOT NULL,
k INTEGER NULL,
i INT NOT NULL,
k INT NULL,
CONSTRAINT a_pkey PRIMARY KEY (i ASC),
CONSTRAINT a_k_fkey FOREIGN KEY (k) REFERENCES a (i),
INDEX a_auto_index_a_k_fkey (k ASC),
CONSTRAINT a_i_fkey FOREIGN KEY (i) REFERENCES b (j),
FAMILY "primary" (i, k)
)`}, {
`CREATE TABLE b (
j INTEGER NOT NULL,
j INT NOT NULL,
CONSTRAINT b_pkey PRIMARY KEY (j ASC),
CONSTRAINT b_j_fkey FOREIGN KEY (j) REFERENCES a (i),
FAMILY "primary" (j)
Expand Down Expand Up @@ -625,14 +625,14 @@ COPY t (a, b, c) FROM stdin;

const (
testPgdumpCreateCities = `CREATE TABLE cities (
city STRING(80) NOT NULL,
city VARCHAR(80) NOT NULL,
CONSTRAINT cities_pkey PRIMARY KEY (city ASC),
FAMILY "primary" (city)
)`
testPgdumpCreateWeather = `CREATE TABLE weather (
city STRING(80) NULL,
temp_lo INTEGER NULL,
temp_hi INTEGER NULL,
city VARCHAR(80) NULL,
temp_lo INT NULL,
temp_hi INT NULL,
prcp FLOAT4 NULL,
date DATE NULL,
CONSTRAINT weather_city_fkey FOREIGN KEY (city) REFERENCES cities (city),
Expand Down Expand Up @@ -2220,7 +2220,7 @@ func TestImportPgDump(t *testing.T) {
// Verify table schema because PKs and indexes are at the bottom of pg_dump.
sqlDB.CheckQueryResults(t, `SHOW CREATE TABLE simple`, [][]string{{
"simple", `CREATE TABLE simple (
i INTEGER NOT NULL,
i INT NOT NULL,
s STRING NULL,
b BYTES NULL,
CONSTRAINT simple_pkey PRIMARY KEY (i ASC),
Expand Down Expand Up @@ -2262,7 +2262,7 @@ func TestImportPgDump(t *testing.T) {
// Verify table schema because PKs and indexes are at the bottom of pg_dump.
sqlDB.CheckQueryResults(t, `SHOW CREATE TABLE second`, [][]string{{
"second", `CREATE TABLE second (
i INTEGER NOT NULL,
i INT NOT NULL,
s STRING NULL,
CONSTRAINT second_pkey PRIMARY KEY (i ASC),
FAMILY "primary" (i, s)
Expand Down Expand Up @@ -2296,8 +2296,8 @@ func TestImportPgDump(t *testing.T) {
if c.expected == expectAll {
sqlDB.CheckQueryResults(t, `SHOW CREATE TABLE seqtable`, [][]string{{
"seqtable", `CREATE TABLE seqtable (
a INTEGER NULL DEFAULT nextval('public.a_seq':::STRING),
b INTEGER NULL,
a INT NULL DEFAULT nextval('public.a_seq':::STRING),
b INT NULL,
FAMILY "primary" (a, b, rowid)
)`,
}})
Expand Down
26 changes: 13 additions & 13 deletions pkg/ccl/importccl/read_import_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func mysqlColToCockroach(
case mysqltypes.VarChar:
def.Type = strOpt(coltypes.VarChar, length)
case mysqltypes.Text:
def.Type = strOpt(coltypes.Text, length)
def.Type = strOpt(coltypes.String, length)

case mysqltypes.Blob:
def.Type = coltypes.Bytes
Expand All @@ -511,25 +511,25 @@ func mysqlColToCockroach(
def.Type = coltypes.Bytes

case mysqltypes.Int8:
def.Type = coltypes.SmallInt
def.Type = coltypes.Int2
case mysqltypes.Uint8:
def.Type = coltypes.SmallInt
def.Type = coltypes.Int2
case mysqltypes.Int16:
def.Type = coltypes.SmallInt
def.Type = coltypes.Int2
case mysqltypes.Uint16:
def.Type = coltypes.SmallInt
def.Type = coltypes.Int2
case mysqltypes.Int24:
def.Type = coltypes.Int
def.Type = coltypes.Int4
case mysqltypes.Uint24:
def.Type = coltypes.Int
def.Type = coltypes.Int4
case mysqltypes.Int32:
def.Type = coltypes.Int
def.Type = coltypes.Int4
case mysqltypes.Uint32:
def.Type = coltypes.Int
def.Type = coltypes.Int4
case mysqltypes.Int64:
def.Type = coltypes.BigInt
def.Type = coltypes.Int8
case mysqltypes.Uint64:
def.Type = coltypes.BigInt
def.Type = coltypes.Int8

case mysqltypes.Float32:
def.Type = coltypes.Float4
Expand All @@ -548,7 +548,7 @@ func mysqlColToCockroach(
case mysqltypes.Datetime:
def.Type = coltypes.TimestampWithTZ
case mysqltypes.Year:
def.Type = coltypes.SmallInt
def.Type = coltypes.Int2

case mysqltypes.Enum:
def.Type = coltypes.String
Expand Down Expand Up @@ -599,7 +599,7 @@ func strOpt(in *coltypes.TString, i int) coltypes.T {
return in
}
res := *in
res.N = i
res.N = uint(i)
return &res
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/ccl/importccl/read_import_pgdump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ COPY public.t (s) FROM stdin;
}
fmt.Fprintf(&sb, "%s;\n", s)
}
const expect = `CREATE TABLE public.second (i INTEGER NOT NULL, s TEXT);
const expect = `CREATE TABLE public.second (i INT NOT NULL, s STRING);
COPY public.second (i, s) FROM STDIN;
"0" "0";
"1" "1";
Expand All @@ -134,7 +134,7 @@ COPY public.second (i, s) FROM STDIN;
"6" "6";
COPY done;
ALTER TABLE public.second ADD CONSTRAINT second_pkey PRIMARY KEY (i);
CREATE TABLE public.t (s TEXT);
CREATE TABLE public.t (s STRING);
COPY public.t (s) FROM STDIN;
"";
"\\.";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CREATE TABLE everything (
i INT PRIMARY KEY,
i INT4 PRIMARY KEY,

c CHAR(10) NOT NULL,
s VARCHAR(100),
Expand All @@ -21,11 +21,11 @@ CREATE TABLE everything (
nu NUMERIC(10, 0),
d53 DECIMAL(5,3),

iw INT NOT NULL,
iz INT,
iw INT4 NOT NULL,
iz INT4,
ti SMALLINT,
si SMALLINT,
mi INT,
mi INT4,
bi BIGINT,

fl FLOAT4 NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CREATE TABLE second (
i INT PRIMARY KEY,
k INT,
i INT4 PRIMARY KEY,
k INT4,
UNIQUE INDEX ik (i, k),
INDEX ki (k, i),
CONSTRAINT second_ibfk_1 FOREIGN KEY (k) REFERENCES simple (i) ON UPDATE CASCADE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CREATE SEQUENCe simple_auto_inc;

CREATE TABLE simple (
i INT PRIMARY KEY DEFAULT nextval('simple_auto_inc':::string),
i INT4 PRIMARY KEY DEFAULT nextval('simple_auto_inc':::string),
s text,
b bytea
)
10 changes: 5 additions & 5 deletions pkg/ccl/importccl/testdata/mysqldump/third.cockroach-schema.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
CREATE TABLE third (
i INT PRIMARY KEY,
a INT,
b INT,
c INT,
i INT4 PRIMARY KEY,
a INT4,
b INT4,
c INT4,
INDEX a (a, b),
INDEX c (c),
FOREIGN KEY (a, b) REFERENCES second (i, k),
FOREIGN KEY (c) REFERENCES third (i) ON UPDATE CASCADE
);
);
2 changes: 1 addition & 1 deletion pkg/ccl/partitionccl/partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ func allPartitioningTests(rng *rand.Rand) []partitioningTest {
case sqlbase.ColumnType_COLLATEDSTRING:
typ.Locale = sqlbase.RandCollationLocale(rng)
colType = fmt.Sprintf(`STRING COLLATE %s`, *typ.Locale)
case sqlbase.ColumnType_JSON:
case sqlbase.ColumnType_JSONB:
// Not indexable.
continue
}
Expand Down
Loading

0 comments on commit 295375f

Please sign in to comment.