From 18784d86885c9d426c5345b15b7078027100c2cd Mon Sep 17 00:00:00 2001 From: serramatutu Date: Tue, 1 Oct 2024 15:52:39 +0200 Subject: [PATCH] refactor: typing public interfaces with order by This commit updates the public `.pyi` files to ensure we use the new order by spec --- dbtsl/api/graphql/client/asyncio.pyi | 12 ++++++------ dbtsl/api/graphql/client/sync.pyi | 12 ++++++------ dbtsl/client/asyncio.pyi | 12 ++++++------ dbtsl/client/sync.pyi | 12 ++++++------ tests/integration/test_sl_client.py | 7 ++++--- 5 files changed, 28 insertions(+), 27 deletions(-) diff --git a/dbtsl/api/graphql/client/asyncio.pyi b/dbtsl/api/graphql/client/asyncio.pyi index 36af1a3..7006af2 100644 --- a/dbtsl/api/graphql/client/asyncio.pyi +++ b/dbtsl/api/graphql/client/asyncio.pyi @@ -1,10 +1,10 @@ from contextlib import AbstractAsyncContextManager -from typing import List, Optional, Self +from typing import List, Optional, Self, Union import pyarrow as pa from typing_extensions import AsyncIterator, Unpack, overload -from dbtsl.api.shared.query_params import QueryParameters +from dbtsl.api.shared.query_params import OrderByGroupBy, OrderByMetric, QueryParameters from dbtsl.models import ( Dimension, Entity, @@ -50,7 +50,7 @@ class AsyncGraphQLClient: metrics: List[str], group_by: Optional[List[str]] = None, limit: Optional[int] = None, - order_by: Optional[List[str]] = None, + order_by: Optional[List[Union[str, OrderByGroupBy, OrderByMetric]]] = None, where: Optional[List[str]] = None, read_cache: bool = True, ) -> str: ... @@ -59,7 +59,7 @@ class AsyncGraphQLClient: self, saved_query: str, limit: Optional[int] = None, - order_by: Optional[List[str]] = None, + order_by: Optional[List[Union[OrderByGroupBy, OrderByMetric]]] = None, where: Optional[List[str]] = None, read_cache: bool = True, ) -> str: ... @@ -73,7 +73,7 @@ class AsyncGraphQLClient: metrics: List[str], group_by: Optional[List[str]] = None, limit: Optional[int] = None, - order_by: Optional[List[str]] = None, + order_by: Optional[List[Union[str, OrderByGroupBy, OrderByMetric]]] = None, where: Optional[List[str]] = None, read_cache: bool = True, ) -> "pa.Table": ... @@ -82,7 +82,7 @@ class AsyncGraphQLClient: self, saved_query: str, limit: Optional[int] = None, - order_by: Optional[List[str]] = None, + order_by: Optional[List[Union[OrderByGroupBy, OrderByMetric]]] = None, where: Optional[List[str]] = None, read_cache: bool = True, ) -> "pa.Table": ... diff --git a/dbtsl/api/graphql/client/sync.pyi b/dbtsl/api/graphql/client/sync.pyi index b050d62..c424dc0 100644 --- a/dbtsl/api/graphql/client/sync.pyi +++ b/dbtsl/api/graphql/client/sync.pyi @@ -1,10 +1,10 @@ from contextlib import AbstractContextManager -from typing import Iterator, List, Optional +from typing import Iterator, List, Optional, Union import pyarrow as pa from typing_extensions import Self, Unpack, overload -from dbtsl.api.shared.query_params import QueryParameters +from dbtsl.api.shared.query_params import OrderByGroupBy, OrderByMetric, QueryParameters from dbtsl.models import ( Dimension, Entity, @@ -50,7 +50,7 @@ class SyncGraphQLClient: metrics: List[str], group_by: Optional[List[str]] = None, limit: Optional[int] = None, - order_by: Optional[List[str]] = None, + order_by: Optional[List[Union[str, OrderByGroupBy, OrderByMetric]]] = None, where: Optional[List[str]] = None, read_cache: bool = True, ) -> str: ... @@ -59,7 +59,7 @@ class SyncGraphQLClient: self, saved_query: str, limit: Optional[int] = None, - order_by: Optional[List[str]] = None, + order_by: Optional[List[Union[OrderByGroupBy, OrderByMetric]]] = None, where: Optional[List[str]] = None, read_cache: bool = True, ) -> str: ... @@ -73,7 +73,7 @@ class SyncGraphQLClient: metrics: List[str], group_by: Optional[List[str]] = None, limit: Optional[int] = None, - order_by: Optional[List[str]] = None, + order_by: Optional[List[Union[str, OrderByGroupBy, OrderByMetric]]] = None, where: Optional[List[str]] = None, read_cache: bool = True, ) -> "pa.Table": ... @@ -82,7 +82,7 @@ class SyncGraphQLClient: self, saved_query: str, limit: Optional[int] = None, - order_by: Optional[List[str]] = None, + order_by: Optional[List[Union[OrderByGroupBy, OrderByMetric]]] = None, where: Optional[List[str]] = None, read_cache: bool = True, ) -> "pa.Table": ... diff --git a/dbtsl/client/asyncio.pyi b/dbtsl/client/asyncio.pyi index cbe9293..08a78f2 100644 --- a/dbtsl/client/asyncio.pyi +++ b/dbtsl/client/asyncio.pyi @@ -1,10 +1,10 @@ from contextlib import AbstractAsyncContextManager -from typing import AsyncIterator, List, Optional +from typing import AsyncIterator, List, Optional, Union import pyarrow as pa from typing_extensions import Self, Unpack, overload -from dbtsl.api.adbc.protocol import QueryParameters +from dbtsl.api.shared.query_params import OrderByGroupBy, OrderByMetric, QueryParameters from dbtsl.models import Dimension, Entity, Measure, Metric, SavedQuery class AsyncSemanticLayerClient: @@ -20,7 +20,7 @@ class AsyncSemanticLayerClient: metrics: List[str], group_by: Optional[List[str]] = None, limit: Optional[int] = None, - order_by: Optional[List[str]] = None, + order_by: Optional[List[Union[str, OrderByGroupBy, OrderByMetric]]] = None, where: Optional[List[str]] = None, read_cache: bool = True, ) -> str: ... @@ -29,7 +29,7 @@ class AsyncSemanticLayerClient: self, saved_query: str, limit: Optional[int] = None, - order_by: Optional[List[str]] = None, + order_by: Optional[List[Union[OrderByGroupBy, OrderByMetric]]] = None, where: Optional[List[str]] = None, read_cache: bool = True, ) -> str: ... @@ -43,7 +43,7 @@ class AsyncSemanticLayerClient: metrics: List[str], group_by: Optional[List[str]] = None, limit: Optional[int] = None, - order_by: Optional[List[str]] = None, + order_by: Optional[List[Union[str, OrderByGroupBy, OrderByMetric]]] = None, where: Optional[List[str]] = None, read_cache: bool = True, ) -> "pa.Table": ... @@ -52,7 +52,7 @@ class AsyncSemanticLayerClient: self, saved_query: str, limit: Optional[int] = None, - order_by: Optional[List[str]] = None, + order_by: Optional[List[Union[OrderByGroupBy, OrderByMetric]]] = None, where: Optional[List[str]] = None, read_cache: bool = True, ) -> "pa.Table": ... diff --git a/dbtsl/client/sync.pyi b/dbtsl/client/sync.pyi index 2546064..1b0f577 100644 --- a/dbtsl/client/sync.pyi +++ b/dbtsl/client/sync.pyi @@ -1,10 +1,10 @@ from contextlib import AbstractContextManager -from typing import Iterator, List, Optional +from typing import Iterator, List, Optional, Union import pyarrow as pa from typing_extensions import Self, Unpack, overload -from dbtsl.api.adbc.protocol import QueryParameters +from dbtsl.api.shared.query_params import OrderByGroupBy, OrderByMetric, QueryParameters from dbtsl.models import Dimension, Entity, Measure, Metric, SavedQuery class SyncSemanticLayerClient: @@ -20,7 +20,7 @@ class SyncSemanticLayerClient: metrics: List[str], group_by: Optional[List[str]] = None, limit: Optional[int] = None, - order_by: Optional[List[str]] = None, + order_by: Optional[List[Union[str, OrderByGroupBy, OrderByMetric]]] = None, where: Optional[List[str]] = None, read_cache: bool = True, ) -> str: ... @@ -29,7 +29,7 @@ class SyncSemanticLayerClient: self, saved_query: str, limit: Optional[int] = None, - order_by: Optional[List[str]] = None, + order_by: Optional[List[Union[OrderByGroupBy, OrderByMetric]]] = None, where: Optional[List[str]] = None, read_cache: bool = True, ) -> str: ... @@ -43,7 +43,7 @@ class SyncSemanticLayerClient: metrics: List[str], group_by: Optional[List[str]] = None, limit: Optional[int] = None, - order_by: Optional[List[str]] = None, + order_by: Optional[List[Union[str, OrderByGroupBy, OrderByMetric]]] = None, where: Optional[List[str]] = None, read_cache: bool = True, ) -> "pa.Table": ... @@ -52,7 +52,7 @@ class SyncSemanticLayerClient: self, saved_query: str, limit: Optional[int] = None, - order_by: Optional[List[str]] = None, + order_by: Optional[List[Union[OrderByGroupBy, OrderByMetric]]] = None, where: Optional[List[str]] = None, read_cache: bool = True, ) -> "pa.Table": ... diff --git a/tests/integration/test_sl_client.py b/tests/integration/test_sl_client.py index ba9ef6a..e66851f 100644 --- a/tests/integration/test_sl_client.py +++ b/tests/integration/test_sl_client.py @@ -3,10 +3,11 @@ import pytest from pytest_subtests import SubTests -from dbtsl import OrderByDimension +from dbtsl import OrderByGroupBy from dbtsl.client.asyncio import AsyncSemanticLayerClient from dbtsl.client.base import ADBC, GRAPHQL from dbtsl.client.sync import SyncSemanticLayerClient +from dbtsl import OrderByDimension from ..conftest import Credentials from ..util import maybe_await @@ -106,7 +107,7 @@ async def test_client_query_saved_query(api: str, client: BothClients) -> None: table = await maybe_await( client.query( saved_query="order_metrics", - order_by=["metric_time"], + order_by=[OrderByGroupBy(name="metric_time", grain=None)], where=["1=1"], limit=1, read_cache=True, @@ -140,7 +141,7 @@ async def test_client_compile_sql_saved_query(client: BothClients) -> None: sql = await maybe_await( client.compile_sql( saved_query="order_metrics", - order_by=["metric_time"], + order_by=[OrderByGroupBy(name="metric_time", grain=None)], where=["1=1"], limit=1, read_cache=True,