|
1 | 1 | { |
2 | 2 | "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "id": "e6f1073c", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "\"\"\"Utilities for restoring deleted BigQuery datasets and tables.\"\"\"\n", |
| 11 | + "from google.cloud import bigquery\n", |
| 12 | + "\n", |
| 13 | + "client = bigquery.Client()\n" |
| 14 | + ] |
| 15 | + }, |
3 | 16 | { |
4 | 17 | "cell_type": "code", |
5 | 18 | "execution_count": null, |
|
10 | 23 | }, |
11 | 24 | "outputs": [], |
12 | 25 | "source": [ |
13 | | - "# sql_engine: bigquery\n", |
14 | | - "# output_variable: df\n", |
15 | | - "# start _sql\n", |
16 | | - "_sql = \"\"\"\n", |
| 26 | + "QUERY = \"\"\"\n", |
17 | 27 | "## [Restore deleted dataset](https://docs.cloud.google.com/bigquery/docs/restore-deleted-datasets#restore_a_dataset)\n", |
18 | 28 | "UNDROP SCHEMA httparchive.crawl;\n", |
19 | | - "\"\"\" # end _sql\n", |
20 | | - "from google.colab.sql import bigquery as _bqsqlcell\n", |
21 | | - "df = _bqsqlcell.run(_sql)\n", |
22 | | - "df" |
| 29 | + "\"\"\"\n", |
| 30 | + "client.query(QUERY).result()" |
23 | 31 | ] |
24 | 32 | }, |
25 | 33 | { |
|
31 | 39 | }, |
32 | 40 | "outputs": [], |
33 | 41 | "source": [ |
34 | | - "## [Restore deleted table](https://docs.cloud.google.com/bigquery/docs/restore-deleted-tables#restore_a_table)\n", |
| 42 | + "# [Restore deleted table]\n", |
| 43 | + "# https://docs.cloud.google.com/bigquery/docs/restore-deleted-tables#restore_a_table\n", |
35 | 44 | "!date -d '2025-08-04 16:00:00.000000Z' +%s000\n", |
36 | | - "!bq cp httparchive.crawl.pages@1759670400000 httparchive.crawl_staging.pages_restored_20250804" |
| 45 | + "!bq cp httparchive.crawl.pages@1759670400000 httparchive.crawl_staging.pages_restored_20250804\n" |
37 | 46 | ] |
38 | 47 | }, |
39 | 48 | { |
|
46 | 55 | }, |
47 | 56 | "outputs": [], |
48 | 57 | "source": [ |
49 | | - "# sql_engine: bigquery\n", |
50 | | - "# output_variable: df\n", |
51 | | - "# start _sql\n", |
52 | | - "_sql = \"\"\"\n", |
| 58 | + "QUERY = \"\"\"\n", |
53 | 59 | "## [Restore a table to a specific point in time](https://cloud.google.com/bigquery/docs/restore-tables#restoring_a_table_to_a_specific_point_in_time)\n", |
54 | 60 | "CREATE TABLE httparchive.crawl_staging.pages_restored_20250804 AS\n", |
55 | 61 | "SELECT *\n", |
56 | 62 | "FROM httparchive.crawl.pages\n", |
57 | 63 | " FOR SYSTEM_TIME AS OF TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 HOUR);\n", |
58 | | - "\"\"\" # end _sql\n", |
59 | | - "from google.colab.sql import bigquery as _bqsqlcell\n", |
60 | | - "df = _bqsqlcell.run(_sql)\n", |
61 | | - "df" |
| 64 | + "\"\"\"\n", |
| 65 | + "client.query(QUERY).result()" |
62 | 66 | ] |
63 | 67 | } |
64 | 68 | ], |
|
0 commit comments