Skip to content

Commit

Permalink
More review comments [CodeBuild]
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsimb committed Nov 28, 2023
1 parent c4e99e6 commit 625c23a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
15 changes: 9 additions & 6 deletions doc/user_guide/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Transformers Extension Package. See [the latest release](https://github.com/exas
--language-alias <LANGUAGE_ALIAS> \
--version <RELEASE_VERSION> \
--ssl-cert-path <ssl-cert-path> \
--use-ssl-cert-validation \
--use-ssl-cert-validation
```
The `--ssl-cert-path` is optional if your certificate is not in the OS truststore.
The option `--use-ssl-cert-validation`is the default, you can disable it with `--no-use-ssl-cert-validation`.
Expand All @@ -119,19 +119,22 @@ Database connection.
By default, the above command will upload and activate the language container at the System level.
The latter requires you to have the System Privileges, as it will attempt to change DB system settings.
If such privileges cannot be granted the activation can be skipped by using the `--no-alter-system` option.
The command will then print the language activation SQL query, which looks like this:
The command will then print two possible language activation SQL queries, which look like the following:
```sql
ALTER SESSION SET SCRIPT_LANGUAGES=...
ALTER SYSTEM SET SCRIPT_LANGUAGES=...
```
This query activates the language container at the Session level. It doesn't require System Privileges.
However, it must be run every time a new session starts.
These quires represent two alternative ways of activating a language container. The first one activates the
container at the Session level. It doesn't require System Privileges. However, it must be run every time a
new session starts. The second one activates the container at the System level. It needs to be run just once,
but it does require System Privileges. It may be executed by a database administrator.

It is also possible to activate the language without repeatedly uploading the container. If the container
has already been uploaded one can use the `--no-upload_container` option to skip this step.
has already been uploaded one can use the `--no-upload-container` option to skip this step.

By default, overriding language activation is not permitted. If a language with the same alias has already
been activated the command will result in an error. To override the activation, you can use the
`--allow_override` option.
`--allow-override` option.

#### Customized Installation
In this installation, you can install the desired or customized language
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
logger = logging.getLogger(__name__)


class LanguageActiveLevel(Enum):
class LanguageActivationLevel(Enum):
f"""
Language activation level, i.e.
ALTER <LanguageActiveLevel> SET SCRIPT_LANGUAGES=...
ALTER <LanguageActivationLevel> SET SCRIPT_LANGUAGES=...
"""
Session = 'SESSION'
System = 'SYSTEM'
Expand All @@ -40,7 +40,7 @@ def deploy_container(self, allow_override: bool = False) -> None:
otherwise a RuntimeException will be thrown.
"""
path_in_udf = self.upload_container()
self.activate_container(LanguageActiveLevel.System, allow_override, path_in_udf)
self.activate_container(LanguageActivationLevel.System, allow_override, path_in_udf)

def upload_container(self) -> PurePosixPath:
"""
Expand All @@ -57,7 +57,7 @@ def upload_container(self) -> PurePosixPath:
logging.debug("Container is uploaded to bucketfs")
return PurePosixPath(path_in_udf)

def activate_container(self, alter_type: LanguageActiveLevel = LanguageActiveLevel.Session,
def activate_container(self, alter_type: LanguageActivationLevel = LanguageActivationLevel.Session,
allow_override: bool = False,
path_in_udf: Optional[PurePosixPath] = None) -> None:
"""
Expand All @@ -72,7 +72,7 @@ def activate_container(self, alter_type: LanguageActiveLevel = LanguageActiveLev
self._pyexasol_conn.execute(alter_command)
logging.debug(alter_command)

def generate_activation_command(self, alter_type: LanguageActiveLevel,
def generate_activation_command(self, alter_type: LanguageActivationLevel,
allow_override: bool = False,
path_in_udf: Optional[PurePosixPath] = None) -> str:
"""
Expand All @@ -93,7 +93,7 @@ def generate_activation_command(self, alter_type: LanguageActiveLevel,
f"ALTER {alter_type.value} SET SCRIPT_LANGUAGES='{new_settings}';"
return alter_command

def _update_previous_language_settings(self, alter_type: LanguageActiveLevel,
def _update_previous_language_settings(self, alter_type: LanguageActivationLevel,
allow_override: bool,
path_in_udf: PurePosixPath) -> str:
prev_lang_settings = self._get_previous_language_settings(alter_type)
Expand Down Expand Up @@ -131,7 +131,7 @@ def _check_if_requested_language_alias_already_exists(
else:
raise RuntimeError(warning_message)

def _get_previous_language_settings(self, alter_type: LanguageActiveLevel) -> str:
def _get_previous_language_settings(self, alter_type: LanguageActivationLevel) -> str:
result = self._pyexasol_conn.execute(
f"""SELECT "{alter_type.value}_VALUE" FROM SYS.EXA_PARAMETERS WHERE
PARAMETER_NAME='SCRIPT_LANGUAGES'""").fetchall()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
import click
from pathlib import Path
from textwrap import dedent
from exasol_transformers_extension.deployment import deployment_utils as utils
from exasol_transformers_extension.deployment.language_container_deployer import \
LanguageContainerDeployer, LanguageActiveLevel
LanguageContainerDeployer, LanguageActivationLevel


def run_deployer(deployer, upload_container: bool = True,
Expand All @@ -14,11 +15,20 @@ def run_deployer(deployer, upload_container: bool = True,
elif upload_container:
deployer.upload_container()
elif alter_system:
deployer.activate_container(LanguageActiveLevel.System, allow_override)
deployer.activate_container(LanguageActivationLevel.System, allow_override)

if not alter_system:
print('Use the following command to activate the SLC at the SESSION level:\n' +
deployer.generate_activation_command(LanguageActiveLevel.Session, True))
message = dedent(f"""
In SQL, you can activate the SLC of the Transformer Extension
by using the following statements:
To activate the SLC only for the current session:
{deployer.generate_activation_command(LanguageActivationLevel.Session, True)}
To activate the SLC on the system:
{deployer.generate_activation_command(LanguageActivationLevel.System, True)}
""")
print(message)


@click.command(name="language-container")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pytest_itde import config

from exasol_transformers_extension.deployment.language_container_deployer \
import LanguageContainerDeployer, LanguageActiveLevel
import LanguageContainerDeployer, LanguageActivationLevel
from tests.utils.parameters import bucketfs_params
from tests.utils.revert_language_settings import revert_language_settings

Expand Down Expand Up @@ -64,7 +64,7 @@ def test_language_container_deployer_alter_session(
language_alias=language_alias,
pyexasol_connection=new_connection,
bucketfs_config=bucketfs_config)
deployer.activate_container(LanguageActiveLevel.Session, True)
deployer.activate_container(LanguageActivationLevel.Session, True)
assert_udf_running(new_connection, language_alias, schema)


Expand Down Expand Up @@ -93,7 +93,7 @@ def test_language_container_deployer_activation_fail(
pyexasol_connection=new_connection,
bucketfs_config=bucketfs_config)
with pytest.raises(RuntimeError):
deployer.activate_container(LanguageActiveLevel.System, False)
deployer.activate_container(LanguageActivationLevel.System, False)


def create_schema(pyexasol_connection: ExaConnection, schema: str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pyexasol import ExaConnection
from exasol_bucketfs_utils_python.bucketfs_location import BucketFSLocation
from exasol_transformers_extension.deployment.language_container_deployer import (
LanguageContainerDeployer, LanguageActiveLevel)
LanguageContainerDeployer, LanguageActivationLevel)
from exasol_transformers_extension.deployment.language_container_deployer_cli import run_deployer


Expand Down Expand Up @@ -45,4 +45,4 @@ def test_language_container_deployer_cli_register(container_deployer):
container_deployer.activate_container = MagicMock()
run_deployer(container_deployer, False, True, True)
container_deployer.upload_container.assert_not_called()
container_deployer.activate_container.assert_called_once_with(LanguageActiveLevel.System, True)
container_deployer.activate_container.assert_called_once_with(LanguageActivationLevel.System, True)

0 comments on commit 625c23a

Please sign in to comment.