Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .changes/unreleased/Features-20251217-140444.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Features
body: Adding EnvironmentInfo query
time: 2025-12-17T14:04:44.035438-05:00
4 changes: 4 additions & 0 deletions dbtsl/api/graphql/client/asyncio.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ from dbtsl.models import (
AsyncMetric,
Dimension,
Entity,
EnvironmentInfo,
Measure,
SavedQuery,
)
Expand Down Expand Up @@ -49,6 +50,9 @@ class AsyncGraphQLClient:
async def saved_queries(self) -> List[SavedQuery]:
"""Get a list of all available saved queries."""
...
async def environment_info(self) -> EnvironmentInfo:
"""Get information about the Semantic Layer environment."""
...

@overload
async def compile_sql(
Expand Down
5 changes: 4 additions & 1 deletion dbtsl/api/graphql/client/sync.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ from dbtsl.api.shared.query_params import GroupByParam, OrderByGroupBy, OrderByM
from dbtsl.models import (
Dimension,
Entity,
EnvironmentInfo,
Measure,
SavedQuery,
SyncMetric,
Expand Down Expand Up @@ -81,7 +82,9 @@ class SyncGraphQLClient:
def compile_sql(self, **query_params: Unpack[QueryParameters]) -> str:
"""Get the compiled SQL that would be sent to the warehouse by a query."""
...

def environment_info(self) -> EnvironmentInfo:
"""Get information about the Semantic Layer environment."""
...
@overload
def query(
self,
Expand Down
25 changes: 25 additions & 0 deletions dbtsl/api/graphql/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
validate_query_parameters,
)
from dbtsl.models import Dimension, Entity, Measure, Metric
from dbtsl.models.environment import EnvironmentInfo
from dbtsl.models.query import QueryId, QueryResult, QueryStatus
from dbtsl.models.saved_query import SavedQuery

Expand Down Expand Up @@ -358,6 +359,29 @@ def parse_response(self, data: Dict[str, Any]) -> str:
return cast(str, data["compileSql"]["sql"])


class GetEnvironmentInfoOperation(ProtocolOperation[EmptyVariables, EnvironmentInfo]):
"""Get information about the Semantic Layer environment."""

@override
def get_request_text(self, *, lazy: bool) -> str:
query = """
query getEnvironmentInfo($environmentId: BigInt!) {
environmentInfo(environmentId: $environmentId) {
...&fragment
}
}
"""
return render_query(query, EnvironmentInfo.gql_fragments(lazy=lazy))

@override
def get_request_variables(self, environment_id: int, variables: EmptyVariables) -> Dict[str, Any]:
return {"environmentId": environment_id}

@override
def parse_response(self, data: Dict[str, Any]) -> EnvironmentInfo:
return decode_to_dataclass(data["environmentInfo"], EnvironmentInfo)


class GraphQLProtocol:
"""Holds the GraphQL implementation for each of method in the API.

Expand All @@ -373,3 +397,4 @@ class GraphQLProtocol:
create_query = CreateQueryOperation()
get_query_result = GetQueryResultOperation()
compile_sql = CompileSqlOperation()
environment_info = GetEnvironmentInfoOperation()
6 changes: 5 additions & 1 deletion dbtsl/client/asyncio.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import pyarrow as pa
from typing_extensions import Self, Unpack, overload

from dbtsl.api.shared.query_params import GroupByParam, OrderByGroupBy, OrderByMetric, QueryParameters
from dbtsl.models import AsyncMetric, Dimension, Entity, Measure, SavedQuery
from dbtsl.models import AsyncMetric, Dimension, Entity, EnvironmentInfo, Measure, SavedQuery
from dbtsl.timeout import TimeoutOptions

class AsyncSemanticLayerClient:
Expand Down Expand Up @@ -116,6 +116,10 @@ class AsyncSemanticLayerClient:
"""Get a list of all available saved queries."""
...

async def environment_info(self) -> EnvironmentInfo:
"""Get information about the Semantic Layer environment."""
...

def session(self) -> AbstractAsyncContextManager[AsyncIterator[Self]]:
"""Establish a connection with the dbt Semantic Layer's servers."""
...
1 change: 1 addition & 0 deletions dbtsl/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class BaseSemanticLayerClient(ABC, Generic[TGQLClient, TADBCClient]):

_METHOD_MAP = {
"compile_sql": GRAPHQL,
"environment_info": GRAPHQL,
"dimension_values": ADBC,
"dimensions": GRAPHQL,
"entities": GRAPHQL,
Expand Down
6 changes: 5 additions & 1 deletion dbtsl/client/sync.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import pyarrow as pa
from typing_extensions import Self, Unpack, overload

from dbtsl.api.shared.query_params import GroupByParam, OrderByGroupBy, OrderByMetric, QueryParameters
from dbtsl.models import Dimension, Entity, Measure, SavedQuery, SyncMetric
from dbtsl.models import Dimension, Entity, EnvironmentInfo, Measure, SavedQuery, SyncMetric
from dbtsl.timeout import TimeoutOptions

class SyncSemanticLayerClient:
Expand Down Expand Up @@ -115,6 +115,10 @@ class SyncSemanticLayerClient:
"""Get a list of all available saved queries."""
...

def environment_info(self) -> EnvironmentInfo:
"""Get information about the Semantic Layer environment."""
...

def session(self) -> AbstractContextManager[Iterator[Self]]:
"""Establish a connection with the dbt Semantic Layer's servers."""
...
4 changes: 4 additions & 0 deletions dbtsl/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .base import BaseModel, GraphQLFragmentMixin
from .dimension import Dimension, DimensionType
from .entity import Entity, EntityType
from .environment import EnvironmentInfo, SqlDialect, SqlEngine
from .measure import AggregationType, Measure
from .metric import AsyncMetric, Metric, MetricType, SyncMetric
from .query import QueryResult
Expand Down Expand Up @@ -36,6 +37,7 @@
"DimensionType",
"Entity",
"EntityType",
"EnvironmentInfo",
"Export",
"ExportConfig",
"ExportDestinationType",
Expand All @@ -48,6 +50,8 @@
"SavedQueryMetricParam",
"SavedQueryQueryParams",
"SavedQueryWhereParam",
"SqlDialect",
"SqlEngine",
"SyncMetric",
"TimeGranularity",
]
45 changes: 45 additions & 0 deletions dbtsl/models/environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from dataclasses import dataclass
from enum import Enum

from dbtsl.models.base import BaseModel, FlexibleEnumMeta, GraphQLFragmentMixin


class SqlDialect(Enum, metaclass=FlexibleEnumMeta):
"""The SQL dialect of the semantic layer."""

UNKNOWN = "UNKNOWN"
SNOWFLAKE = "SNOWFLAKE"
BIGQUERY = "BIGQUERY"
POSTGRES = "POSTGRES"
REDSHIFT = "REDSHIFT"
DATABRICKS = "DATABRICKS"
APACHE_SPARK = "APACHE_SPARK"
DATABRICKS_SPARK = "DATABRICKS_SPARK"
TRINO = "TRINO"
ATHENA = "ATHENA"
FABRIC = "FABRIC"
SYNAPSE = "SYNAPSE"
TERADATA = "TERADATA"


class SqlEngine(Enum, metaclass=FlexibleEnumMeta):
"""The SQL engine/warehouse type."""

UNKNOWN = "UNKNOWN"
BIGQUERY = "BIGQUERY"
DUCKDB = "DUCKDB"
REDSHIFT = "REDSHIFT"
POSTGRES = "POSTGRES"
SNOWFLAKE = "SNOWFLAKE"
DATABRICKS = "DATABRICKS"
TRINO = "TRINO"


@dataclass
class EnvironmentInfo(BaseModel, GraphQLFragmentMixin):
"""Information about the dbt Semantic Layer environment."""

sql_dialect: SqlDialect
has_metrics_defined: bool
dialect: SqlEngine
dialect_supported_by_slg: bool
1 change: 1 addition & 0 deletions tests/api/graphql/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"get_query_result": [{"query_id": 1}],
"create_query": TEST_QUERIES,
"compile_sql": TEST_QUERIES,
"environment_info": [{}],
}

TestCase = Tuple[str, Dict[str, Any]]
Expand Down
Loading