Skip to content

Commit a5f3a3f

Browse files
committed
Test dynamic column names in resultsets
Test for crate/crate#17580
1 parent e0bf903 commit a5f3a3f

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

tests/bwc/test_upgrade.py

+24-11
Original file line numberDiff line numberDiff line change
@@ -258,20 +258,22 @@ def _do_upgrade(self,
258258
assert_busy(lambda: self.assert_green(conn, 'blob', 'b1'))
259259
self.assertIsNotNone(container.get(digest))
260260

261+
accumulated_dynamic_column_names: list[str] = []
261262
self._process_on_stop()
262263
for version_def in versions[1:]:
263264
timestamp = datetime.utcnow().isoformat(timespec='seconds')
264265
print(f"{timestamp} Upgrade to: {version_def.version}")
265-
self.assert_data_persistence(version_def, nodes, digest, paths)
266+
self.assert_data_persistence(version_def, nodes, digest, paths, accumulated_dynamic_column_names)
266267
# restart with latest version
267268
version_def = versions[-1]
268-
self.assert_data_persistence(version_def, nodes, digest, paths)
269+
self.assert_data_persistence(version_def, nodes, digest, paths, accumulated_dynamic_column_names)
269270

270271
def assert_data_persistence(self,
271272
version_def: VersionDef,
272273
nodes: int,
273274
digest: str,
274-
paths: Iterable[str]):
275+
paths: Iterable[str],
276+
accumulated_dynamic_column_names: list[str]):
275277
env = prepare_env(version_def.java_home)
276278
version = version_def.version
277279
cluster = self._new_cluster(version, nodes, data_paths=paths, settings=self.CLUSTER_SETTINGS, env=env)
@@ -303,15 +305,26 @@ def assert_data_persistence(self,
303305
cursor.execute(f'select * from versioned."{table}"')
304306
cursor.execute(f'insert into versioned."{table}" (id, col_int) values (?, ?)', [str(uuid4()), 1])
305307

308+
# to trigger `alter` stmt bug(https://github.com/crate/crate/pull/17178) that falsely updated the table's
309+
# version created setting that resulted in oids instead of column names in resultsets
310+
cursor.execute('ALTER TABLE doc.parted SET ("refresh_interval" = 900)')
311+
306312
# older versions had a bug that caused this to fail
307-
if version in ('latest-nightly', '3.2'):
308-
# Test that partition and dynamic columns can be created
309-
obj = {"t_" + version.replace('.', '_'): True}
310-
args = (str(uuid4()), version, obj)
311-
cursor.execute(
312-
'INSERT INTO doc.parted (id, version, cols) values (?, ?, ?)',
313-
args
314-
)
313+
# Test that partition and dynamic columns can be created
314+
key = "t_" + version.replace('.', '_')
315+
obj = {key: True}
316+
args = (str(uuid4()), version, obj)
317+
cursor.execute(
318+
'INSERT INTO doc.parted (id, version, cols) VALUES (?, ?, ?)',
319+
args
320+
)
321+
cursor.execute('REFRESH TABLE doc.parted')
322+
accumulated_dynamic_column_names.append(key)
323+
cursor.execute('SELECT cols FROM doc.parted')
324+
result = cursor.fetchall()
325+
for row in result:
326+
for name in row[0].keys():
327+
self.assertIn(name, accumulated_dynamic_column_names)
315328
self._process_on_stop()
316329

317330
def assert_green(self, conn: Connection, schema: str, table_name: str):

0 commit comments

Comments
 (0)