-
Notifications
You must be signed in to change notification settings - Fork 2k
Fixes #25721: Handle Pinot JSON results with a custom type #27530
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
Draft
hyspacex
wants to merge
1
commit into
open-metadata:main
Choose a base branch
from
hyspacex:pinot-json-type-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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
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
49 changes: 49 additions & 0 deletions
49
ingestion/src/metadata/ingestion/source/database/pinotdb/custom_types.py
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,49 @@ | ||
| # Copyright 2025 Collate | ||
| # Licensed under the Collate Community License, Version 1.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # https://github.com/open-metadata/OpenMetadata/blob/main/ingestion/LICENSE | ||
| # 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. | ||
| """Custom Pinot SQLAlchemy types.""" | ||
| import json | ||
| from typing import Any | ||
|
|
||
| from sqlalchemy import types | ||
|
|
||
| from metadata.utils.logger import ingestion_logger | ||
|
|
||
| logger = ingestion_logger() | ||
|
|
||
|
|
||
| class PinotJSONType(types.JSON): | ||
| """ | ||
| Replace SQLAlchemy's default JSON result processor to normalize Pinot's | ||
| engine-dependent payloads. | ||
|
|
||
| The single-stage engine can return already-deserialized Python containers, | ||
| while the multistage engine returns raw JSON strings. This custom type | ||
| accepts both shapes while preserving JSON semantics for OpenMetadata. | ||
| """ | ||
|
|
||
| def result_processor(self, dialect, coltype): | ||
| def process(value: Any) -> Any: | ||
| if value is None or isinstance(value, (dict, list)): | ||
| return value | ||
|
|
||
| if isinstance(value, (str, bytes, bytearray)): | ||
| try: | ||
| return json.loads(value) | ||
| except (TypeError, ValueError) as exc: | ||
| logger.warning( | ||
| "Failed to deserialize Pinot JSON value. Returning raw value instead: %s", | ||
| exc, | ||
| ) | ||
| return value | ||
|
|
||
| return value | ||
|
|
||
| return process | ||
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Edge Case: result_processor passes through numeric/bool JSON scalars unparsed
In
PinotJSONType.result_processor, a raw JSON numeric or boolean scalar (e.g., the string"42"or"true"representing a JSON column value) would fall through to theisinstance(value, str)branch and be parsed correctly viajson.loads. However, if Pinot's single-stage engine returns a Pythonint,float, orbool(which are valid JSON scalars), these fall through to the finalreturn valuewithout being covered by theisinstance(value, (dict, list))short-circuit. This is functionally correct (they're already deserialized), but the docstring and the test coverage only describe containers. Consider adding a test case for scalar JSON values (int/float/bool) to document this behavior explicitly.Was this helpful? React with 👍 / 👎 | Reply
gitar fixto apply this suggestion