Skip to content

Commit b38021e

Browse files
authored
feat: Add EnvironmentInfo into SDK (#95)
* feat: Add EnvironmentInfo into SDK * Changelog
1 parent f12794b commit b38021e

10 files changed

Lines changed: 97 additions & 3 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Features
2+
body: Adding EnvironmentInfo query
3+
time: 2025-12-17T14:04:44.035438-05:00

dbtsl/api/graphql/client/asyncio.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ from dbtsl.models import (
1111
AsyncMetric,
1212
Dimension,
1313
Entity,
14+
EnvironmentInfo,
1415
Measure,
1516
SavedQuery,
1617
)
@@ -49,6 +50,9 @@ class AsyncGraphQLClient:
4950
async def saved_queries(self) -> List[SavedQuery]:
5051
"""Get a list of all available saved queries."""
5152
...
53+
async def environment_info(self) -> EnvironmentInfo:
54+
"""Get information about the Semantic Layer environment."""
55+
...
5256

5357
@overload
5458
async def compile_sql(

dbtsl/api/graphql/client/sync.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ from dbtsl.api.shared.query_params import GroupByParam, OrderByGroupBy, OrderByM
1010
from dbtsl.models import (
1111
Dimension,
1212
Entity,
13+
EnvironmentInfo,
1314
Measure,
1415
SavedQuery,
1516
SyncMetric,
@@ -81,7 +82,9 @@ class SyncGraphQLClient:
8182
def compile_sql(self, **query_params: Unpack[QueryParameters]) -> str:
8283
"""Get the compiled SQL that would be sent to the warehouse by a query."""
8384
...
84-
85+
def environment_info(self) -> EnvironmentInfo:
86+
"""Get information about the Semantic Layer environment."""
87+
...
8588
@overload
8689
def query(
8790
self,

dbtsl/api/graphql/protocol.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
validate_query_parameters,
1313
)
1414
from dbtsl.models import Dimension, Entity, Measure, Metric
15+
from dbtsl.models.environment import EnvironmentInfo
1516
from dbtsl.models.query import QueryId, QueryResult, QueryStatus
1617
from dbtsl.models.saved_query import SavedQuery
1718

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

360361

362+
class GetEnvironmentInfoOperation(ProtocolOperation[EmptyVariables, EnvironmentInfo]):
363+
"""Get information about the Semantic Layer environment."""
364+
365+
@override
366+
def get_request_text(self, *, lazy: bool) -> str:
367+
query = """
368+
query getEnvironmentInfo($environmentId: BigInt!) {
369+
environmentInfo(environmentId: $environmentId) {
370+
...&fragment
371+
}
372+
}
373+
"""
374+
return render_query(query, EnvironmentInfo.gql_fragments(lazy=lazy))
375+
376+
@override
377+
def get_request_variables(self, environment_id: int, variables: EmptyVariables) -> Dict[str, Any]:
378+
return {"environmentId": environment_id}
379+
380+
@override
381+
def parse_response(self, data: Dict[str, Any]) -> EnvironmentInfo:
382+
return decode_to_dataclass(data["environmentInfo"], EnvironmentInfo)
383+
384+
361385
class GraphQLProtocol:
362386
"""Holds the GraphQL implementation for each of method in the API.
363387
@@ -373,3 +397,4 @@ class GraphQLProtocol:
373397
create_query = CreateQueryOperation()
374398
get_query_result = GetQueryResultOperation()
375399
compile_sql = CompileSqlOperation()
400+
environment_info = GetEnvironmentInfoOperation()

dbtsl/client/asyncio.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import pyarrow as pa
77
from typing_extensions import Self, Unpack, overload
88

99
from dbtsl.api.shared.query_params import GroupByParam, OrderByGroupBy, OrderByMetric, QueryParameters
10-
from dbtsl.models import AsyncMetric, Dimension, Entity, Measure, SavedQuery
10+
from dbtsl.models import AsyncMetric, Dimension, Entity, EnvironmentInfo, Measure, SavedQuery
1111
from dbtsl.timeout import TimeoutOptions
1212

1313
class AsyncSemanticLayerClient:
@@ -116,6 +116,10 @@ class AsyncSemanticLayerClient:
116116
"""Get a list of all available saved queries."""
117117
...
118118

119+
async def environment_info(self) -> EnvironmentInfo:
120+
"""Get information about the Semantic Layer environment."""
121+
...
122+
119123
def session(self) -> AbstractAsyncContextManager[AsyncIterator[Self]]:
120124
"""Establish a connection with the dbt Semantic Layer's servers."""
121125
...

dbtsl/client/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class BaseSemanticLayerClient(ABC, Generic[TGQLClient, TADBCClient]):
2424

2525
_METHOD_MAP = {
2626
"compile_sql": GRAPHQL,
27+
"environment_info": GRAPHQL,
2728
"dimension_values": ADBC,
2829
"dimensions": GRAPHQL,
2930
"entities": GRAPHQL,

dbtsl/client/sync.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import pyarrow as pa
77
from typing_extensions import Self, Unpack, overload
88

99
from dbtsl.api.shared.query_params import GroupByParam, OrderByGroupBy, OrderByMetric, QueryParameters
10-
from dbtsl.models import Dimension, Entity, Measure, SavedQuery, SyncMetric
10+
from dbtsl.models import Dimension, Entity, EnvironmentInfo, Measure, SavedQuery, SyncMetric
1111
from dbtsl.timeout import TimeoutOptions
1212

1313
class SyncSemanticLayerClient:
@@ -115,6 +115,10 @@ class SyncSemanticLayerClient:
115115
"""Get a list of all available saved queries."""
116116
...
117117

118+
def environment_info(self) -> EnvironmentInfo:
119+
"""Get information about the Semantic Layer environment."""
120+
...
121+
118122
def session(self) -> AbstractContextManager[Iterator[Self]]:
119123
"""Establish a connection with the dbt Semantic Layer's servers."""
120124
...

dbtsl/models/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from .base import BaseModel, GraphQLFragmentMixin
88
from .dimension import Dimension, DimensionType
99
from .entity import Entity, EntityType
10+
from .environment import EnvironmentInfo, SqlDialect, SqlEngine
1011
from .measure import AggregationType, Measure
1112
from .metric import AsyncMetric, Metric, MetricType, SyncMetric
1213
from .query import QueryResult
@@ -36,6 +37,7 @@
3637
"DimensionType",
3738
"Entity",
3839
"EntityType",
40+
"EnvironmentInfo",
3941
"Export",
4042
"ExportConfig",
4143
"ExportDestinationType",
@@ -48,6 +50,8 @@
4850
"SavedQueryMetricParam",
4951
"SavedQueryQueryParams",
5052
"SavedQueryWhereParam",
53+
"SqlDialect",
54+
"SqlEngine",
5155
"SyncMetric",
5256
"TimeGranularity",
5357
]

dbtsl/models/environment.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from dataclasses import dataclass
2+
from enum import Enum
3+
4+
from dbtsl.models.base import BaseModel, FlexibleEnumMeta, GraphQLFragmentMixin
5+
6+
7+
class SqlDialect(Enum, metaclass=FlexibleEnumMeta):
8+
"""The SQL dialect of the semantic layer."""
9+
10+
UNKNOWN = "UNKNOWN"
11+
SNOWFLAKE = "SNOWFLAKE"
12+
BIGQUERY = "BIGQUERY"
13+
POSTGRES = "POSTGRES"
14+
REDSHIFT = "REDSHIFT"
15+
DATABRICKS = "DATABRICKS"
16+
APACHE_SPARK = "APACHE_SPARK"
17+
DATABRICKS_SPARK = "DATABRICKS_SPARK"
18+
TRINO = "TRINO"
19+
ATHENA = "ATHENA"
20+
FABRIC = "FABRIC"
21+
SYNAPSE = "SYNAPSE"
22+
TERADATA = "TERADATA"
23+
24+
25+
class SqlEngine(Enum, metaclass=FlexibleEnumMeta):
26+
"""The SQL engine/warehouse type."""
27+
28+
UNKNOWN = "UNKNOWN"
29+
BIGQUERY = "BIGQUERY"
30+
DUCKDB = "DUCKDB"
31+
REDSHIFT = "REDSHIFT"
32+
POSTGRES = "POSTGRES"
33+
SNOWFLAKE = "SNOWFLAKE"
34+
DATABRICKS = "DATABRICKS"
35+
TRINO = "TRINO"
36+
37+
38+
@dataclass
39+
class EnvironmentInfo(BaseModel, GraphQLFragmentMixin):
40+
"""Information about the dbt Semantic Layer environment."""
41+
42+
sql_dialect: SqlDialect
43+
has_metrics_defined: bool
44+
dialect: SqlEngine
45+
dialect_supported_by_slg: bool

tests/api/graphql/test_protocol.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"get_query_result": [{"query_id": 1}],
1717
"create_query": TEST_QUERIES,
1818
"compile_sql": TEST_QUERIES,
19+
"environment_info": [{}],
1920
}
2021

2122
TestCase = Tuple[str, Dict[str, Any]]

0 commit comments

Comments
 (0)