Skip to content

Commit

Permalink
Add temporary_udf_name to QueryHandlerContext
Browse files Browse the repository at this point in the history
  • Loading branch information
tkilias committed Feb 4, 2024
1 parent 10209bc commit 4c0c02e
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from exasol_data_science_utils_python.schema.udf_name import UDFName

from exasol_advanced_analytics_framework.query_handler.query.drop_query import DropQuery


class DropUDFQuery(DropQuery):

def __init__(self, udf_name: UDFName):
self._udf_name = udf_name

@property
def query_string(self) -> str:
return f"DROP SCRIPT IF EXISTS {self._udf_name.fully_qualified};"

@property
def table_name(self) -> UDFName:
return self._udf_name
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from exasol_data_science_utils_python.schema.udf_name import UDFName

from exasol_advanced_analytics_framework.query_handler.context.proxy.db_object_name_with_schema_proxy import \
DBObjectNameWithSchemaProxy
from exasol_advanced_analytics_framework.query_handler.context.proxy.drop_udf_query import DropUDFQuery
from exasol_advanced_analytics_framework.query_handler.query.query import Query


class UDFNameProxy(DBObjectNameWithSchemaProxy[UDFName], UDFName):

def get_cleanup_query(self) -> Query:
return DropUDFQuery(self._db_object_name)

def __init__(self, script_name: UDFName, global_counter_value: int):
super().__init__(script_name, global_counter_value)
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ def get_temporary_view_name(self) -> ViewName:

pass

@abc.abstractmethod
def get_temporary_udf_name(self) -> ViewName:
"""
This function registers a new temporary script without creating it.
After the release of this context the framework will issue a cleanup query.
"""

pass


@abc.abstractmethod
def get_temporary_bucketfs_location(self) -> BucketFSLocationProxy:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from exasol_data_science_utils_python.schema.schema_name import SchemaName
from exasol_data_science_utils_python.schema.table_name import TableName
from exasol_data_science_utils_python.schema.table_name_builder import TableNameBuilder
from exasol_data_science_utils_python.schema.udf_name import UDFName
from exasol_data_science_utils_python.schema.udf_name_builder import UDFNameBuilder
from exasol_data_science_utils_python.schema.view_name import ViewName
from exasol_data_science_utils_python.schema.view_name_builder import ViewNameBuilder

Expand All @@ -15,6 +17,7 @@
from exasol_advanced_analytics_framework.query_handler.context.proxy.db_object_name_proxy import DBObjectNameProxy
from exasol_advanced_analytics_framework.query_handler.context.proxy.object_proxy import ObjectProxy
from exasol_advanced_analytics_framework.query_handler.context.proxy.table_name_proxy import TableNameProxy
from exasol_advanced_analytics_framework.query_handler.context.proxy.udf_name_proxy import UDFNameProxy
from exasol_advanced_analytics_framework.query_handler.context.proxy.view_name_proxy import ViewNameProxy
from exasol_advanced_analytics_framework.query_handler.context.scope_query_handler_context import \
ScopeQueryHandlerContext, Connection
Expand Down Expand Up @@ -110,6 +113,14 @@ def _get_temporary_view_name(self) -> ViewName:
schema=SchemaName(schema_name=self._temporary_schema_name))
return temporary_view_name

def _get_temporary_udf_name(self) -> UDFName:
self._check_if_released()
temporary_name = self._get_temporary_db_object_name()
temporary_script_name = UDFNameBuilder.create(
name=temporary_name,
schema=SchemaName(schema_name=self._temporary_schema_name))
return temporary_script_name

def _get_temporary_db_object_name(self) -> str:
temporary_name = f"{self._temporary_db_object_name_prefix}_{self._get_counter_value()}"
return temporary_name
Expand All @@ -134,6 +145,14 @@ def get_temporary_view_name(self) -> ViewName:
self._own_object(object_proxy)
return object_proxy

def get_temporary_udf_name(self) -> UDFName:
self._check_if_released()
temporary_script_name = self._get_temporary_udf_name()
object_proxy = UDFNameProxy(temporary_script_name,
self._global_temporary_object_counter.get_current_value())
self._own_object(object_proxy)
return object_proxy

def get_temporary_bucketfs_location(self) -> BucketFSLocationProxy:
self._check_if_released()
temporary_path = self._get_temporary_path()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@

class DropyQuery(Query):
pass


class DropQuery(Query):
pass
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from exasol_data_science_utils_python.schema.table_name import TableName
from exasol_advanced_analytics_framework.query_handler.query.query import Query

class DropQuery(Query):
pass
from exasol_advanced_analytics_framework.query_handler.query.drop_query import DropQuery


class DropTableQuery(DropQuery):
Expand All @@ -15,5 +13,5 @@ def query_string(self) -> str:
return f"DROP TABLE IF EXISTS {self._table_name.fully_qualified};"

@property
def table_name(self)->TableName:
return self._table_name
def table_name(self) -> TableName:
return self._table_name
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from exasol_data_science_utils_python.schema.table_name import TableName
from exasol_data_science_utils_python.schema.view_name import ViewName

from exasol_advanced_analytics_framework.query_handler.query.drop_table_query import DropQuery
from exasol_advanced_analytics_framework.query_handler.query.drop_query import DropQuery


class DropViewQuery(DropQuery):
Expand Down

0 comments on commit 4c0c02e

Please sign in to comment.