Skip to content

Commit

Permalink
Shortened user guide
Browse files Browse the repository at this point in the history
- Renamed MY_QUERY_HANDLER_UDF to EXAMPLE_QUERY_HANDLER_UDF
- Renamed BFS_CON to EXAMPLE_BFS_CON
- Removed section "Activating the AAF SLC by Setting a Language Alias"
  • Loading branch information
ckunki committed Oct 25, 2024
1 parent 008854a commit cf8bd2b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 65 deletions.
2 changes: 1 addition & 1 deletion doc/user_guide/example-udf-script/create.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--/
CREATE OR REPLACE PYTHON3_AAF SET SCRIPT "EXAMPLE_SCHEMA"."MY_QUERY_HANDLER_UDF"(...)
CREATE OR REPLACE PYTHON3_AAF SET SCRIPT "EXAMPLE_SCHEMA"."EXAMPLE_QUERY_HANDLER_UDF"(...)
EMITS (outputs VARCHAR(2000000)) AS

from typing import Union
Expand Down
4 changes: 2 additions & 2 deletions doc/user_guide/example-udf-script/execute.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ EXECUTE SCRIPT "AAF_DB_SCHEMA"."AAF_RUN_QUERY_HANDLER"('{
"parameter": "bla-bla",
"udf": {
"schema": "EXAMPLE_SCHEMA",
"name": "MY_QUERY_HANDLER_UDF"
"name": "EXAMPLE_QUERY_HANDLER_UDF"
}
},
"temporary_output": {
"bucketfs_location": {
"connection_name": "BFS_CON",
"connection_name": "EXAMPLE_BFS_CON",
"directory": "temp"
},
"schema_name": "EXAMPLE_TEMP_SCHEMA"
Expand Down
68 changes: 7 additions & 61 deletions doc/user_guide/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,86 +73,32 @@ pip install exasol-advanced-analytics-framework

Exasol executes User Defined Functions (UDFs) in an isolated Container whose root filesystem is derived from a Script Language Container (SLC).

Running the AAF requires an SLC.

#### Uploading the SLC to the BucketFS

The following command
* downloads the specified version `$VERSION` (preferrably the latest) of a prebuilt AAF SLC from the [AAF releases](https://github.com/exasol/advanced-analytics-framework/releases/latest) on GitHub,
Running the AAF requires an SLC. The following command
* downloads the related prebuilt AAF SLC from the [AAF releases](https://github.com/exasol/advanced-analytics-framework/releases) on GitHub,
* uploads the file into the BucketFS,
* and registers it to the database.

The variable `$LANGUAGE_ALIAS` will be reused in [Defining Additional SQL Scripts](#defining-additional-sql-scripts).

```shell
LANGUAGE_ALIAS=PYTHON3_AAF
python -m exasol_advanced_analytics_framework.deploy language-container \
--dsn "$DB_HOST:$DB_PORT" \
--db-user "$DB_USER" \
--db-pass "$DB_PASSWORD" \
--bucketfs-name "$BUCKETFS_NAME" \
--bucketfs-host "$BUCKETFS_HOST" \
--bucketfs-port "$BUCKETFS_PORT" \
--bucketfs-user "$BUCKETFS_USER" \
--bucketfs-password "$BUCKETFS_PASSWORD" \
--bucket "$BUCKETFS_NAME" \
--path-in-bucket "$PATH_IN_BUCKET" \
--version "$VERSION" \
--language-alias "$LANGUAGE_ALIAS"
python -m exasol_advanced_analytics_framework.deploy language-container
```

#### Activating the AAF SLC by Setting a Language Alias

AAF requires activating the AAF SLC as _script language_. This is accomplished by setting a _language alias_, see [Activate the New Script Language Container](https://docs.exasol.com/db/latest/database_concepts/udf_scripts/adding_new_packages_script_languages.htm) in the official Exasol documentation.

When using the AAF command `deploy` `language-container` for uploading the SLC you can activate the language alias on one of two available levels using the corresponding CLI option:

| Level | CLI option | Required Permissions | Persistent? |
|------------------------|---------------------|----------------------------|-------------|
| system level (default) | `--alter-system` | Administration permissions | yes |
| session level (fallback) | `--no-alter-system` | none | no |

By default the AAF deploy command will try to set the language alias on _system level_. If the specified user does not have administration permissions, then the command falls back to using only _session level_.

When setting the language alias on _session level_, you need to set it for each session again. The session used by the AAF deploy command will be closed after the command has terminated and hence the language alias will no longer exist when you want to execute a query handler script.

The following SQL statement displays the language aliases currently defined in the `EXA_PARAMETERS` system table:

```sql
SELECT * FROM exa_parameters WHERE parameter_name='SCRIPT_LANGUAGES';
```

When using the AAF deploy command with CLI option `--no-alter-system` then the command will display the `ALTER SESSION` SQL statements so you can copy them into your SQL editor and execute them for each session.

Here is an example output

```
In SQL, you can activate the SLC by using the following statements:
To activate the SLC only for the current session:
ALTER SESSION SET SCRIPT_LANGUAGES='R=builtin_r JAVA=builtin_java PYTHON3=builtin_python3 PYTHON3_AAF=localzmq+protobuf:///bfsdefault/default/temp/exasol_advanced_analytics_framework_container_release?lang=python#/buckets/bfsdefault/default/temp/exasol_advanced_analytics_framework_container_release/exaudf/exaudfclient_py3';
To activate the SLC on the system:
ALTER SYSTEM SET SCRIPT_LANGUAGES='R=builtin_r JAVA=builtin_java PYTHON3=builtin_python3 PYTHON3_AAF=localzmq+protobuf:///bfsdefault/default/temp/exasol_advanced_analytics_framework_container_release?lang=python#/buckets/bfsdefault/default/temp/exasol_advanced_analytics_framework_container_release/exaudf/exaudfclient_py3';
```
See the documentation in the Exasol Python Extension Common package for [options common to all Exasol extensions](https://github.com/exasol/python-extension-common/blob/0.8.0/doc/user_guide/user-guide).

### Defining Additional SQL Scripts

Besides the BucketFS connection, the SLC, and the Python package AAF also requires some additional Lua scripts to be created in the Exasol database.

The following command deploys the additional scripts to the specified `DB_SCHEMA` using the `LANGUAGE_ALIAS` of the SLC:
The following command deploys the additional scripts to the specified database schema `$AAF_DB_SCHEMA` using the same language alias `$LANGUAGE_ALIAS` as for uploading the SLC before:

```shell
python -m exasol_advanced_analytics_framework.deploy scripts \
--dsn "$DB_HOST:DB_PORT" \
--dsn "$DB_HOST:$DB_PORT" \
--db-user "$DB_USER" \
--db-pass "$DB_PASSWORD" \
--schema "$AAF_DB_SCHEMA" \
--language-alias "$LANGUAGE_ALIAS"
```

When later on [executing the script](#placeholders) you must use the schema name `AAF_DB_SCHEMA` or make it the current schema.

## Usage

The entry point of this framework is `AAF_RUN_QUERY_HANDLER` script. This script is simply a query loop which is responsible for executing the implemented algorithm.
Expand Down Expand Up @@ -238,7 +184,7 @@ In order to execute the example successfully you need to
3. Make sure the database schemas used in the example exist.

The example assumes
* the name for the BucketFS Connection `<CONNECTION_NAME>` to be `BFS_CON`
* the name for the BucketFS Connection `<CONNECTION_NAME>` to be `EXAMPLE_BFS_CON`
* the name for the AAF database schema `<AAF_DB_SCHEMA>` to be `AAF_DB_SCHEMA`, see [Defining Additional SQL Scripts](#defining-additional-sql-scripts).

The following SQL statements create the required database schemas unless they already exist:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/with_db/test_user_guide_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_user_guide_example(database_with_slc, pyexasol_connection, example_db_s
statement = (
(dir / "execute.sql")
.read_text()
.replace("BFS_CON", bucketfs_connection_name)
.replace("EXAMPLE_BFS_CON", bucketfs_connection_name)
.replace("AAF_DB_SCHEMA", schema_name)
.replace("EXAMPLE_SCHEMA", example_db_schemas[0])
.replace("EXAMPLE_TEMP_SCHEMA", example_db_schemas[1])
Expand Down

0 comments on commit cf8bd2b

Please sign in to comment.