Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: do not wrap query to apply limits in SQL connectors #1620

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Changed

- Snowflake: it is now assumed that the weaverbird translator takes care of adding OFFSET and LIMIT to queries

## [6.1.2] 2024-04-18

### Fixed
Expand Down
16 changes: 0 additions & 16 deletions tests/snowflake/test_snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,22 +249,6 @@ def test_retrieve_data_fetch(snowflake_connector: SnowflakeConnector, snowflake_
assert 11 == len(df_result)


@pytest.mark.usefixtures("snowflake_retrieve_data")
def test_retrieve_data_fetch_offset_limit(
snowflake_connector: SnowflakeConnector, snowflake_datasource: SnowflakeDataSource
):
df_result = snowflake_connector._fetch_data(snowflake_datasource, offset=5, limit=3)
assert 11 == len(df_result)


@pytest.mark.usefixtures("snowflake_retrieve_data")
def test_retrieve_data_fetch_too_much(
snowflake_connector: SnowflakeConnector, snowflake_datasource: SnowflakeDataSource
):
df_result = snowflake_connector._fetch_data(snowflake_datasource, offset=10, limit=20)
assert 11 == len(df_result)


def test_schema_fields_order():
schema_props_keys = list(JsonWrapper.loads(SnowflakeConnector.schema_json())["properties"].keys())
ordered_keys = [
Expand Down
16 changes: 5 additions & 11 deletions toucan_connectors/snowflake/snowflake_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,17 +410,10 @@ def _get_databases(self, database_name: str | None = None) -> list[str]:
result = self._execute_query(query, database=database_name)
return result["name"].to_list() if "name" in result.columns else []

def _fetch_data(
self,
data_source: SnowflakeDataSource,
offset: int | None = None,
limit: int | None = None,
) -> pd.DataFrame:
def _fetch_data(self, data_source: SnowflakeDataSource) -> pd.DataFrame:
data_source = self._set_warehouse(data_source)

prepared_query, prepared_params = SqlQueryHelper.prepare_limit_query(
data_source.query, data_source.parameters, offset=offset, limit=limit
)
prepared_query, prepared_params = SqlQueryHelper.prepare_query(data_source.query, data_source.parameters)
return self._execute_query(
prepared_query,
prepared_params,
Expand All @@ -439,8 +432,9 @@ def get_slice(
limit: int | None = None,
get_row_count: bool | None = False,
) -> DataSlice:
# We assume permissions have been applied earlier
df = self._fetch_data(data_source, offset=offset, limit=limit)
# We assume permissions have been applied earlier and that OFFSET and LIMIT have been
# applied by the PyPika translator
df = self._fetch_data(data_source)
return DataSlice(
df=df,
pagination_info=build_pagination_info(offset=0, limit=limit, total_rows=None, retrieved_rows=len(df)),
Expand Down