-
Notifications
You must be signed in to change notification settings - Fork 62
Add schema verification step #955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Eyal-Danieli
merged 6 commits into
mlrun:development
from
danielperezz:verify-schema-step
Dec 31, 2025
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
97592c0
step files, empty notebook
danielperezz 60bdce5
missing type hint
danielperezz 501a47d
fix test
danielperezz ce939ec
post review fixes
danielperezz 8e1cc98
fix test and cover new argument
danielperezz 293aeb7
add copyright
danielperezz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| apiVersion: v1 | ||
| categories: | ||
| - data-preparation | ||
| - model-serving | ||
| description: 'This step verifies the event is aligned with the provided schema.' | ||
danielperezz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| example: verify_schema.ipynb | ||
| generationDate: 2025-12-29:11-59 | ||
| hidden: false | ||
| labels: | ||
| author: Iguazio | ||
| mlrunVersion: 1.10.0-rc44 | ||
danielperezz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| name: verify_schema | ||
| className: VerifySchema | ||
| defaultHandler: | ||
| spec: | ||
| filename: verify_schema.py | ||
| image: mlrun/mlrun | ||
| requirements: | ||
| version: 1.0.0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| from verify_schema import VerifySchema | ||
danielperezz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| class TestVerifySchema: | ||
| def test_verify_schema(self): | ||
| schema = ["id", "name", "active"] | ||
| verifier = VerifySchema(name="test_verifier", schema=schema) | ||
|
|
||
| # Test with valid event | ||
| event = { | ||
| "id": 1, | ||
| "name": "Test Event", | ||
| "active": True | ||
| } | ||
| result = verifier.do(event) | ||
| assert result == event | ||
|
|
||
| # Test with missing key | ||
| event_missing_key = { | ||
| "id": 1, | ||
| "name": "Test Event" | ||
| } | ||
| try: | ||
| verifier.do(event_missing_key) | ||
| except KeyError as e: | ||
| assert "key 'active' not found in event" in str(e) | ||
|
|
||
| # Test with unexpected key | ||
| event_unexpected_key = { | ||
| "id": 1, | ||
| "name": "Test Event", | ||
| "active": True, | ||
| "extra": "unexpected" | ||
| } | ||
| try: | ||
| verifier.do(event_unexpected_key) | ||
| except KeyError as e: | ||
| assert "unexpected key 'extra' found in event" in str(e) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "metadata": {}, | ||
| "cell_type": "code", | ||
| "outputs": [], | ||
| "execution_count": null, | ||
| "source": "", | ||
| "id": "556b36b9b89d0515" | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "Python 3", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 2 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython2", | ||
| "version": "2.7.6" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Copyright 2025 Iguazio | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| class VerifySchema: | ||
danielperezz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def __init__(self, name, schema: list): | ||
danielperezz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| self.name = name | ||
danielperezz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| self.schema = schema | ||
|
|
||
| def do(self, event: dict): | ||
| missing = set(self.schema) - set(event) | ||
| unexpected = set(event) - set(self.schema) | ||
| if missing: | ||
| raise KeyError(f"Schema verification failed: missing keys {missing} in event: {event}") | ||
| if unexpected: | ||
| raise KeyError(f"Schema verification failed: unexpected keys {unexpected} in event: {event}") | ||
| return event | ||
danielperezz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.