예제 #1
0
def get_time_range_endpoints(
    form_data: Dict[str, Any], slc: Optional[models.Slice]
) -> Optional[Tuple[TimeRangeEndpoint, TimeRangeEndpoint]]:
    """
    Get the slice aware time range endpoints from the form-data falling back to the SQL
    database specific definition or default if not defined.

    For SIP-15 all new slices use the [start, end) interval which is consistent with the
    native Druid connector.

    :param form_data: The form-data
    :param slc: The chart
    :returns: The time range endpoints tuple
    """

    endpoints = form_data.get("time_range_endpoints")

    if slc and not endpoints:
        try:
            _, datasource_type = get_datasource_info(None, None, form_data)
        except SupersetException:
            return None

        if datasource_type == "table":
            endpoints = slc.datasource.database.get_extra().get(
                "time_range_endpoints")

            if not endpoints:
                endpoints = app.config["SIP_15_DEFAULT_TIME_RANGE_ENDPOINTS"]

    if endpoints:
        start, end = endpoints
        return (TimeRangeEndpoint(start), TimeRangeEndpoint(end))

    return (TimeRangeEndpoint.INCLUSIVE, TimeRangeEndpoint.EXCLUSIVE)
예제 #2
0
def get_time_range_endpoints(
    form_data: Dict[str, Any],
    slc: Optional[models.Slice] = None,
    slice_id: Optional[int] = None,
) -> Optional[Tuple[TimeRangeEndpoint, TimeRangeEndpoint]]:
    """
    Get the slice aware time range endpoints from the form-data falling back to the SQL
    database specific definition or default if not defined.

    Note under certain circumstances the slice object may not exist, however the slice
    ID may be defined which serves as a fallback.

    When SIP-15 is enabled all slices and will the [start, end) interval. If the grace
    period is defined and has ended all slices will adhere to the [start, end) interval.

    :param form_data: The form-data
    :param slc: The slice
    :param slice_id: The slice ID
    :returns: The time range endpoints tuple
    """

    if (
        app.config["SIP_15_GRACE_PERIOD_END"]
        and date.today() >= app.config["SIP_15_GRACE_PERIOD_END"]
    ):
        return (TimeRangeEndpoint.INCLUSIVE, TimeRangeEndpoint.EXCLUSIVE)

    endpoints = form_data.get("time_range_endpoints")

    if (slc or slice_id) and not endpoints:
        try:
            _, datasource_type = get_datasource_info(None, None, form_data)
        except SupersetException:
            return None

        if datasource_type == "table":
            if not slc:
                slc = (
                    db.session.query(models.Slice).filter_by(id=slice_id).one_or_none()
                )

            if slc:
                endpoints = slc.datasource.database.get_extra().get(
                    "time_range_endpoints"
                )

            if not endpoints:
                endpoints = app.config["SIP_15_DEFAULT_TIME_RANGE_ENDPOINTS"]

    if endpoints:
        start, end = endpoints
        return (TimeRangeEndpoint(start), TimeRangeEndpoint(end))

    return (TimeRangeEndpoint.INCLUSIVE, TimeRangeEndpoint.EXCLUSIVE)
    def _determine_time_range_endpoints(
        self,
        raw_endpoints: Optional[Tuple[str, str]] = None,
    ) -> Optional[Tuple[TimeRangeEndpoint, TimeRangeEndpoint]]:
        if (self._config["SIP_15_GRACE_PERIOD_END"]
                and date.today() >= self._config["SIP_15_GRACE_PERIOD_END"]):
            return TimeRangeEndpoint.INCLUSIVE, TimeRangeEndpoint.EXCLUSIVE

        if raw_endpoints:
            start, end = raw_endpoints
            return TimeRangeEndpoint(start), TimeRangeEndpoint(end)

        return TimeRangeEndpoint.INCLUSIVE, TimeRangeEndpoint.EXCLUSIVE
예제 #4
0
def get_time_range_endpoints(
    form_data: Dict[str, Any], slc: Optional[models.Slice]
) -> Optional[Tuple[TimeRangeEndpoint, TimeRangeEndpoint]]:
    """
    Get the slice aware time range endpoints from the form-data falling back to the SQL
    database specific definition or default if not defined.

    When SIP-15 is enabled all slices and will the [start, end) interval. If the grace
    period is defined and has ended all slices will adhere to the [start, end) interval.

    :param form_data: The form-data
    :param slc: The chart
    :returns: The time range endpoints tuple
    """

    if (app.config["SIP_15_GRACE_PERIOD_END"]
            and date.today() >= app.config["SIP_15_GRACE_PERIOD_END"]):
        return (TimeRangeEndpoint.INCLUSIVE, TimeRangeEndpoint.EXCLUSIVE)

    endpoints = form_data.get("time_range_endpoints")

    if slc and not endpoints:
        try:
            _, datasource_type = get_datasource_info(None, None, form_data)
        except SupersetException:
            return None

        if datasource_type == "table":
            endpoints = slc.datasource.database.get_extra().get(
                "time_range_endpoints")

            if not endpoints:
                endpoints = app.config["SIP_15_DEFAULT_TIME_RANGE_ENDPOINTS"]

    if endpoints:
        start, end = endpoints
        return (TimeRangeEndpoint(start), TimeRangeEndpoint(end))

    return (TimeRangeEndpoint.INCLUSIVE, TimeRangeEndpoint.EXCLUSIVE)