-
Notifications
You must be signed in to change notification settings - Fork 16.6k
Implement specialized get_first and get_records method in OracleHook #61144
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
dabla
merged 20 commits into
apache:main
from
dabla:feature/oracle-hook-resolve-oracledb-types-handler
Feb 1, 2026
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1d3dc64
refactor: Override the get_first and get_records method with Oracle e…
dabla b84a8da
Merge branch 'main' into feature/oracle-hook-resolve-oracledb-types-h…
dabla 9492135
refactor: Added unit test for get_first and get_records method
dabla 49730a4
Merge branch 'main' into feature/oracle-hook-resolve-oracledb-types-h…
dabla 5bc5c17
refactor: Reformatted get_first method in OracleHook
dabla 37b8df9
refactor: Fixed test_test_connection_use_dual_table
dabla afab71b
Merge branch 'main' into feature/oracle-hook-resolve-oracledb-types-h…
dabla c14f705
Update providers/oracle/src/airflow/providers/oracle/hooks/oracle.py
dabla 0263e5a
refactor: Moved Oracle handlers in separate module like in common.sql
dabla 7178b8b
refactor: Fixed return type of fetch_one_handler in common.sql provider
dabla 49a4e11
Merge branch 'main' into feature/oracle-hook-resolve-oracledb-types-h…
dabla ce05d62
refactor: Fixed return type of fetch_one_handler in common.sql provider
dabla d6f6deb
refactor: Added handlers in python-module of Oracle hook
dabla b83516b
refactor: Added handlers test for Oracle provider
dabla 4cca406
refactor: Updated hooks in provider info
dabla da5f0a0
refactor: Reformatted test files
dabla ef3c2e2
refactor: Updated test_fetch_one_handler as fetchone method is suppos…
dabla 46e2b16
Merge branch 'main' into feature/oracle-hook-resolve-oracledb-types-h…
dabla aa28f49
Merge branch 'main' into feature/oracle-hook-resolve-oracledb-types-h…
dabla d2fe038
Merge branch 'main' into feature/oracle-hook-resolve-oracledb-types-h…
dabla 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
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
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
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
57 changes: 57 additions & 0 deletions
57
providers/oracle/src/airflow/providers/oracle/hooks/handlers.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,57 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you 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. | ||
| from __future__ import annotations | ||
|
|
||
| import oracledb | ||
|
|
||
|
|
||
| def _read_lob(val): | ||
| if isinstance(val, oracledb.LOB): | ||
| return val.read() | ||
| return val | ||
|
|
||
|
|
||
| def _read_lobs(row): | ||
| if row is not None: | ||
| return tuple([_read_lob(value) for value in row]) | ||
| return row | ||
|
|
||
|
|
||
| def fetch_all_handler(cursor) -> list[tuple] | None: | ||
| """Return results for DbApiHook.run(). If oracledb.LOB objects are present, then those will be read.""" | ||
| if not hasattr(cursor, "description"): | ||
| raise RuntimeError( | ||
| "The database we interact with does not support DBAPI 2.0. Use operator and " | ||
| "handlers that are specifically designed for your database." | ||
| ) | ||
| if cursor.description is not None: | ||
| results = [_read_lobs(row) for row in cursor.fetchall()] | ||
| return results | ||
| return None | ||
|
|
||
|
|
||
| def fetch_one_handler(cursor) -> tuple | None: | ||
| """Return first result for DbApiHook.run(). If oracledb.LOB objects are present, then those will be read.""" | ||
| if not hasattr(cursor, "description"): | ||
| raise RuntimeError( | ||
| "The database we interact with does not support DBAPI 2.0. Use operator and " | ||
| "handlers that are specifically designed for your database." | ||
| ) | ||
| if cursor.description is not None: | ||
| return _read_lobs(cursor.fetchone()) | ||
| return None |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you 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. | ||
| from __future__ import annotations | ||
|
|
||
| from unittest.mock import MagicMock | ||
|
|
||
| from airflow.providers.oracle.hooks.handlers import ( | ||
| fetch_all_handler, | ||
| fetch_one_handler, | ||
| ) | ||
|
|
||
| from unit.oracle.test_utils import mock_oracle_lob | ||
|
|
||
|
|
||
| class TestHandlers: | ||
| def test_fetch_all_handler(self): | ||
| cursor = MagicMock() | ||
| cursor.description = [("col1", "int"), ("col2", "string")] | ||
| cursor.fetchall.return_value = [(1, mock_oracle_lob("hello"))] | ||
|
|
||
| assert fetch_all_handler(cursor) == [(1, "hello")] | ||
|
|
||
| cursor.description = None | ||
| assert fetch_all_handler(cursor) is None | ||
|
|
||
| def test_fetch_one_handler(self): | ||
| cursor = MagicMock() | ||
| cursor.description = [("col1", "int")] | ||
| cursor.fetchone.return_value = (mock_oracle_lob("hello"),) | ||
|
|
||
| assert fetch_one_handler(cursor) == ("hello",) | ||
|
|
||
| cursor.description = None | ||
| assert fetch_one_handler(cursor) is None |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you 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. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from unittest.mock import MagicMock | ||
|
|
||
| import oracledb | ||
|
|
||
|
|
||
| def mock_oracle_lob(value): | ||
| mock_lob = MagicMock(spec=oracledb.LOB) | ||
| mock_lob.read.return_value = value | ||
| return mock_lob |
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.