Ejemplo n.º 1
0
    def validate(self, query: Query, alias: Optional[str] = None) -> None:
        selected = query.get_selected_columns()
        if len(selected) != 1:
            raise InvalidQueryException(
                "only one aggregation in the select allowed")

        disallowed = ["groupby", "having", "orderby"]
        for field in disallowed:
            if getattr(query, f"get_{field}")():
                raise InvalidQueryException(
                    f"invalid clause {field} in subscription query")
Ejemplo n.º 2
0
    def validate(
        self,
        query: Query,
        alias: Optional[str] = None,
    ) -> None:
        selected = query.get_selected_columns()
        if len(selected) > self.max_allowed_aggregations:
            aggregation_error_text = (
                "1 aggregation is" if self.max_allowed_aggregations == 1 else
                f"{self.max_allowed_aggregations} aggregations are")
            raise InvalidQueryException(
                f"A maximum of {aggregation_error_text} allowed in the select")

        for field in self.disallowed_aggregations:
            if getattr(query, f"get_{field}")():
                raise InvalidQueryException(
                    f"invalid clause {field} in subscription query")

        if "groupby" not in self.disallowed_aggregations:
            self._validate_groupby_fields_have_matching_conditions(
                query, alias)
Ejemplo n.º 3
0
def _format_select(query: AbstractQuery,
                   formatter: ClickhouseExpressionFormatterBase) -> StringNode:
    selected_cols = [
        e.expression.accept(formatter) for e in query.get_selected_columns()
    ]
    return StringNode(f"SELECT {', '.join(selected_cols)}")
Ejemplo n.º 4
0
def _format_select(query: AbstractQuery,
                   formatter: ExpressionVisitor[str]) -> StringNode:
    selected_cols = [
        e.expression.accept(formatter) for e in query.get_selected_columns()
    ]
    return StringNode(f"SELECT {', '.join(selected_cols)}")