def validate(self, query: Query, alias: Optional[str] = None) -> None: granularity = query.get_granularity() if granularity is None: if self.required: raise InvalidQueryException("Granularity is missing") elif granularity < self.minimum or (granularity % self.minimum) != 0: raise InvalidQueryException( f"granularity must be multiple of {self.minimum}")
def _format_granularity( query: AbstractQuery, formatter: ExpressionVisitor[str] ) -> Optional[StringNode]: ast_granularity = query.get_granularity() return ( StringNode(f"GRANULARITY {ast_granularity}") if ast_granularity is not None else None )