def METHOD_NAME(use_discover: bool, remove_on_demand: bool):
    """
    Returns a get_stats function that can fetch from either metrics or discover and
        with or without on_demand metrics.
    """
    def get_discover_stats(
        query_columns: Sequence[str],
        query: str,
        params: Dict[str, str],
        rollup: int,
        zerofill_results: bool,
        comparison_delta: Optional[datetime],
    ) -> SnubaTSResult:
        # use discover or metrics_performance depending on the dataset
        if use_discover:
            module: ModuleType = discover
        else:
            module = metrics_performance
            # (RaduW) horrible hack check function definition
            query_columns = to_metrics_columns(query_columns)
        if remove_on_demand:
            query = to_standard_metrics_query(query)
        return module.timeseries_query(
            selected_columns=query_columns,
            query=query,
            params=params,
            rollup=rollup,
            referrer=Referrer.API_ORGANIZATION_METRICS_ESTIMATION_STATS.value,
            zerofill_results=True,
            has_metrics=True,
        )
    return get_discover_stats