|
40 | 40 | except (ImportError, AttributeError): |
41 | 41 | pyarrow = None |
42 | 42 |
|
43 | | -from google.api_core import datetime_helpers |
44 | 43 | from google.api_core.exceptions import InternalServerError |
45 | 44 | from google.api_core.exceptions import ServiceUnavailable |
46 | 45 | from google.api_core.exceptions import TooManyRequests |
@@ -1428,69 +1427,6 @@ def test_extract_table_compressed(client, to_delete): |
1428 | 1427 | to_delete.insert(0, blob) |
1429 | 1428 |
|
1430 | 1429 |
|
1431 | | -def test_undelete_table(client, to_delete): |
1432 | | - dataset_id = "undelete_table_dataset_{}".format(_millis()) |
1433 | | - table_id = "undelete_table_table_{}".format(_millis()) |
1434 | | - dataset = bigquery.Dataset(client.dataset(dataset_id)) |
1435 | | - dataset.location = "US" |
1436 | | - dataset = client.create_dataset(dataset) |
1437 | | - to_delete.append(dataset) |
1438 | | - |
1439 | | - table = bigquery.Table(dataset.table(table_id), schema=SCHEMA) |
1440 | | - client.create_table(table) |
1441 | | - |
1442 | | - # [START bigquery_undelete_table] |
1443 | | - # TODO(developer): Uncomment the lines below and replace with your values. |
1444 | | - # import time |
1445 | | - # from google.cloud import bigquery |
1446 | | - # client = bigquery.Client() |
1447 | | - # dataset_id = 'my_dataset' # Replace with your dataset ID. |
1448 | | - # table_id = 'my_table' # Replace with your table ID. |
1449 | | - |
1450 | | - table_ref = client.dataset(dataset_id).table(table_id) |
1451 | | - |
1452 | | - # TODO(developer): Choose an appropriate snapshot point as epoch |
1453 | | - # milliseconds. For this example, we choose the current time as we're about |
1454 | | - # to delete the table immediately afterwards. |
1455 | | - snapshot_epoch = int(time.time() * 1000) |
1456 | | - # [END bigquery_undelete_table] |
1457 | | - |
1458 | | - # Due to very short lifecycle of the table, ensure we're not picking a time |
1459 | | - # prior to the table creation due to time drift between backend and client. |
1460 | | - table = client.get_table(table_ref) |
1461 | | - created_epoch = datetime_helpers.to_microseconds(table.created) |
1462 | | - if created_epoch > snapshot_epoch: |
1463 | | - snapshot_epoch = created_epoch |
1464 | | - |
1465 | | - # [START bigquery_undelete_table] |
1466 | | - |
1467 | | - # "Accidentally" delete the table. |
1468 | | - client.delete_table(table_ref) # API request |
1469 | | - |
1470 | | - # Construct the restore-from table ID using a snapshot decorator. |
1471 | | - snapshot_table_id = "{}@{}".format(table_id, snapshot_epoch) |
1472 | | - source_table_ref = client.dataset(dataset_id).table(snapshot_table_id) |
1473 | | - |
1474 | | - # Choose a new table ID for the recovered table data. |
1475 | | - recovered_table_id = "{}_recovered".format(table_id) |
1476 | | - dest_table_ref = client.dataset(dataset_id).table(recovered_table_id) |
1477 | | - |
1478 | | - # Construct and run a copy job. |
1479 | | - job = client.copy_table( |
1480 | | - source_table_ref, |
1481 | | - dest_table_ref, |
1482 | | - # Location must match that of the source and destination tables. |
1483 | | - location="US", |
1484 | | - ) # API request |
1485 | | - |
1486 | | - job.result() # Waits for job to complete. |
1487 | | - |
1488 | | - print( |
1489 | | - "Copied data from deleted table {} to {}".format(table_id, recovered_table_id) |
1490 | | - ) |
1491 | | - # [END bigquery_undelete_table] |
1492 | | - |
1493 | | - |
1494 | 1430 | def test_client_query_legacy_sql(client): |
1495 | 1431 | """Run a query with Legacy SQL explicitly set""" |
1496 | 1432 | # [START bigquery_query_legacy] |
|
0 commit comments