should be it

This commit is contained in:
2025-10-24 19:21:19 -05:00
parent a4b23fc57c
commit f09560c7b1
14047 changed files with 3161551 additions and 1 deletions

View File

@@ -0,0 +1,128 @@
# name: test/sql/alter/map/add_column_in_struct.test
# group: [map]
query I
WITH cte as (
select a::MAP(STRUCT(n INTEGER, m INTEGER), STRUCT(i INTEGER, j INTEGER)) a from
VALUES
(MAP {ROW(3,3): ROW(1, 1)}),
(MAP {ROW(4,4): ROW(2, 2)})
t(a)
)
SELECT remap_struct(
a,
NULL::MAP(STRUCT(n INTEGER, m INTEGER), STRUCT(i INTEGER, j INTEGER, k INTEGER)),
{
'key': 'key',
'value': (
'value', {
'i': 'i',
'j': 'j'
}
)
},
{
'value': {
'k': NULL::INTEGER
}
}
) from cte;
----
{{'n': 3, 'm': 3}={'i': 1, 'j': 1, 'k': NULL}}
{{'n': 4, 'm': 4}={'i': 2, 'j': 2, 'k': NULL}}
statement ok
CREATE TABLE test(
s MAP(
STRUCT(
n INTEGER,
m INTEGER
),
STRUCT(
i INTEGER,
j INTEGER
)
)
)
statement ok
INSERT INTO test VALUES
(MAP {ROW(3,3): ROW(1, 1)}),
(MAP {ROW(4,4): ROW(2, 2)})
# add a column to the struct inside the 'key'
statement ok
ALTER TABLE test ADD COLUMN s.key.k INTEGER
query I
select * from test;
----
{{'n': 3, 'm': 3, 'k': NULL}={'i': 1, 'j': 1}}
{{'n': 4, 'm': 4, 'k': NULL}={'i': 2, 'j': 2}}
# add a column to the struct inside the 'value'
statement ok
ALTER TABLE test ADD COLUMN s.value.b VARCHAR
query I
select * from test;
----
{{'n': 3, 'm': 3, 'k': NULL}={'i': 1, 'j': 1, 'b': NULL}}
{{'n': 4, 'm': 4, 'k': NULL}={'i': 2, 'j': 2, 'b': NULL}}
statement ok
drop table test;
statement ok
CREATE TABLE test(
s STRUCT(
a MAP(
STRUCT(
n INTEGER,
m INTEGER
),
STRUCT(
i INTEGER,
j INTEGER
)
)
)
)
statement ok
INSERT INTO test VALUES
(ROW(MAP {ROW(3,3): ROW(1, 1)})),
(ROW(MAP {ROW(4,4): ROW(2, 2)}))
# add a column to the struct in the 'key'
statement ok
ALTER TABLE test ADD COLUMN s.a.key.k INTEGER
query I
select * from test;
----
{'a': {{'n': 3, 'm': 3, 'k': NULL}={'i': 1, 'j': 1}}}
{'a': {{'n': 4, 'm': 4, 'k': NULL}={'i': 2, 'j': 2}}}
# add a column to the struct in the 'value'
statement ok
ALTER TABLE test ADD COLUMN s.a.value.b VARCHAR
query I
select * from test;
----
{'a': {{'n': 3, 'm': 3, 'k': NULL}={'i': 1, 'j': 1, 'b': NULL}}}
{'a': {{'n': 4, 'm': 4, 'k': NULL}={'i': 2, 'j': 2, 'b': NULL}}}
# attempt to add a field to a map
statement error
ALTER TABLE test ADD COLUMN s.a.not_key INTEGER
----
Binder Error: Column a is not a struct - ALTER TABLE can only add fields to structs
# attempt to add the 'key' field to a map
statement error
ALTER TABLE test ADD COLUMN s.a.key INTEGER
----
Binder Error: Column a is not a struct - ALTER TABLE can only add fields to structs

View File

