|
88 | 88 | "In this step, we will create the table and populate it with the dataset from [nab-machine-failure.csv]. If you are using CrateDB Cloud, you can use the [URL import] available in the console, otherwise, use the `COPY FROM` statement used below. You can run it in the console in the Admin UI or you can use [Crash], in this case, we are using SQLAlchemy.\n",
|
89 | 89 | "\n",
|
90 | 90 | "[URL import]: https://cratedb.com/docs/cloud/en/latest/reference/overview.html#import-from-url\n",
|
91 |
| - "[nab-machine-failure.csv]: https://github.com/crate/cratedb-datasets/raw/main/timeseries/nab-machine-failure.csv\",\n", |
| 91 | + "[nab-machine-failure.csv]: https://github.com/crate/cratedb-datasets/raw/main/timeseries/nab-machine-failure.csv\n", |
92 | 92 | "[Crash]: https://cratedb.com/docs/crate/crash/en/latest/getting-started.html"
|
93 | 93 | ]
|
94 | 94 | },
|
|
98 | 98 | "metadata": {},
|
99 | 99 | "outputs": [],
|
100 | 100 | "source": [
|
101 |
| - "# Use this connection string template for CrateDB Cloud Clusters\n", |
| 101 | + "# crate://<USER>:<PASSWORD>@<HOST>\n", |
102 | 102 | "CONNECTION_STRING = os.environ.get(\n",
|
103 | 103 | " \"CRATEDB_CONNECTION_STRING\",\n",
|
104 |
| - " \"crate://<USER>:<PASSWORD>@<HOST>\",\n", |
105 |
| - ")\n", |
106 |
| - "\n", |
107 |
| - "# Use this connection string template for CrateDB running locally\n", |
108 |
| - "#CONNECTION_STRING = os.environ.get(\n", |
109 |
| - "# \"CRATEDB_CONNECTION_STRING\",\n", |
110 |
| - "# \"crate://localhost:4200\",\n", |
111 |
| - "# )\n", |
| 104 | + " \"crate://localhost:4200\",\n", |
| 105 | + " )\n", |
112 | 106 | "\n",
|
113 | 107 | "engine = sa.create_engine(CONNECTION_STRING, echo=os.environ.get('DEBUG'))\n",
|
114 | 108 | "\n",
|
115 |
| - "query_create_table = 'CREATE TABLE machine_data (\"timestamp\" TIMESTAMP, \"value\" DOUBLE PRECISION)' \n", |
116 |
| - "query_copy_from = \"COPY machine_data FROM 'https://github.com/crate/cratedb-datasets/raw/main/timeseries/nab-machine-failure.csv';\"\n", |
| 109 | + "sql_ddl = 'CREATE TABLE machine_data (\"timestamp\" TIMESTAMP, \"value\" DOUBLE PRECISION)'\n", |
| 110 | + "sql_load = \"COPY machine_data FROM 'https://github.com/crate/cratedb-datasets/raw/main/timeseries/nab-machine-failure.csv';\"\n", |
| 111 | + "sql_refresh = \"REFRESH TABLE machine_data;\"\n", |
| 112 | + "\n", |
117 | 113 | "with engine.connect() as conn:\n",
|
118 |
| - " conn.execute(sa.text(query_create_table))\n", |
119 |
| - " conn.execute(sa.text(query_copy_from))\n" |
| 114 | + " conn.execute(sa.text(sql_ddl))\n", |
| 115 | + " conn.execute(sa.text(sql_load))\n", |
| 116 | + " conn.execute(sa.text(sql_refresh))" |
120 | 117 | ]
|
121 | 118 | },
|
122 | 119 | {
|
|
0 commit comments