-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dev-exp): Add support for storage direct queries (#186)
* add storage class * add storage query tests * add tests * request test * update CHANGES.rst * remove extra files * fix typing * update repr
- Loading branch information
1 parent
6e3dc43
commit 79e090a
Showing
16 changed files
with
350 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import re | ||
from dataclasses import dataclass, field | ||
from typing import Optional | ||
|
||
from snuba_sdk.expressions import Expression | ||
from snuba_sdk.schema import DataModel | ||
|
||
storage_name_re = re.compile(r"^[a-zA-Z_]+$") | ||
|
||
|
||
class InvalidStorageError(Exception): | ||
pass | ||
|
||
|
||
@dataclass(frozen=True, repr=False) | ||
class Storage(Expression): | ||
name: str | ||
sample: Optional[float] = None | ||
data_model: Optional[DataModel] = field(hash=False, default=None) | ||
|
||
def validate(self) -> None: | ||
if not isinstance(self.name, str) or not storage_name_re.match(self.name): | ||
raise InvalidStorageError(f"'{self.name}' is not a valid storage name") | ||
|
||
if self.sample is not None: | ||
if not isinstance(self.sample, float): | ||
raise InvalidStorageError("sample must be a float") | ||
elif self.sample <= 0.0: | ||
raise InvalidStorageError("samples must be greater than 0.0") | ||
|
||
if self.data_model is not None: | ||
if not isinstance(self.data_model, DataModel): | ||
raise InvalidStorageError("data_model must be an instance of DataModel") | ||
|
||
def __repr__(self) -> str: | ||
sample = f", sample={self.sample}" if self.sample is not None else "" | ||
return f"STORAGE('{self.name}'{sample})" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.