MCPcopy Create free account
hub / github.com/apache/impala / test_execute_rollback

Method test_execute_rollback

tests/query_test/test_iceberg.py:368–437  ·  view source on GitHub ↗

Test for EXECUTE ROLLBACK.

(self, unique_database)

Source from the content-addressed store, hash-verified

366 self.run_test_case('QueryTest/iceberg-rollback-negative', vector)
367
368 def test_execute_rollback(self, unique_database):
369 """Test for EXECUTE ROLLBACK."""
370 iceberg_catalogs = IcebergCatalogs(unique_database)
371 for catalog_properties in iceberg_catalogs.get_iceberg_catalog_properties():
372 # Create a table with multiple snapshots.
373 tbl_name = unique_database + ".iceberg_execute_rollback"
374 # We are setting the TIMEZONE query option in this test, so let's create a local
375 # impala client.
376 with self.create_impala_client() as impalad_client:
377 orig_timezone = 'America/Los_Angeles'
378 impalad_client.execute("SET TIMEZONE='" + orig_timezone + "'")
379 impalad_client.execute("""
380 create table {0} (i int) stored as iceberg
381 TBLPROPERTIES ({1})""".format(tbl_name, catalog_properties))
382 initial_snapshots = 3
383 for i in range(initial_snapshots):
384 impalad_client.execute("INSERT INTO {0} VALUES ({1})".format(tbl_name, i))
385 snapshots = get_snapshots(impalad_client, tbl_name,
386 expected_result_size=initial_snapshots)
387
388 output = self.rollback_to_id(tbl_name, snapshots[1].get_snapshot_id())
389 LOG.info("success output={0}".format(output))
390
391 # We rolled back, but that creates a new snapshot, so now there are 4.
392 snapshots = get_snapshots(impalad_client, tbl_name, expected_result_size=4)
393 # The new snapshot has the same id (and parent id) as the snapshot we rolled back
394 # to, but it has a different creation time.
395 assert snapshots[1].get_snapshot_id() == snapshots[3].get_snapshot_id()
396 assert snapshots[1].get_parent_id() == snapshots[3].get_parent_id()
397 assert snapshots[1].get_creation_time() < snapshots[3].get_creation_time()
398 # The "orphaned" snapshot is now not a current ancestor.
399 assert not snapshots[2].is_current_ancestor()
400
401 # We cannot roll back to a snapshot that is not a current ancestor.
402 output = self.rollback_to_id_expect_failure(tbl_name,
403 snapshots[2].get_snapshot_id(),
404 expected_text="Cannot roll back to snapshot, not an ancestor of the current "
405 "state")
406
407 # Create another snapshot.
408 before_insert = datetime.datetime.now(pytz.timezone(orig_timezone))
409 impalad_client.execute("INSERT INTO {0} VALUES ({1})".format(tbl_name, 4))
410 snapshots = get_snapshots(impalad_client, tbl_name, expected_result_size=5)
411
412 # Rollback to before the last insert.
413 self.rollback_to_ts(impalad_client, tbl_name, before_insert)
414 # This creates another snapshot.
415 snapshots = get_snapshots(impalad_client, tbl_name, expected_result_size=6)
416 # The snapshot id is the same, the dates differ
417 assert snapshots[3].get_snapshot_id() == snapshots[5].get_snapshot_id()
418 assert snapshots[3].get_creation_time() < snapshots[5].get_creation_time()
419 assert not snapshots[4].is_current_ancestor()
420
421 # Show that the EXECUTE ROLLBACK is respecting the current timezone.
422 # To do this we try to roll back to a time for which there is no
423 # snapshot, this will fail with an error message that includes the specified
424 # time. We parse out that time. By doing this in two timezones we can see
425 # that the parameter being used was affected by the current timezone.

Callers

nothing calls this directly

Calls 15

rollback_to_idMethod · 0.95
rollback_to_tsMethod · 0.95
IcebergCatalogsClass · 0.90
get_snapshotsFunction · 0.90
rangeFunction · 0.85
create_impala_clientMethod · 0.80
get_snapshot_idMethod · 0.80
get_parent_idMethod · 0.80
get_creation_timeMethod · 0.80

Tested by

no test coverage detected