Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions producer/spark_dataproc/scenarios/hive/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"min": "1.0.0",
"max": "5.0.0"
},
"unchecked_facets": {
"catalog": ["1.38.0","1.39.0","1.40.0","1.40.1"]
},
"tests": [
{
"name": "run_event_test",
Expand Down
29 changes: 25 additions & 4 deletions scripts/validate_ol_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
from jsonschema import RefResolver

class OLSyntaxValidator:
def __init__(self, schema_validators):
def __init__(self, schema_validators, unchecked_facets=None, openlineage_version=None):
self.schema_validators = schema_validators
self.unchecked_facets = unchecked_facets or {}
self.openlineage_version = openlineage_version

@staticmethod
def is_custom_facet(facet, schema_type):
Expand All @@ -36,7 +38,7 @@ def get_validators(cls, spec_path, tags):
return {tag: cls.get_validator(spec_path, tag) for tag in tags}

@classmethod
def get_validator(cls, spec_path, tag):
def get_validator(cls, spec_path, tag, unchecked_facets=None):
file_paths = listdir(join(spec_path, tag))
facet_schemas = [load_json(join(spec_path, tag, path)) for path in file_paths if path.__contains__('Facet.json')]
spec_schema = next(load_json(join(spec_path, tag, path)) for path in file_paths if path.__contains__('OpenLineage.json'))
Expand All @@ -51,9 +53,14 @@ def get_validator(cls, spec_path, tag):
schema_validators[name] = Draft202012Validator(schema, resolver=resolver)

schema_validators['core'] = Draft202012Validator(spec_schema)
return cls(schema_validators)
return cls(schema_validators, unchecked_facets, tag)

def validate_entity(self, instance, schema_type, name):
# Check if this facet should be skipped for the current version
if self.should_skip_facet(schema_type):
print(f"Skipping validation for facet '{schema_type}' in version {self.openlineage_version} (unchecked_facets)")
return []

try:
schema_validator = self.schema_validators.get(schema_type)
if schema_validator is not None:
Expand All @@ -70,6 +77,17 @@ def validate_entity(self, instance, schema_type, name):
except Exception:
print(f"when validating {schema_type}, for instance of {name} following exception occurred \n {traceback.format_exc()}")

def should_skip_facet(self, facet_name):
if not self.unchecked_facets or not self.openlineage_version:
return False

if facet_name in self.unchecked_facets:
excluded_versions = self.unchecked_facets[facet_name]
if self.openlineage_version in excluded_versions:
return True

return False

def validate(self, event, name):
validation_result = []
run_validation = self.validate_entity(event, 'core', name)
Expand Down Expand Up @@ -243,16 +261,19 @@ def main():
if isdir(scenario_path):
config = get_config(producer_dir, component, scenario_name)
validator = validators.get(config.get('openlineage_version'))
if 'unchecked_facets' in config:
validator.unchecked_facets = config['unchecked_facets']
print(f"for scenario {scenario_name} validation version is {config.get('openlineage_version')}")
result_events = {file: load_json(path) for file in listdir(scenario_path) if
isfile(path := join(scenario_path, file))}
tests = validate_scenario_syntax(result_events, validator, config)
scenarios[scenario_name] = Scenario.simplified(scenario_name, tests)
report = Report({component: Component(component, 'producer', scenarios, "", "")})
else:
validator = OLSyntaxValidator.get_validator(spec_path=spec_dirs, tag=openlineage_version)
for scenario_name in listdir(base_dir):
config = get_config(producer_dir, component, scenario_name)
unchecked_facets = config.get('unchecked_facets')
validator = OLSyntaxValidator.get_validator(spec_path=spec_dirs, tag=openlineage_version, unchecked_facets=unchecked_facets)
scenario_path = get_path(base_dir, component, scenario_name)
expected = get_expected_events(producer_dir, component, scenario_name, config, component_version, openlineage_version)
result_events = {file: load_json(path) for file in listdir(scenario_path) if
Expand Down
Loading