Example #1
0
    def __validate_impl(self, parameters: Sequence[Expression],
                        schema: ColumnSet) -> None:
        if len(parameters) < len(self.__param_types):
            raise InvalidFunctionCall(
                f"Too few arguments. Required {[str(t) for t in self.__param_types]}"
            )

        if not self.__allow_extra_params and len(parameters) > len(
                self.__param_types):
            raise InvalidFunctionCall(
                f"Too many arguments. Required {[str(t) for t in self.__param_types]}"
            )

        for validator, param in zip(self.__param_types, parameters):
            validator.validate(param, schema)
Example #2
0
    def __validate_impl(self, func_name: str, parameters: Sequence[Expression],
                        data_source: DataSource) -> None:
        if len(parameters) < len(self.__param_types):
            raise InvalidFunctionCall(
                f"Too few arguments. Required {[str(t) for t in self.__param_types]}"
            )

        if not self.__allow_extra_params and len(parameters) > len(
                self.__param_types):
            raise InvalidFunctionCall(
                f"Too many arguments. Required {[str(t) for t in self.__param_types]}"
            )

        for validator, param in zip(self.__param_types, parameters):
            validator.validate(param, data_source.get_columns())
Example #3
0
    def validate(self, expression: Expression, schema: ColumnSet) -> None:
        match = COLUMN_PATTERN.match(expression)
        if match is None:
            return

        column_name = match.string("column_name")
        column = schema.get(column_name)
        if column is None:
            # TODO: We cannot raise exceptions if the column is not present
            # on the schema just yet because the current logical schemas are
            # sadly not complete. Fix them and then raise an exception in this
            # case.
            return

        nullable = column.type.has_modifier(Nullable)

        if not isinstance(column.type, tuple(self.__valid_types)) or (
            nullable and not self.__allow_nullable
        ):
            raise InvalidFunctionCall(
                (
                    f"Illegal type {'Nullable ' if nullable else ''}{str(column.type)} "
                    f"of argument `{column_name}`. Required types {self.__valid_types}"
                )
            )
Example #4
0
    def validate(self, expression: Expression, schema: ColumnSet) -> None:
        if not isinstance(expression, LiteralType):
            return None

        value = expression.value
        if not isinstance(value, tuple(self.__valid_types)):
            raise InvalidFunctionCall(
                f"Illegal type {type(value)} of argument {value}. Required types {self.__valid_types}"
            )
Example #5
0
    def validate(self, func_name: str, parameters: Sequence[Expression],
                 data_source: DataSource) -> None:

        if is_valid_global_function(func_name):
            return

        if state.get_config("function-validator.enabled", False):
            raise InvalidFunctionCall(f"Invalid function name: {func_name}")
        else:
            metrics.increment("invalid_funcs", tags={"func_name": func_name})
Example #6
0
    def validate(self, parameters: Sequence[Expression],
                 schema: ColumnSet) -> None:
        if self.__fails:
            raise InvalidFunctionCall()

        return
Example #7
0
    def validate(self, func_name: str, parameters: Sequence[Expression],
                 data_source: DataSource) -> None:
        if self.__fails:
            raise InvalidFunctionCall()

        return