Skip to content

Commit 07e2766

Browse files
committed
tests for inheritance schema propagation
Signed-off-by: PJ <[email protected]>
1 parent 7572e08 commit 07e2766

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

pg_lake_table/tests/pytests/test_inheritance.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,77 @@ def test_pg_child(s3, pg_conn, extension, with_default_location):
143143
assert full_plan["Node Type"] == "Append"
144144

145145
pg_conn.rollback()
146+
147+
def test_schema_propagation(s3, pg_conn, extension, with_default_location):
148+
# 1. add column should propagate
149+
run_command(
150+
"""
151+
create table parent (id bigint, value text) using iceberg;
152+
create table child1 (id bigint, value text) using iceberg;
153+
alter table child1 inherit parent;
154+
insert into parent values (1, 'parent');
155+
insert into child1 values (2, 'child1');
156+
alter table parent add column z int default 10;
157+
""",
158+
pg_conn,
159+
)
160+
161+
result = run_query("select * from parent", pg_conn)
162+
assert len(result) == 2
163+
assert len(result[0]) == 3
164+
assert result[0]["z"] == 10
165+
166+
result = run_query("select * from child1", pg_conn)
167+
assert len(result) == 1
168+
assert len(result[0]) == 3
169+
assert result[0]["z"] == 10
170+
171+
pg_conn.rollback()
172+
173+
174+
# 2. rename column should propagate
175+
run_command(
176+
"""
177+
create table parent (id bigint, old_name text) using iceberg;
178+
create table child1 (id bigint, old_name text) using iceberg;
179+
alter table child1 inherit parent;
180+
insert into parent values (1, 'parent');
181+
insert into child1 values (2, 'child1');
182+
alter table parent rename column old_name to new_name;
183+
""",
184+
pg_conn,
185+
)
186+
187+
result = run_query("select id, new_name from parent order by id", pg_conn)
188+
assert len(result) == 2
189+
assert result[0]["new_name"] == "parent"
190+
191+
result = run_query("select id, new_name from child1", pg_conn)
192+
assert len(result) == 1
193+
assert result[0]["new_name"] == "child1"
194+
195+
pg_conn.rollback()
196+
197+
198+
# 3. drop column should not propagate
199+
run_command(
200+
"""
201+
create table parent (id bigint, value text, z int) using iceberg;
202+
create table child1 (id bigint, value text, z int) using iceberg;
203+
alter table child1 inherit parent;
204+
insert into parent values (1, 'parent', 10);
205+
insert into child1 values (2, 'child1', 20);
206+
alter table parent drop column z;
207+
""",
208+
pg_conn,
209+
)
210+
211+
result = run_query("select * from parent", pg_conn)
212+
assert len(result) == 2
213+
assert len(result[0]) == 2
214+
215+
result = run_query("select * from child1", pg_conn)
216+
assert len(result) == 1
217+
assert len(result[0]) == 3
218+
219+
pg_conn.rollback()

0 commit comments

Comments
 (0)