Skip to content

Commit

Permalink
copy-paste query interface protocols from DSI into MF (#787)
Browse files Browse the repository at this point in the history
Ideally, we would bring in these changes via the DSI dependency. However, there are currently some dependency conflicts between DSI & MF see here and here (internal to dbt Labs). We would like to get these changes out sooner so that we can create a dev release. We can figure out the dependencies issue later.
  • Loading branch information
DevonFulcher authored Sep 26, 2023
1 parent afb5681 commit 9cd6ac1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230926-140015.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Removing methods and reordering parameters for Query Interface.
time: 2023-09-26T14:00:15.741015-05:00
custom:
Author: DevonFulcher
Issue: None
33 changes: 18 additions & 15 deletions metricflow/protocols/query_interface.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
from __future__ import annotations

from abc import abstractmethod
from typing import Optional, Protocol, Sequence


class QueryInterfaceMetric(Protocol):
"""Represents the interface for Metric in the query interface."""

@abstractmethod
def descending(self, _is_descending: bool) -> QueryInterfaceMetric:
"""Set the sort order for order-by."""
raise NotImplementedError
pass


class QueryInterfaceDimension(Protocol):
"""Represents the interface for Dimension in the query interface."""

@abstractmethod
def grain(self, _grain: str) -> QueryInterfaceDimension:
"""The time granularity."""
raise NotImplementedError

def alias(self, _alias: str) -> QueryInterfaceDimension:
"""Renaming the column."""
raise NotImplementedError
pass

@abstractmethod
def descending(self, _is_descending: bool) -> QueryInterfaceDimension:
"""Set the sort order for order-by."""
pass

@abstractmethod
def date_part(self, _date_part: str) -> QueryInterfaceDimension:
"""Date part to extract from the dimension."""
raise NotImplementedError
pass


class QueryInterfaceDimensionFactory(Protocol):
Expand All @@ -36,9 +38,10 @@ class QueryInterfaceDimensionFactory(Protocol):
Represented as the Dimension constructor in the Jinja sandbox.
"""

@abstractmethod
def create(self, name: str, entity_path: Sequence[str] = ()) -> QueryInterfaceDimension:
"""Create a QueryInterfaceDimension."""
raise NotImplementedError
pass


class QueryInterfaceTimeDimension(Protocol):
Expand All @@ -53,24 +56,23 @@ class QueryInterfaceTimeDimensionFactory(Protocol):
Represented as the TimeDimension constructor in the Jinja sandbox.
"""

@abstractmethod
def create(
self,
time_dimension_name: str,
time_granularity_name: str,
descending: bool = False,
date_part_name: Optional[str] = None,
entity_path: Sequence[str] = (),
descending: Optional[bool] = None,
date_part_name: Optional[str] = None,
) -> QueryInterfaceTimeDimension:
"""Create a TimeDimension."""
raise NotImplementedError
pass


class QueryInterfaceEntity(Protocol):
"""Represents the interface for Entity in the query interface."""

def descending(self, _is_descending: bool) -> QueryInterfaceEntity:
"""Set the sort order for order-by."""
raise NotImplementedError
pass


class QueryInterfaceEntityFactory(Protocol):
Expand All @@ -79,6 +81,7 @@ class QueryInterfaceEntityFactory(Protocol):
Represented as the Entity constructor in the Jinja sandbox.
"""

@abstractmethod
def create(self, entity_name: str, entity_path: Sequence[str] = ()) -> QueryInterfaceEntity:
"""Create an Entity."""
raise NotImplementedError
pass
6 changes: 4 additions & 2 deletions metricflow/specs/where_filter_time_dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,17 @@ def create(
self,
time_dimension_name: str,
time_granularity_name: str,
descending: bool = False,
date_part_name: Optional[str] = None,
entity_path: Sequence[str] = (),
descending: Optional[bool] = None,
date_part_name: Optional[str] = None,
) -> WhereFilterTimeDimension:
"""Create a WhereFilterTimeDimension."""
if descending:
raise InvalidQuerySyntax(
"Can't set descending in the where clause. Try setting descending in the order_by clause instead"
)
if date_part_name:
raise InvalidQuerySyntax("date_part_name isn't currently supported in the where parameter")
structured_name = DunderedNameFormatter.parse_name(time_dimension_name)
call_parameter_set = TimeDimensionCallParameterSet(
time_dimension_reference=TimeDimensionReference(element_name=structured_name.element_name),
Expand Down

0 comments on commit 9cd6ac1

Please sign in to comment.