@@ -0,0 +1,98 @@
# name: test/sql/alter/map/drop_column_in_struct.test
# group: [map]
statement ok
CREATE TABLE test(
s MAP(
STRUCT(
n INTEGER,
m INTEGER
),
STRUCT(
i INTEGER,
j INTEGER
)
)
)
statement ok
INSERT INTO test VALUES
(MAP {ROW(3,3): ROW(1, 1)}),
(MAP {ROW(4,4): ROW(2, 2)})
# attempt to drop 'key' from the map
statement error
ALTER TABLE test DROP COLUMN s.key
----
Catalog Error: Cannot drop field 'key' from column 's' - it's not a struct
# attempt to drop 'value' from the map
statement error
ALTER TABLE test DROP COLUMN s.value
----
Catalog Error: Cannot drop field 'value' from column 's' - it's not a struct
# drop a column from the struct inside the 'value'
statement ok
ALTER TABLE test DROP COLUMN s.value.j
query I
select * from test;
----
{{'n': 3, 'm': 3}={'i': 1}}
{{'n': 4, 'm': 4}={'i': 2}}
# drop a column from the struct inside the 'key'
statement ok
ALTER TABLE test DROP COLUMN s.key.n
query I
select * from test;
----
{{'m': 3}={'i': 1}}
{{'m': 4}={'i': 2}}
statement ok
drop table test;
statement ok
CREATE TABLE test(
s STRUCT(
a MAP(
STRUCT(
n INTEGER,
m INTEGER
),
STRUCT(
i INTEGER,
j INTEGER
)
)
)
)
statement ok
INSERT INTO test VALUES
(ROW(MAP {ROW(3,3): ROW(1, 1)})),
(ROW(MAP {ROW(4,4): ROW(2, 2)}))
# drop a column from the struct in the 'key'
statement ok
ALTER TABLE test DROP COLUMN s.a.key.m
query I
select * from test;
----
{'a': {{'n': 3}={'i': 1, 'j': 1}}}
{'a': {{'n': 4}={'i': 2, 'j': 2}}}
# drop a column from the struct in the 'value'
statement ok
ALTER TABLE test DROP COLUMN s.a.value.j
query I
select * from test;
----
{'a': {{'n': 3}={'i': 1}}}
{'a': {{'n': 4}={'i': 2}}}

View File

@@ -0,0 +1,98 @@
# name: test/sql/alter/map/rename_column_in_struct.test
# group: [map]
statement ok
CREATE TABLE test(
s MAP(
STRUCT(
n INTEGER,
m INTEGER
),
STRUCT(
i INTEGER,
j INTEGER
)
)
)
statement ok
INSERT INTO test VALUES
(MAP {ROW(3,3): ROW(1, 1)}),
(MAP {ROW(4,4): ROW(2, 2)})
# attempt to rename 'key'
statement error
ALTER TABLE test RENAME COLUMN s.key to anything
----
Catalog Error: Cannot rename field 'key' from column 's' - can only rename fields inside a struct
# attempt to rename 'value'
statement error
ALTER TABLE test RENAME COLUMN s.value to anything
----
Catalog Error: Cannot rename field 'value' from column 's' - can only rename fields inside a struct
# rename a column from the struct inside the 'value'
statement ok
ALTER TABLE test RENAME COLUMN s.value.j TO abc
query I
select * from test;
----
{{'n': 3, 'm': 3}={'i': 1, 'abc': 1}}
{{'n': 4, 'm': 4}={'i': 2, 'abc': 2}}
# rename a column from the struct inside the 'key'
statement ok
ALTER TABLE test RENAME COLUMN s.key.n TO def
query I
select * from test;
----
{{'def': 3, 'm': 3}={'i': 1, 'abc': 1}}
{{'def': 4, 'm': 4}={'i': 2, 'abc': 2}}
statement ok
drop table test;
statement ok
CREATE TABLE test(
s STRUCT(
a MAP(
STRUCT(
n INTEGER,
m INTEGER
),
STRUCT(
i INTEGER,
j INTEGER
)
)
)
)
statement ok
INSERT INTO test VALUES
(ROW(MAP {ROW(3,3): ROW(1, 1)})),
(ROW(MAP {ROW(4,4): ROW(2, 2)}))
# rename a column from the struct in the 'key'
statement ok
ALTER TABLE test RENAME COLUMN s.a.key.m TO abc
query I
select * from test;
----
{'a': {{'n': 3, 'abc': 3}={'i': 1, 'j': 1}}}
{'a': {{'n': 4, 'abc': 4}={'i': 2, 'j': 2}}}
# rename a column from the struct in the 'value'
statement ok
ALTER TABLE test RENAME COLUMN s.a.value.j TO def
query I
select * from test;
----
{'a': {{'n': 3, 'abc': 3}={'i': 1, 'def': 1}}}
{'a': {{'n': 4, 'abc': 4}={'i': 2, 'def': 2}}}