Example #1
0
class ApiDataRequest(schematics.Model, ApiModelSchematics):
    """API representation of data request"""

    taxons: List[TaxonExpressionStr] = ListType(NonEmptyStringType,
                                                required=False,
                                                default=[])

    preaggregation_filters = PolyModelType(get_all_filter_clauses())

    order_by: List[TaxonDataOrder] = ListType(ModelType(TaxonDataOrder),
                                              default=list())

    limit: Optional[int] = IntType()

    offset: Optional[int] = IntType()

    properties: DataRequestProperties = ModelType(DataRequestProperties,
                                                  required=True)

    scope: ApiScope = ModelType(ApiScope, required=True)

    origin: Optional[DataRequestOrigin] = ModelType(DataRequestOrigin)

    def to_internal_model(self) -> 'InternalDataRequest':
        return InternalDataRequest(self.to_primitive())
Example #2
0
class InternalDataRequest(schematics.Model):
    """Internal representation of data request"""

    taxons: List[TaxonExpressionStr] = ListType(NonEmptyStringType,
                                                required=False,
                                                default=[])

    preaggregation_filters = PolyModelType(get_all_filter_clauses())

    order_by: List[TaxonDataOrder] = ListType(ModelType(TaxonDataOrder),
                                              default=list())

    limit: Optional[int] = IntType()

    offset: Optional[int] = IntType()

    properties: DataRequestProperties = ModelType(DataRequestProperties,
                                                  required=True)

    scope: Scope = ModelType(Scope, required=True)

    origin: Optional[DataRequestOrigin] = ModelType(DataRequestOrigin)

    physical_data_sources: Optional[List[str]] = ListType(NonEmptyStringType,
                                                          required=False)
    """
Example #3
0
class Scope(schematics.Model):

    company_id: str = StringType(required=True)
    """
    Historically, company_id=None meant global. Now, we should use support company id, same as with taxons.
    """
    project_id: Optional[str] = StringType()

    model_visibility: ModelVisibility = EnumType(
        ModelVisibility, default=ModelVisibility.available)
    """
    Every production consumer should not set this field. Set to experimental if you want to test new changes / models.
    """

    preaggregation_filters = PolyModelType(get_all_filter_clauses())
    """Optional pre-aggregation filters which determine scope of this Husky request"""
    @property
    def all_filters(self):
        """
        Get current preaggregation scope filters
        """
        return self.preaggregation_filters

    def __hash__(self) -> int:
        return hash('_'.join(
            str(part) for part in [
                self.project_id,
                self.company_id,
                self.model_visibility,
            ]))
Example #4
0
class ApiScope(schematics.Model):
    company_id: str = StringType()
    project_id: Optional[str] = StringType()

    model_visibility: ModelVisibility = EnumType(
        ModelVisibility, default=ModelVisibility.available)
    """
    Every production consumer should not set this field. Set to experimental if you want to test new changes / models.
    """

    preaggregation_filters = PolyModelType(get_all_filter_clauses())
    """Pre-aggregation filters which determine scope of this Husky request"""
Example #5
0
class BlendingDataRequest(schematics.Model):
    data_subrequests: List[ApiDataRequest] = ListType(
        ModelType(ApiDataRequest), min_size=1)

    taxons: List[TaxonExpressionStr] = ListType(NonEmptyStringType,
                                                required=False)
    """
    List of taxons to fetch. Pushed to individual subrequests based on the data source.
    """

    order_by: List[TaxonDataOrder] = ListType(ModelType(TaxonDataOrder),
                                              default=list())
    """
    Specify order of the final blended data frame.
    Taxons used here are not automatically propagated into subrequest.
    Example: if you use order by for taxonA, but don't specify the taxonA in *any* of the subrequests, it will fail,
    coz the taxonA won't be available and possible to sort on. We cannot propagate the taxonA to all subrequests
    automatically, because there are cases where you don't want to select taxonA from all subrequests, but just from
    some.
    """

    limit: Optional[int] = IntType()

    origin: DataRequestOrigin = ModelType(DataRequestOrigin)

    comparison: Optional[ComparisonConfig] = ModelType(ComparisonConfig,
                                                       required=False)
    grouping_sets: Optional[List[List[TaxonExpressionStr]]] = GroupingSets
    """
    Groups data exactly as defined on https://docs.snowflake.net/manuals/sql-reference/constructs/group-by-grouping-sets.html#group-by-grouping-sets
    NULL values produced by the aggregation are encoded as "PANORAMIC_GROUPINGSETS_NULL" (string).
    """

    fill_date_gaps: Optional[bool] = BooleanType(required=False, default=False)

    filters = PolyModelType(get_all_filter_clauses(
    ))  # Omitting type here to avoid circular dependencies
    """
    Typically metric filters, applied after all computations and aggregations.
    """

    physical_data_sources: Optional[List[str]] = ListType(NonEmptyStringType,
                                                          required=False)
    """