def __init__( self, dataset: Dataset, params: ParamsType, query: Optional[str] = None, selected_columns: Optional[List[str]] = None, orderby: Optional[List[str]] = None, auto_aggregations: bool = False, use_aggregate_conditions: bool = False, limit: Optional[int] = 50, offset: Optional[int] = 0, limitby: Optional[Tuple[str, int]] = None, ): super().__init__(dataset, params) # TODO: implement this in `resolve_select` self.auto_aggregations = auto_aggregations self.limit = None if limit is None else Limit(limit) self.offset = None if offset is None else Offset(offset) self.limitby = self.resolve_limitby(limitby) self.where, self.having = self.resolve_conditions( query, use_aggregate_conditions=use_aggregate_conditions) # params depends on parse_query, and conditions being resolved first since there may be projects in conditions self.where += self.resolve_params() self.columns = self.resolve_select(selected_columns) self.orderby = self.resolve_orderby(orderby)
def data_fn(offset, limit): if use_snql: trend_query.offset = Offset(offset) trend_query.limit = Limit(limit) result = raw_snql_query( trend_query.get_snql_query(), referrer="api.trends.get-percentage-change.wip-snql", ) result = discover.transform_results( result, trend_query.function_alias_map, {}, None ) return result else: return discover.query( selected_columns=selected_columns + trend_columns, query=query, params=params, orderby=orderby, offset=offset, limit=limit, referrer="api.trends.get-percentage-change", auto_fields=True, auto_aggregations=True, use_aggregate_conditions=True, )
def run_outcomes_query_timeseries(query: QueryDefinition) -> ResultSet: snql_query = Query( dataset=query.dataset.value, match=Entity(query.match), select=query.select_params, groupby=query.group_by + [Column(TS_COL)], where=query.conditions, limit=Limit(10000), offset=Offset(0), granularity=Granularity(query.rollup), ) result_timeseries = raw_snql_query(snql_query, referrer="outcomes.timeseries") return _format_rows(result_timeseries["data"], query)
def __init__( self, dataset: Dataset, params: ParamsType, query: Optional[str] = None, selected_columns: Optional[List[str]] = None, equations: Optional[List[str]] = None, orderby: Optional[List[str]] = None, auto_fields: bool = False, auto_aggregations: bool = False, use_aggregate_conditions: bool = False, functions_acl: Optional[List[str]] = None, array_join: Optional[str] = None, limit: Optional[int] = 50, offset: Optional[int] = 0, limitby: Optional[Tuple[str, int]] = None, turbo: bool = False, sample_rate: Optional[float] = None, ): super().__init__(dataset, params, auto_fields, functions_acl) self.auto_aggregations = auto_aggregations self.limit = None if limit is None else Limit(limit) self.offset = None if offset is None else Offset(offset) self.limitby = self.resolve_limitby(limitby) self.turbo = Turbo(turbo) self.sample_rate = sample_rate self.where, self.having = self.resolve_conditions( query, use_aggregate_conditions=use_aggregate_conditions) # params depends on parse_query, and conditions being resolved first since there may be projects in conditions self.where += self.resolve_params() self.columns = self.resolve_select(selected_columns, equations) self.orderby = self.resolve_orderby(orderby) self.array_join = None if array_join is None else self.resolve_column( array_join)
], groupby=[Column("title")], where=[ Condition(Column("timestamp"), Op.GT, NOW), Condition(Function("toHour", [Column("timestamp")]), Op.LTE, NOW), Condition(Column("project_id"), Op.IN, Function("tuple", [1, 2, 3])), ], having=[ Condition(Function("uniq", [Column("event_id")]), Op.GT, 1) ], orderby=[OrderBy(Column("title"), Direction.ASC)], limitby=LimitBy(Column("title"), 5), limit=Limit(10), offset=Offset(1), granularity=Granularity(3600), totals=Totals(True), ), ( "MATCH (events SAMPLE 1000)", "SELECT title, uniq(event_id) AS uniq_events, quantile(0.5)(duration) AS p50", "BY title", ("WHERE timestamp > toDateTime('2021-01-02T03:04:05.000006') " "AND toHour(timestamp) <= toDateTime('2021-01-02T03:04:05.000006') " "AND project_id IN tuple(1, 2, 3)"), "HAVING uniq(event_id) > 1", "ORDER BY title ASC", "LIMIT 5 BY title", "LIMIT 10", "OFFSET 1",
def test_offset(value: Any, exception: Optional[Exception]) -> None: if exception is not None: with pytest.raises(type(exception), match=re.escape(str(exception))): Offset(value) else: assert Offset(value).offset == value
def set_offset(self, offset: int) -> "Query": return self._replace("offset", Offset(offset))