-
Notifications
You must be signed in to change notification settings - Fork 99
feat(ibis): Add Oracle connector #1067
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
Merged
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
97a470c
feat(ibis): Add Oracle connector
douenergy caf7545
Fix Oracle connection issue
douenergy 11a5731
more test case
douenergy 13dedb1
validate test
douenergy a31fe48
pass metadata test
douenergy d73a3d4
more metadata test
douenergy baa1f15
pass all oracle test
douenergy fe2a2a1
Merge branch 'main' into oracle-connector
douenergy 6e484da
update poetry.lcok
douenergy 747e197
fix test assert
douenergy 2bad36e
fix flaky test_local_file
douenergy a7fd85d
enhance the test
douenergy 279c583
Merge remote-tracking branch 'wren/main' into oracle-connector
douenergy 30611a1
update lock file
douenergy 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import base64 | ||
|
||
import orjson | ||
import pandas as pd | ||
import pytest | ||
import sqlalchemy | ||
from sqlalchemy import text | ||
from testcontainers.oracle import OracleDbContainer | ||
|
||
from tests.conftest import file_path | ||
|
||
pytestmark = pytest.mark.oracle | ||
|
||
base_url = "/v2/connector/oracle" | ||
oracle_password = "Oracle123" | ||
oracle_user = "SYSTEM" | ||
oracle_database = "FREEPDB1" | ||
|
||
manifest = { | ||
"catalog": "my_catalog", | ||
"schema": "my_schema", | ||
"models": [ | ||
{ | ||
"name": "Orders", | ||
"tableReference": { | ||
"schema": "SYSTEM", | ||
"table": "ORDERS", | ||
}, | ||
"columns": [ | ||
{"name": "orderkey", "expression": "O_ORDERKEY", "type": "number"}, | ||
{"name": "custkey", "expression": "O_CUSTKEY", "type": "number"}, | ||
{ | ||
"name": "orderstatus", | ||
"expression": "O_ORDERSTATUS", | ||
"type": "varchar2", | ||
douenergy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
{ | ||
"name": "totalprice", | ||
"expression": "O_TOTALPRICE", | ||
"type": "number", | ||
}, | ||
{"name": "orderdate", "expression": "O_ORDERDATE", "type": "date"}, | ||
{ | ||
"name": "order_cust_key", | ||
"expression": "O_ORDERKEY || '_' || O_CUSTKEY", | ||
"type": "varchar2", | ||
}, | ||
{ | ||
"name": "timestamp", | ||
"expression": "TO_TIMESTAMP('2024-01-01 23:59:59', 'YYYY-MM-DD HH24:MI:SS')", | ||
"type": "timestamp", | ||
}, | ||
{ | ||
"name": "test_null_time", | ||
"expression": "CAST(NULL AS TIMESTAMP)", | ||
"type": "timestamp", | ||
}, | ||
{ | ||
"name": "blob_column", | ||
"expression": "UTL_RAW.CAST_TO_RAW('abc')", | ||
"type": "blob", | ||
}, | ||
], | ||
"primaryKey": "orderkey", | ||
} | ||
], | ||
} | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def manifest_str(): | ||
return base64.b64encode(orjson.dumps(manifest)).decode("utf-8") | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def oracle(request) -> OracleDbContainer: | ||
oracle = OracleDbContainer( | ||
"gvenzl/oracle-free:23.6-slim-faststart", oracle_password=f"{oracle_password}" | ||
).start() | ||
engine = sqlalchemy.create_engine(oracle.get_connection_url()) | ||
with engine.begin() as conn: | ||
pd.read_parquet(file_path("resource/tpch/data/orders.parquet")).to_sql( | ||
"orders", engine, index=False | ||
) | ||
pd.read_parquet(file_path("resource/tpch/data/customer.parquet")).to_sql( | ||
"customer", engine, index=False | ||
) | ||
Comment on lines
+92
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling for data loading. The data loading from parquet files lacks error handling. Consider:
|
||
# Add table and column comments | ||
conn.execute(text("COMMENT ON TABLE orders IS 'This is a table comment'")) | ||
conn.execute(text("COMMENT ON COLUMN orders.o_comment IS 'This is a comment'")) | ||
|
||
return oracle | ||
|
||
douenergy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
async def test_query(client, manifest_str, oracle: OracleDbContainer): | ||
connection_info = _to_connection_info(oracle) | ||
response = await client.post( | ||
url=f"{base_url}/query", | ||
json={ | ||
"connectionInfo": connection_info, | ||
"manifestStr": manifest_str, | ||
"sql": 'SELECT * FROM "Orders" LIMIT 1', | ||
}, | ||
) | ||
assert response.status_code == 200 | ||
|
||
|
||
async def test_query_with_connection_url( | ||
client, manifest_str, oracle: OracleDbContainer | ||
): | ||
connection_url = _to_connection_url(oracle) | ||
response = await client.post( | ||
url=f"{base_url}/query", | ||
json={ | ||
"connectionInfo": {"connectionUrl": connection_url}, | ||
"manifestStr": manifest_str, | ||
"sql": 'SELECT * FROM "Orders" LIMIT 1', | ||
}, | ||
) | ||
assert response.status_code == 200 | ||
result = response.json() | ||
assert len(result["columns"]) == len(manifest["models"][0]["columns"]) | ||
assert len(result["data"]) == 1 | ||
assert result["data"][0][0] == 1 | ||
assert result["dtypes"] is not None | ||
|
||
|
||
def _to_connection_info(oracle: OracleDbContainer): | ||
# We can't use oracle.user, oracle.password, oracle.dbname here | ||
# since these values are None at this point | ||
return { | ||
"host": oracle.get_container_host_ip(), | ||
"port": oracle.get_exposed_port(oracle.port), | ||
"user": f"{oracle_user}", | ||
"password": f"{oracle_password}", | ||
"database": f"{oracle_database}", | ||
} | ||
|
||
|
||
def _to_connection_url(oracle: OracleDbContainer): | ||
info = _to_connection_info(oracle) | ||
return f"oracle://{info['user']}:{info['password']}@{info['host']}:{info['port']}/{info['database']}" |
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.