Skip to content

Commit

Permalink
Removed query compiler from data sources
Browse files Browse the repository at this point in the history
  • Loading branch information
altvod committed Nov 8, 2023
1 parent afcf4bb commit b4d1306
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
BigQuerySubselectDataSourceSpec,
BigQueryTableDataSourceSpec,
)
from dl_connector_bigquery.core.query_compiler import BigQueryQueryCompiler
from dl_connector_bigquery.core.us_connection import ConnectionSQLBigQuery


Expand All @@ -45,8 +44,6 @@ class BigQueryTableDataSource(BigQueryDataSourceMixin, TableSQLDataSourceMixin,
BigQuery table
"""

compiler_cls = BigQueryQueryCompiler

@property
def spec(self) -> BigQueryTableDataSourceSpec:
assert isinstance(self._spec, BigQueryTableDataSourceSpec)
Expand Down Expand Up @@ -89,8 +86,6 @@ class BigQuerySubselectDataSource(BigQueryDataSourceMixin, SubselectDataSource):
BigQuery subselect
"""

compiler_cls = BigQueryQueryCompiler

@property
def spec(self) -> BigQuerySubselectDataSourceSpec:
assert isinstance(self._spec, BigQuerySubselectDataSourceSpec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
)

from dl_connector_clickhouse.core.clickhouse_base.constants import CONNECTION_TYPE_CLICKHOUSE
from dl_connector_clickhouse.core.clickhouse_base.query_compiler import ClickHouseQueryCompiler


if TYPE_CHECKING:
Expand Down Expand Up @@ -45,7 +44,6 @@ class ClickHouseBaseMixin(BaseSQLDataSource):
JoinType.right,
}
)
compiler_cls = ClickHouseQueryCompiler

def get_connect_args(self) -> dict:
return dict(super().get_connect_args(), server_version=self.db_version or self.default_server_version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
SOURCE_TYPE_GP_SUBSELECT,
SOURCE_TYPE_GP_TABLE,
)
from dl_connector_postgresql.core.postgresql_base.query_compiler import PostgreSQLQueryCompiler


class GreenplumDataSourceMixin(BaseSQLDataSource):
compiler_cls = PostgreSQLQueryCompiler

conn_type = CONNECTION_TYPE_GREENPLUM

@classmethod
Expand Down
2 changes: 0 additions & 2 deletions lib/dl_connector_mysql/dl_connector_mysql/core/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
SOURCE_TYPE_MYSQL_SUBSELECT,
SOURCE_TYPE_MYSQL_TABLE,
)
from dl_connector_mysql.core.query_compiler import MySQLQueryCompiler


LOGGER = logging.getLogger(__name__)
Expand All @@ -37,7 +36,6 @@ class MySQLDataSourceMixin(BaseSQLDataSource):
)

conn_type = CONNECTION_TYPE_MYSQL
compiler_cls = MySQLQueryCompiler

@classmethod
def is_compatible_with_type(cls, source_type: DataSourceType) -> bool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@
SOURCE_TYPE_ORACLE_SUBSELECT,
SOURCE_TYPE_ORACLE_TABLE,
)
from dl_connector_oracle.core.query_compiler import OracleQueryCompiler


LOGGER = logging.getLogger(__name__)


class OracleDataSourceMixin(BaseSQLDataSource):
compiler_cls = OracleQueryCompiler

conn_type = CONNECTION_TYPE_ORACLE

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
SOURCE_TYPE_PG_SUBSELECT,
SOURCE_TYPE_PG_TABLE,
)
from dl_connector_postgresql.core.postgresql_base.query_compiler import PostgreSQLQueryCompiler


class PostgreSQLDataSourceMixin(BaseSQLDataSource):
compiler_cls = PostgreSQLQueryCompiler
supported_join_types: ClassVar[FrozenSet[JoinType]] = frozenset(
{
JoinType.inner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
from sqlalchemy.sql.selectable import FromClause

from dl_constants.enums import DataSourceRole
from dl_core.backend_types import get_backend_type
from dl_core.components.accessor import DatasetComponentAccessor
from dl_core.components.ids import AvatarId
from dl_core.constants import DataAPILimits
from dl_core.data_processing.prepared_components.manager_base import PreparedComponentManagerBase
from dl_core.data_processing.prepared_components.primitives import PreparedSingleFromInfo
from dl_core.data_processing.query_compiler_registry import get_sa_query_compiler_cls
from dl_core.data_source.collection import DataSourceCollectionFactory
import dl_core.data_source.sql
import dl_core.exc as exc
Expand Down Expand Up @@ -80,7 +82,12 @@ def get_columns(): # type: ignore # TODO: fix
columns = get_columns()
col_names = [col.name for col in columns]
from_subquery = from_subquery and dsrc.supports_preview_from_subquery
query_compiler = dsrc.get_query_compiler()
connection = dsrc.connection
conn_type = connection.conn_type
backend_type = get_backend_type(conn_type=conn_type)
sa_dialect = connection.get_dialect()
query_compiler_cls = get_sa_query_compiler_cls(backend_type=backend_type)
query_compiler = query_compiler_cls(dialect=sa_dialect)

sql_source: FromClause
if from_subquery:
Expand Down
1 change: 1 addition & 0 deletions lib/dl_core/dl_core/data_processing/selectors/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
@attr.s
class DatasetDbDataSelectorAsync(DatasetDataSelectorAsyncBase):
"""Async selector that fetches data from the database"""

# TODO: Merge all selector logic into data processors

_active_queries: list[BIQueryExecutionContext] = attr.ib(init=False, factory=list)
Expand Down
5 changes: 0 additions & 5 deletions lib/dl_core/dl_core/data_source/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,6 @@ def get_schema_info(self, conn_executor_factory: Callable[[], SyncConnExecutorBa
schema_info = conn_executor.get_table_schema_info(table_def)
return self._postprocess_raw_schema_from_db(schema_info)

def get_query_compiler(self) -> QueryCompiler:
return self.compiler_cls(
dialect=self.get_dialect(),
)

def _get_db_version(self, conn_executor_factory: Callable[[], SyncConnExecutorBase]) -> Optional[str]:
conn_executor = conn_executor_factory()
return conn_executor.get_db_version(
Expand Down
12 changes: 6 additions & 6 deletions lib/dl_core/dl_core/services_registry/selector_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def _create_dataset_selector(
allow_cache_usage: bool = True,
) -> DatasetDataSelectorAsyncBase:
return DatasetDbDataSelectorAsync(
dataset=dataset,
service_registry=self.services_registry,
# allow_cache_usage=allow_cache_usage,
# is_bleeding_edge_user=self._is_bleeding_edge_user,
us_entry_buffer=us_entry_buffer,
)
dataset=dataset,
service_registry=self.services_registry,
# allow_cache_usage=allow_cache_usage,
# is_bleeding_edge_user=self._is_bleeding_edge_user,
us_entry_buffer=us_entry_buffer,
)

0 comments on commit b4d1306

Please sign in to comment.