Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update setup_db.ipynb #26

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 58 additions & 35 deletions doc/tutorials/setup_db.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,36 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 5,
"id": "d6b50070-ae30-4c1c-a56a-bd8881bba1a0",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2023-10-30T16:19:59.735069Z",
"start_time": "2023-10-30T16:19:59.728879Z"
}
},
"outputs": [],
"source": [
"# TODO: Move this to a separate configuration notebook. Here we just need to load this configuration from a store.\n",
"from dataclasses import dataclass\n",
"\n",
"@dataclass\n",
"class SandboxConfig:\n",
" EXTERNAL_HOST_NAME = \"192.168.124.93\"\n",
" HOST_PORT = \"8888\"\n",
" EXTERNAL_HOST_NAME: str = \"192.168.124.93\"\n",
" HOST_PORT: int = 8888\n",
"\n",
" @property\n",
" def EXTERNAL_HOST(self):\n",
" return f\"\"\"{self.EXTERNAL_HOST_NAME}:{self.HOST_PORT}\"\"\"\n",
"\n",
" USER = \"sys\"\n",
" PASSWORD = \"exasol\"\n",
" BUCKETFS_PORT = \"6666\"\n",
" BUCKETFS_USER = \"w\"\n",
" BUCKETFS_PASSWORD = \"write\"\n",
" BUCKETFS_USE_HTTPS = False\n",
" BUCKETFS_SERVICE = \"bfsdefault\"\n",
" BUCKETFS_BUCKET = \"default\"\n",
" USER: str = \"sys\"\n",
" PASSWORD: str = \"exasol\"\n",
" BUCKETFS_PORT: int = 6666\n",
" BUCKETFS_USER: str = \"w\"\n",
" BUCKETFS_PASSWORD: str = \"write\"\n",
" BUCKETFS_USE_HTTPS: bool = False\n",
" BUCKETFS_SERVICE: str = \"bfsdefault\"\n",
" BUCKETFS_BUCKET: str = \"default\"\n",
"\n",
" @property\n",
" def EXTERNAL_BUCKETFS_HOST(self):\n",
Expand All @@ -53,11 +58,11 @@
" # Filesystem-Path to the read-only mounted BucketFS inside the running UDF Container\n",
" return f\"/buckets/{self.BUCKETFS_SERVICE}/{self.BUCKETFS_BUCKET}\"\n",
"\n",
" SCRIPT_LANGUAGE_NAME = \"PYTHON3_60\"\n",
" UDF_FLAVOR = \"python3-ds-EXASOL-6.0.0\"\n",
" UDF_RELEASE= \"20190116\"\n",
" UDF_CLIENT = \"exaudfclient\" # or for newer versions of the flavor exaudfclient_py3\n",
" SCHEMA = \"IDA\"\n",
" SCRIPT_LANGUAGE_NAME: str = \"PYTHON3_60\"\n",
" UDF_FLAVOR: str = \"python3-ds-EXASOL-6.0.0\"\n",
" UDF_RELEASE: str = \"20190116\"\n",
" UDF_CLIENT: str = \"exaudfclient\" # or for newer versions of the flavor exaudfclient_py3\n",
" SCHEMA: str = \"IDA\"\n",
"\n",
" @property\n",
" def SCRIPT_LANGUAGES(self):\n",
Expand All @@ -83,41 +88,59 @@
" \"BUCKETFS_PATH\": self.BUCKETFS_PATH\n",
" }\n",
"\n",
"conf = SandboxConfig()"
"#conf = SandboxConfig()"
Shmuma marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 6,
"id": "7f31ccfd-bd6d-435a-9f4c-ae2e5af04ea3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"creates Schema in 42.64ms\n"
]
"metadata": {
"ExecuteTime": {
"end_time": "2023-10-30T16:20:00.552424Z",
"start_time": "2023-10-30T16:20:00.540210Z"
}
],
},
"outputs": [],
"source": [
"import pyexasol\n",
"from stopwatch import Stopwatch\n",
"stopwatch = Stopwatch()\n",
"\n",
"with pyexasol.connect(dsn=conf.EXTERNAL_HOST, user=conf.USER, password=conf.PASSWORD, compression=True) as conn:\n",
" conn.execute(query=\"CREATE SCHEMA IF NOT EXISTS {schema!i}\", query_params=conf.params)\n",
"def setup_schema(conf: SandboxConfig):\n",
" stopwatch = Stopwatch()\n",
"\n",
"print(f\"creates Schema in {stopwatch}\")"
" with pyexasol.connect(dsn=conf.EXTERNAL_HOST, user=conf.USER, password=conf.PASSWORD, compression=True) as conn:\n",
" conn.execute(query=\"CREATE SCHEMA IF NOT EXISTS {schema!i}\", query_params=conf.params)\n",
"\n",
" print(f\"Schema created in {stopwatch}\")"
]
},
{
"cell_type": "markdown",
"source": [
"# Usage \n",
"This notebook could be used in other notebooks like this:\n",
"\n",
"```\n",
"%run ../setup_db.ipynb\n",
"conf = SandboxConfig(EXTERNAL_HOST_NAME=\"127.0.0.1\", HOST_PORT=8563)\n",
"setup_schema(conf)\n",
"```"
],
"metadata": {
"collapsed": false
},
"id": "26d6af42cc6d777f"
},
{
"cell_type": "code",
"execution_count": null,
"id": "fd30de4d-78c1-49cb-a86a-825ee3d42f6d",
"metadata": {},
"outputs": [],
"source": []
"source": [],
"metadata": {
"collapsed": false
},
"id": "207efa4935251bf5"
}
],
"metadata": {
Expand Down
Loading