Example #1
0
from snuba.clickhouse.columns import Array, String
from snuba.datasets.entity import Entity
from snuba.query.exceptions import InvalidExpressionException
from snuba.query.expressions import Expression, FunctionCall
from snuba.query.parser.validation import ExpressionValidator
from snuba.query.validation import FunctionCallValidator, InvalidFunctionCall
from snuba.query.validation.signature import Any, Column, SignatureValidator

logger = logging.getLogger(__name__)

default_validators: Mapping[str, FunctionCallValidator] = {
    # like and notLike need to take care of Arrays as well since
    # Arrays are exploded into strings if they are part of the arrayjoin
    # clause.
    # TODO: provide a more restrictive support for arrayjoin.
    "like": SignatureValidator([Column({Array, String}),
                                Any()]),
    "notLike": SignatureValidator([Column({Array, String}),
                                   Any()]),
}


class FunctionCallsValidator(ExpressionValidator):
    """
    Applies all function validators on the provided expression.
    The individual function validators are divided in two mappings:
    a default one applied to all queries and one a mapping per dataset.
    """
    def validate(self, exp: Expression, entity: Entity) -> None:
        if not isinstance(exp, FunctionCall):
            return
Example #2
0
 pytest.param(
     (
         ColumnExpr(alias=None, table_name=None, column_name="event_id"),
         LiteralExpr(None, "param"),
     ),
     [Any(), Any()],
     False,
     False,
     id="Valid Expression",
 ),
 pytest.param(
     (
         ColumnExpr(alias=None, table_name=None, column_name="event_id"),
         LiteralExpr(None, "param"),
     ),
     [Column({String}), Any()],
     False,
     False,
     id="Valid Specific Expression",
 ),
 pytest.param(
     (
         ColumnExpr(alias=None, table_name=None, column_name="timestamp"),
         LiteralExpr(None, "param"),
     ),
     [Column({String}), Any()],
     False,
     True,
     id="Invalid specific expression",
 ),
 pytest.param(