Skip to content

Commit

Permalink
Added query_type allow_selector flag to connector options (#322)
Browse files Browse the repository at this point in the history
* Added query_type allow_selector flag to connector options
  • Loading branch information
altvod authored Feb 23, 2024
1 parent 702ce26 commit f475223
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class QueryTypeInfoSchema(Schema):
query_type = DynamicEnumField(DashSQLQueryType, dump_only=True)
query_type_label = ma_fields.String(dump_only=True)
required_parameters = ma_fields.List(ma_fields.Nested(RequiredParameterInfoSchema()), dump_only=True)
allow_selector = ma_fields.Boolean(dump_only=True)


class ConnectionOptionsSchema(Schema):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from typing import ClassVar

from dl_constants.enums import DashSQLQueryType
from dl_core.us_connection_base import DataSourceTemplate
from dl_core.us_connection_base import (
DataSourceTemplate,
QueryTypeInfo,
)
from dl_i18n.localizer_base import Localizer

from dl_connector_clickhouse.core.clickhouse.constants import (
Expand Down Expand Up @@ -41,10 +44,13 @@ def get_conn_dto(self) -> ClickHouseConnDTO:
def allow_public_usage(self) -> bool:
return True

def get_supported_dashsql_query_types(self) -> frozenset[DashSQLQueryType]:
def get_supported_query_type_infos(self) -> frozenset[QueryTypeInfo]:
return frozenset(
{
DashSQLQueryType.generic_query,
QueryTypeInfo(
query_type=DashSQLQueryType.generic_query,
allow_selector=True,
),
}
)

Expand Down
28 changes: 14 additions & 14 deletions lib/dl_core/dl_core/us_connection_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,16 @@ class RequiredParameterInfo:
class QueryTypeInfo:
query_type: DashSQLQueryType = attr.ib(kw_only=True)
query_type_label: str = attr.ib(kw_only=True) # How the value should be displayed in the UI
required_parameters: list[RequiredParameterInfo] = attr.ib(kw_only=True)
required_parameters: tuple[RequiredParameterInfo, ...] = attr.ib(kw_only=True, default=())
allow_selector: bool = attr.ib(kw_only=True, default=False)

@query_type_label.default
def _default_query_type_label(self) -> str:
# FIXME: This is a temporary hack until we start using real texts here
label = self.query_type.name
label = label.replace("_", " ")
label = " ".join([word.capitalize() for word in label.split()])
return label


@attr.s(frozen=True)
Expand Down Expand Up @@ -365,20 +374,11 @@ def get_cache_key_part(self) -> LocalKeyRepresentation:
)
return local_key_rep

def get_supported_dashsql_query_types(self) -> frozenset[DashSQLQueryType]:
def get_supported_query_type_infos(self) -> frozenset[QueryTypeInfo]:
return frozenset()

def get_options(self) -> ConnectionOptions:
query_type_info_list: list[QueryTypeInfo] = []
for dsql_qt in sorted(self.get_supported_dashsql_query_types(), key=lambda qt: qt.name):
query_type_info = QueryTypeInfo(
query_type=dsql_qt,
# FIXME: This should probably be a localized human-readable label
query_type_label=dsql_qt.name,
required_parameters=[],
)
query_type_info_list.append(query_type_info)

query_type_info_list = sorted(self.get_supported_query_type_infos(), key=lambda qti: qti.query_type.name)
return ConnectionOptions(
allow_dashsql_usage=self.is_dashsql_allowed,
allow_dataset_usage=self.is_dataset_allowed,
Expand Down Expand Up @@ -440,8 +440,8 @@ def get_tables(
conn_executor = conn_executor_factory(self)
return conn_executor.get_tables(SchemaIdent(db_name=db_name, schema_name=schema_name))

def get_supported_dashsql_query_types(self) -> frozenset[DashSQLQueryType]:
return frozenset({DashSQLQueryType.generic_query})
def get_supported_query_type_infos(self) -> frozenset[QueryTypeInfo]:
return frozenset({QueryTypeInfo(query_type=DashSQLQueryType.generic_query)})


class SubselectMixin:
Expand Down

0 comments on commit f475223

Please sign in to comment.