Giter VIP home page Giter VIP logo

Comments (2)

callum-mcdata avatar callum-mcdata commented on July 2, 2024

@QMalcolm I wanted to lay out a proposed implementation to get your feedback on whether I'm heading in the right direction. Dimensions contain 4 classes that we'll want to migrate over:

  • DimensionType (enum)
  • DimensionValidityParams
  • DimensionTypeParams
  • Dimension

For the final three, I think it is reasonable for us to create Protocols for each of them.

Where I'm a bit fuzzy is in regard to our implementation of enums and methods that we've used the @property decorator on. Let's start with methods.

@Property Methods

To the best of my knowledge, Protocols can't support methods as properties. Which means:

    @property
    def is_primary_time(self) -> bool:  # noqa: D
        if self.type == DimensionType.TIME and self.type_params is not None:
            return self.type_params.is_primary

        return False

Would become:

    def is_primary_time(self) -> bool:
        if self.type == DimensionType.TIME and self.type_params is not None:
            return self.type_params.is_primary
        return False

Then when we implement it in MetricFlow we would use the @Property decorator and the default implementation from the Protocol. That way we ensure that we don't need to change its use all throughout the codebase.

    @property
    def is_primary_time(self) -> bool:
        return super().is_primary_time()

Does that seem like a reasonable implementation to you?

Enums

Okay this one I'm a bit more confused about. Do we ... have to do anything here beyond moving the Enum into this repo and then referencing it in the Protocol? Is it as simple as that?

Protocols

Oh just to make sure I'm also thinking about the Protocols correctly, is this looking fine? Do we have a naming convention of wanting to keep it to the same name or would we want Protocol to be appended onto the end of it so the implementing libraries can use the original name 🤔

class DimensionTypeParamsProtocol(Protocol):
    is_primary: bool
    time_granularity: TimeGranularity
    validity_params: Optional[DimensionValidityParams]

from dbt-semantic-interfaces.

callum-mcdata avatar callum-mcdata commented on July 2, 2024

While we wait to cut the code over from MetricFlow, I'm gonna throw a draft into this issue.

# Keeping this the same!
class DimensionType(ExtendedEnum):
    """Determines types of values expected of dimensions."""

    CATEGORICAL = "categorical"
    TIME = "time"

    def is_time_type(self) -> bool:
        """Checks if this type of dimension is a time type"""
        return self in [DimensionType.TIME]

class DimensionValidityParamsProtocol(Protocol):
    is_start: bool = False
    is_end: bool = False

class DimensionTypeParamsProtocol(Protocol):
    is_primary: bool
    time_granularity: TimeGranularity
    validity_params: Optional[DimensionValidityParams]

class DimensionProtocol(Protocol):
    name: str
    description: Optional[str]
    type: DimensionType
    type_params: Optional[DimensionTypeParams]
    is_partition: bool
    expr: Optional[str]
    is_primary_time: bool
    reference: DimensionReference
    time_dimension_reference: TimeDimensionReference
    validity_params: Optional[DimensionValidityParams]

from dbt-semantic-interfaces.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.