-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
agg granularity to restrict group by
- Loading branch information
Showing
4 changed files
with
65 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from enum import IntEnum, EnumMeta | ||
from pyspark.sql.column import Column | ||
|
||
class AggregationGranularity: | ||
def __init__(self, granularity: EnumMeta) -> None: | ||
assert isinstance(granularity, EnumMeta), "Granularity should be of type Enum." | ||
self.granularity = granularity | ||
|
||
|
||
def validate(self, feat, groupby_list): | ||
if not feat.agg_granularity: | ||
return None | ||
min_granularity_level = float("inf") | ||
for level in groupby_list: | ||
if isinstance(level, str): | ||
try: | ||
level = self.granularity[level] | ||
except: | ||
print(f"{level} is not part of {self.granularity}") | ||
continue | ||
if isinstance(level, Column): | ||
continue | ||
min_granularity_level = min(min_granularity_level, level.value) | ||
assert min_granularity_level <= feat.agg_granularity.value, f"Required granularity for {feat.name} is {feat.agg_granularity}" | ||
|
||
|
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