Skip to content

Commit

Permalink
added select_txt and select_distinct function to main pipestat class
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldcampbelljr committed Sep 5, 2023
1 parent ee98145 commit 4588f4f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
8 changes: 8 additions & 0 deletions pipestat/backends/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,11 @@ def remove_record(
def select(self):
_LOGGER.warning("Not implemented yet for this backend")
pass

Check warning on line 150 in pipestat/backends/abstract.py

View check run for this annotation

Codecov / codecov/patch

pipestat/backends/abstract.py#L149-L150

Added lines #L149 - L150 were not covered by tests

def select_txt(self):
_LOGGER.warning("Not implemented yet for this backend")
pass

Check warning on line 154 in pipestat/backends/abstract.py

View check run for this annotation

Codecov / codecov/patch

pipestat/backends/abstract.py#L153-L154

Added lines #L153 - L154 were not covered by tests

def select_distinct(self):
_LOGGER.warning("Not implemented yet for this backend")
pass

Check warning on line 158 in pipestat/backends/abstract.py

View check run for this annotation

Codecov / codecov/patch

pipestat/backends/abstract.py#L157-L158

Added lines #L157 - L158 were not covered by tests
38 changes: 38 additions & 0 deletions pipestat/pipestat.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,44 @@ def select(self, **kwargs):

return result

@require_backend
def select_txt(self, **kwargs):
"""
Execute a query with a textual filter. Returns all results.
To retrieve all table contents, leave the filter arguments out.
Table name uses pipeline_type
:param str filter_templ: filter template with value placeholders,
formatted as follows `id<:value and name=:name`
:param Dict[str, Any] filter_params: a mapping keys specified in the `filter_templ`
to parameters that are supposed to replace the placeholders
:param str table_name: name of the table to query
:param int offset: skip this number of rows
:param int limit: include this number of rows
:param str pipeline_type: sample vs project pipeline
:return List[Any]: a list of matched records
"""
# Note this is only implemented for DBBackend
result = self.backend.select_txt(**kwargs)

return result

@require_backend
def select_distinct(self, **kwargs):
"""
Perform a `SELECT DISTINCT` on given table and column
:param str table_name: name of the table to SELECT from
:param List[str] columns: columns to include in the result
:param str pipeline_type: "sample" or "project"
:return List[Any]: returns distinct values.
"""
# Note this is only implemented for DBBackend
results = self.backend.select_distinct(**kwargs)

Check warning on line 521 in pipestat/pipestat.py

View check run for this annotation

Codecov / codecov/patch

pipestat/pipestat.py#L521

Added line #L521 was not covered by tests

return results

Check warning on line 523 in pipestat/pipestat.py

View check run for this annotation

Codecov / codecov/patch

pipestat/pipestat.py#L523

Added line #L523 was not covered by tests

@require_backend
def set_status(
self,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_db_only_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,5 @@ def test_select_txt(
psm.report(values=val, force_overwrite=True)
val_name = list(val.keys())[0]
# assert psm.backend.select(filter_conditions=[(val_name, "eq", val[val_name])])[0]
assert val_name in str(psm.backend.select_txt())
assert val_name not in str(psm.backend.select_txt(offset=2))
assert val_name in str(psm.select_txt())
assert val_name not in str(psm.select_txt(offset=2))
6 changes: 3 additions & 3 deletions tests/test_pipestat.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def test_remove_basic(
else:
col_name = list(vals[0].keys())[0]
value = list(vals[0].values())[0]
result = psm.backend.select(filter_conditions=[(col_name, "eq", value)])
result = psm.select(filter_conditions=[(col_name, "eq", value)])
assert len(result) == 0

@pytest.mark.parametrize("rec_id", ["sample1", "sample2"])
Expand Down Expand Up @@ -496,7 +496,7 @@ def test_remove_record(
else:
col_name = list(vals[0].keys())[0]
value = list(vals[0].values())[0]
result = psm.backend.select(filter_conditions=[(col_name, "eq", value)])
result = psm.select(filter_conditions=[(col_name, "eq", value)])
assert len(result) == 0

@pytest.mark.parametrize(
Expand Down Expand Up @@ -615,7 +615,7 @@ def test_report(
)
if backend == "db":
val_name = list(val.keys())[0]
assert psm.backend.select(filter_conditions=[(val_name, "eq", val[val_name])])
assert psm.select(filter_conditions=[(val_name, "eq", val[val_name])])

@pytest.mark.parametrize(
"val",
Expand Down

0 comments on commit 4588f4f

Please sign in to comment.