Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add random sample to table manager #297

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions caveclient/tools/table_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ def query(
desired_resolution: Optional[list] = None,
get_counts: bool = False,
log_warning: bool = True,
random_sample: Optional[int] = None,
):
"""Set data return options for the specified query

Expand All @@ -690,6 +691,8 @@ def query(
If True, only return the number of rows that match the query, by default False
log_warning : bool, optional
Whether to log warnings associated with tables
random_sample: int, optional
If set, will return a random sample of the data, by default None

Returns
-------
Expand All @@ -710,6 +713,7 @@ def query(
get_counts=get_counts,
metadata=metadata,
log_warning=log_warning,
random_sample=random_sample,
**self.filter_kwargs_mat,
)
elif timestamp is None:
Expand All @@ -725,6 +729,7 @@ def query(
suffixes={self._reference_table: "_ref", self._base_table: ""},
metadata=metadata,
log_warning=log_warning,
random_sample=random_sample,
**self.filter_kwargs_mat,
)
else:
Expand All @@ -737,6 +742,7 @@ def query(
desired_resolution=desired_resolution,
allow_missing_lookups=False,
log_warning=log_warning,
random_sample=random_sample,
**self.filter_kwargs_mat,
)

Expand All @@ -750,6 +756,7 @@ def live_query(
desired_resolution: Optional[list] = None,
allow_missing_lookups: bool = False,
log_warning: bool = True,
random_sample: Optional[int] = None,
):
"""Set data return options for the specified live query

Expand All @@ -772,6 +779,8 @@ def live_query(
Do not set to True if writing code you intended to give consistent answers every time.
log_warning : bool, optional
Whether to log warnings associated with tables
random_sample: int, optional
If set, will return a random sample of the data, by default None

Returns
-------
Expand All @@ -791,6 +800,7 @@ def live_query(
allow_missing_lookups=allow_missing_lookups,
metadata=metadata,
log_warning=log_warning,
random_sample=random_sample,
**self.filter_kwargs_live,
)
else:
Expand All @@ -806,6 +816,7 @@ def live_query(
allow_missing_lookups=allow_missing_lookups,
metadata=metadata,
log_warning=log_warning,
random_sample=random_sample,
**self.filter_kwargs_live,
**self.joins_kwargs,
)
Expand All @@ -825,6 +836,7 @@ def query(
desired_resolution: Optional[list] = None,
get_counts: bool = False,
log_warning: bool = True,
random_sample: Optional[int] = None,
):
"""Query views through the table interface

Expand All @@ -850,6 +862,8 @@ def query(
Only return number of rows in the query, by default False
log_warning : bool, optional
Whether to log warnings associated with tables
random_sample: int, optional
If set, will return a random sample of the data, by default None
"""
return client.materialize.query_view(
self._base_table,
Expand All @@ -861,6 +875,7 @@ def query(
offset=offset,
select_columns=select_columns,
get_counts=get_counts,
random_sample=random_sample,
**self.filter_kwargs_mat,
)

Expand Down