Skip to content

Commit

Permalink
Merge pull request cockroachdb#91743 from ecwall/backport22.1-91702
Browse files Browse the repository at this point in the history
  • Loading branch information
rafiss authored Nov 14, 2022
2 parents 4ca1980 + 7182849 commit 7b98d9c
Show file tree
Hide file tree
Showing 57 changed files with 1,863 additions and 1,859 deletions.
31 changes: 28 additions & 3 deletions pkg/sql/logictest/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4074,11 +4074,36 @@ func (t *logicTest) formatValues(vals []string, valsPerLine int) []string {
var buf bytes.Buffer
tw := tabwriter.NewWriter(&buf, 2, 1, 2, ' ', 0)

for line := 0; line < len(vals)/valsPerLine; line++ {
numLines := len(vals) / valsPerLine
for line := 0; line < numLines; line++ {
maxSubLines := 0
lineOffset := line * valsPerLine

// Split multi-line values into sublines to output correctly formatted rows.
lineSubLines := make([][]string, valsPerLine)
for i := 0; i < valsPerLine; i++ {
fmt.Fprintf(tw, "%s\t", vals[line*valsPerLine+i])
cellSubLines := strings.Split(vals[lineOffset+i], "\n")
lineSubLines[i] = cellSubLines
numSubLines := len(cellSubLines)
if numSubLines > maxSubLines {
maxSubLines = numSubLines
}
}

for j := 0; j < maxSubLines; j++ {
for i := 0; i < len(lineSubLines); i++ {
cellSubLines := lineSubLines[i]
// If a value's #sublines < #maxSubLines, an empty cell (just a "\t") is written to preserve columns.
if j < len(cellSubLines) {
cellSubLine := cellSubLines[j]
// Replace tabs with spaces to prevent them from being interpreted by tabwriter.
cellSubLine = strings.ReplaceAll(cellSubLine, "\t", " ")
fmt.Fprint(tw, cellSubLine)
}
fmt.Fprint(tw, "\t")
}
fmt.Fprint(tw, "\n")
}
fmt.Fprint(tw, "\n")
}
_ = tw.Flush()

Expand Down
14 changes: 7 additions & 7 deletions pkg/sql/logictest/testdata/logic_test/aggregate
Original file line number Diff line number Diff line change
Expand Up @@ -3496,13 +3496,13 @@ query TT
SHOW CREATE osagg_view
----
osagg_view CREATE VIEW public.osagg_view (
disc,
cont
) AS SELECT
percentile_disc(0.50)WITHIN GROUP (ORDER BY f),
percentile_cont(0.50)WITHIN GROUP (ORDER BY f DESC)
FROM
test.public.osagg
disc,
cont
) AS SELECT
percentile_disc(0.50)WITHIN GROUP (ORDER BY f),
percentile_cont(0.50)WITHIN GROUP (ORDER BY f DESC)
FROM
test.public.osagg

# Test malformed ordered-set aggregation.
statement error ordered-set aggregations must have a WITHIN GROUP clause containing one ORDER BY column
Expand Down
14 changes: 7 additions & 7 deletions pkg/sql/logictest/testdata/logic_test/alias_types
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ SHOW CREATE TABLE aliases
----
table_name create_statement
aliases CREATE TABLE public.aliases (
a OID NULL,
b NAME NULL,
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT aliases_pkey PRIMARY KEY (rowid ASC),
FAMILY "primary" (a, rowid),
FAMILY fam_1_b (b)
)
a OID NULL,
b NAME NULL,
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT aliases_pkey PRIMARY KEY (rowid ASC),
FAMILY "primary" (a, rowid),
FAMILY fam_1_b (b)
)

statement ok
INSERT INTO aliases VALUES (100, 'abc')
Expand Down
52 changes: 26 additions & 26 deletions pkg/sql/logictest/testdata/logic_test/alter_column_type
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ show create table t
----
table_name create_statement
t CREATE TABLE public.t (
a INT8 NOT NULL,
i INT8 NULL,
CONSTRAINT t_pkey PRIMARY KEY (a ASC),
INDEX idx2 (i ASC)
)
a INT8 NOT NULL,
i INT8 NULL,
CONSTRAINT t_pkey PRIMARY KEY (a ASC),
INDEX idx2 (i ASC)
)

statement ok
ALTER TABLE t RENAME COLUMN i TO b
Expand Down Expand Up @@ -266,13 +266,13 @@ query TT
SHOW CREATE TABLE t6
----
t6 CREATE TABLE public.t6 (
id INT8 NULL,
id2 STRING NULL,
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT t6_pkey PRIMARY KEY (rowid ASC),
FAMILY f1 (id, rowid),
FAMILY f2 (id2)
)
id INT8 NULL,
id2 STRING NULL,
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT t6_pkey PRIMARY KEY (rowid ASC),
FAMILY f1 (id, rowid),
FAMILY f2 (id2)
)

# Ensure the type of the default column is checked
statement ok
Expand All @@ -298,10 +298,10 @@ query TT
SHOW CREATE TABLE t8
----
t8 CREATE TABLE public.t8 (
x STRING NULL,
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT t8_pkey PRIMARY KEY (rowid ASC)
)
x STRING NULL,
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT t8_pkey PRIMARY KEY (rowid ASC)
)

# Ensure ALTER COLUMN TYPE is disallowed if column is part of primary key.
statement ok
Expand Down Expand Up @@ -387,12 +387,12 @@ show create table t17
----
table_name create_statement
t17 CREATE TABLE public.t17 (
x STRING NULL DEFAULT 'HELLO':::STRING,
y STRING NULL ON UPDATE 'HELLO':::STRING,
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT t17_pkey PRIMARY KEY (rowid ASC),
FAMILY f1 (x, y, rowid)
)
x STRING NULL DEFAULT 'HELLO':::STRING,
y STRING NULL ON UPDATE 'HELLO':::STRING,
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT t17_pkey PRIMARY KEY (rowid ASC),
FAMILY f1 (x, y, rowid)
)


# Ensure ALTER COLUMN TYPE fails if the column is part of an FK relationship.
Expand Down Expand Up @@ -468,10 +468,10 @@ show create table t24
----
table_name create_statement
t24 CREATE TABLE public.t24 (
x STRING NULL,
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT t24_pkey PRIMARY KEY (rowid ASC)
)
x STRING NULL,
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT t24_pkey PRIMARY KEY (rowid ASC)
)

# Ensure USING EXPRESSION rolls back if the USING EXPRESSION does not conform
# to the new type of the column.
Expand Down
Loading

0 comments on commit 7b98d9c

Please sign in to comment.