-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/0.3.0' into main
- Loading branch information
Showing
29 changed files
with
740 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
Empty file.
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,75 @@ | ||
from typing import List | ||
|
||
from metabase.mbql.base import Mbql, Option | ||
|
||
|
||
class Aggregation(Mbql): | ||
function: str | ||
|
||
def __init__(self, id: int, name: str = None, option: Option = None): | ||
self.name = name | ||
super(Aggregation, self).__init__(id=id, option=option) | ||
|
||
def compile(self) -> List: | ||
compiled = [self.function, super(Aggregation, self).compile()] | ||
|
||
if self.name is not None: | ||
compiled = self.compile_name(compiled, self.name) | ||
|
||
return compiled | ||
|
||
@staticmethod | ||
def compile_name(compiled, name: str) -> str: | ||
return ( | ||
["aggregation-options"] | ||
+ [compiled] | ||
+ [{"name": name, "display-name": name}] | ||
) | ||
|
||
|
||
class Count(Aggregation): | ||
function = "count" | ||
|
||
def __init__(self, id: int = None, name: str = None, option: Option = None): | ||
self.id = id | ||
self.name = name | ||
|
||
def compile(self) -> List: | ||
compiled = [self.function] | ||
|
||
if self.name is not None: | ||
compiled = self.compile_name(compiled, self.name) | ||
|
||
return compiled | ||
|
||
|
||
class Sum(Aggregation): | ||
function = "sum" | ||
|
||
|
||
class Average(Aggregation): | ||
function = "avg" | ||
|
||
|
||
class Distinct(Aggregation): | ||
function = "distinct" | ||
|
||
|
||
class CumulativeSum(Aggregation): | ||
function = "cum-sum" | ||
|
||
|
||
class CumulativeCount(Aggregation): | ||
function = "cum-count" | ||
|
||
|
||
class StandardDeviation(Aggregation): | ||
function = "stddev" | ||
|
||
|
||
class Min(Aggregation): | ||
function = "min" | ||
|
||
|
||
class Max(Aggregation): | ||
function = "max" |
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,17 @@ | ||
from typing import List | ||
|
||
|
||
class Option: | ||
pass | ||
|
||
|
||
class Mbql: | ||
def __init__(self, id: int, option: Option = None): | ||
self.id = id | ||
self.option = option | ||
|
||
def compile(self) -> List: | ||
return ["field", self.id, self.option] | ||
|
||
def __repr__(self): | ||
return str(self.compile()) |
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,141 @@ | ||
from typing import Any, List | ||
|
||
from metabase.mbql.base import Mbql, Option | ||
|
||
|
||
class CaseOption(Option): | ||
CASE_SENSITIVE = {"case-sensitive": True} | ||
CASE_INSENSITIVE = {"case-sensitive": False} | ||
|
||
|
||
class TimeGrainOption(Option): | ||
MINUTE = "minute" | ||
HOUR = "hour" | ||
DAY = "day" | ||
WEEK = "week" | ||
MONTH = "month" | ||
QUARTER = "quarter" | ||
YEAR = "year" | ||
|
||
|
||
class Filter(Mbql): | ||
function: str | ||
|
||
def __init__(self, id: int, option: Option = None): | ||
self.id = id | ||
self.option = None | ||
self.filter_option = option | ||
|
||
def compile(self) -> List: | ||
compiled = [self.function, super(Filter, self).compile()] | ||
|
||
if self.filter_option is not None: | ||
compiled = compiled + [self.filter_option] | ||
|
||
return compiled | ||
|
||
|
||
class ValueFilter(Filter): | ||
def __init__(self, id: int, value: Any, option: Option = None): | ||
self.id = id | ||
self.value = value | ||
self.option = None | ||
self.filter_option = option | ||
|
||
def compile(self) -> List: | ||
compiled = [self.function, super(Filter, self).compile(), self.value] | ||
|
||
if self.filter_option is not None: | ||
compiled = compiled + [self.filter_option] | ||
|
||
return compiled | ||
|
||
|
||
class Equal(ValueFilter): | ||
function = "=" | ||
|
||
|
||
class NotEqual(ValueFilter): | ||
function = "!=" | ||
|
||
|
||
class Greater(ValueFilter): | ||
function = ">" | ||
|
||
|
||
class Less(ValueFilter): | ||
function = "<" | ||
|
||
|
||
class Between(Filter): | ||
function = "between" | ||
|
||
def __init__( | ||
self, id: int, lower_bound: float, upper_bound: float, option: Option = None | ||
): | ||
self.id = id | ||
self.option = None | ||
self.filter_option = option | ||
self.lower_bound = lower_bound | ||
self.upper_bound = upper_bound | ||
|
||
def compile(self) -> List: | ||
return super(Between, self).compile() + [self.lower_bound, self.upper_bound] | ||
|
||
|
||
class GreaterEqual(ValueFilter): | ||
function = ">=" | ||
|
||
|
||
class LessEqual(ValueFilter): | ||
function = "<=" | ||
|
||
|
||
class IsNull(Filter): | ||
function = "is-null" | ||
|
||
|
||
class IsNotNull(Filter): | ||
function = "not-null" | ||
|
||
|
||
class Contains(ValueFilter): | ||
function = "contains" | ||
|
||
|
||
class StartsWith(ValueFilter): | ||
function = "starts-with" | ||
|
||
|
||
class EndsWith(ValueFilter): | ||
function = "ends-with" | ||
|
||
|
||
class TimeInterval(Filter): | ||
function = "time-interval" | ||
|
||
def __init__( | ||
self, | ||
id: int, | ||
value: Any, | ||
time_grain: TimeGrainOption, | ||
include_current: bool = True, | ||
): | ||
self.id = id | ||
self.value = value | ||
self.option = None | ||
self.time_grain = time_grain | ||
self.include_current = include_current | ||
|
||
def compile(self) -> List: | ||
compiled = [ | ||
self.function, | ||
super(Filter, self).compile(), | ||
self.value, | ||
self.time_grain, | ||
] | ||
|
||
if self.include_current: | ||
compiled = compiled + [{"include-current": True}] | ||
|
||
return compiled |
Oops, something went wrong.