-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathpredicate_validator.py
More file actions
36 lines (27 loc) · 1004 Bytes
/
predicate_validator.py
File metadata and controls
36 lines (27 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#
# Copyright (c) 2025 Airbyte, Inc., all rights reserved.
#
from dataclasses import dataclass
from typing import Any
from airbyte_cdk.sources.declarative.interpolation.interpolated_boolean import InterpolatedBoolean
from airbyte_cdk.sources.declarative.validators.validation_strategy import ValidationStrategy
from airbyte_cdk.sources.types import Config
@dataclass
class PredicateValidator:
"""
Validator that applies a validation strategy to a value.
"""
value: Any
strategy: ValidationStrategy
config: Config
condition: str
def __post_init__(self) -> None:
self._interpolated_condition = InterpolatedBoolean(condition=self.condition, parameters={})
def validate(self) -> None:
"""
Applies the validation strategy to the value.
:raises ValueError: If validation fails
"""
if self.condition and not self._interpolated_condition.eval(self.config):
return
self.strategy.validate(self.value)