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

copy-paste query interface protocols from DSI into MF #787

Merged
merged 1 commit into from
Sep 26, 2023
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
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