mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2026-01-06 04:26:57 +00:00
Oracle fix (#3984)
* Oracle fix * Oracle added json refactoring * Fixed Oracle * Oracle json modified * Oracle modified
This commit is contained in:
parent
aa6a3fa8c4
commit
d7248cd5b9
@ -47,6 +47,11 @@
|
||||
"description": "Database of the data source. This is optional parameter, if you would like to restrict the metadata reading to a single database. When left blank , OpenMetadata Ingestion attempts to scan all the databases in Oracle.",
|
||||
"type": "string"
|
||||
},
|
||||
"oracleServiceName": {
|
||||
"description": "Oracle Service Name to be passed. Note: either Database or Oracle service name can be sent, not both.",
|
||||
"type": "string",
|
||||
"default": null
|
||||
},
|
||||
"connectionOptions": {
|
||||
"$ref": "connectionBasicType.json#/definitions/connectionOptions"
|
||||
},
|
||||
|
||||
@ -1,25 +1,27 @@
|
||||
{
|
||||
"source": {
|
||||
"type": "oracle",
|
||||
"source": {
|
||||
"type": "oracle",
|
||||
"serviceName": "local_oracle",
|
||||
"serviceConnection": {
|
||||
"config": {
|
||||
"host_port":"host:1521",
|
||||
"username": "pdbadmin",
|
||||
"hostPort": "hostPort",
|
||||
"username": "username",
|
||||
"password": "password",
|
||||
"service_name": "local_oracle",
|
||||
"service_type": "Oracle",
|
||||
"oracle_service_name": "ORCLPDB1"
|
||||
}
|
||||
},
|
||||
"sink": {
|
||||
"type": "metadata-rest",
|
||||
"config": {
|
||||
}
|
||||
},
|
||||
"metadata_server": {
|
||||
"type": "metadata-server",
|
||||
"config": {
|
||||
"api_endpoint": "http://localhost:8585/api",
|
||||
"auth_provider_type": "no-auth"
|
||||
"type": "Oracle",
|
||||
"oracleServiceName":"TESTDB"
|
||||
}
|
||||
},"sourceConfig":{
|
||||
"config":{}
|
||||
}
|
||||
},
|
||||
"sink": {
|
||||
"type": "metadata-rest",
|
||||
"config": {}
|
||||
},
|
||||
"workflowConfig": {
|
||||
"openMetadataServerConfig": {
|
||||
"hostPort": "http://localhost:8585/api",
|
||||
"authProvider": "no-auth"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,47 +10,50 @@
|
||||
# limitations under the License.
|
||||
|
||||
# This import verifies that the dependencies are available.
|
||||
from typing import Optional
|
||||
|
||||
import cx_Oracle # noqa: F401
|
||||
import pydantic
|
||||
|
||||
from metadata.generated.schema.entity.data.database import Database
|
||||
from metadata.generated.schema.entity.services.connections.database.oracleConnection import (
|
||||
OracleConnection,
|
||||
)
|
||||
from metadata.generated.schema.metadataIngestion.workflow import (
|
||||
OpenMetadataServerConfig,
|
||||
)
|
||||
from metadata.generated.schema.metadataIngestion.workflow import (
|
||||
Source as WorkflowSource,
|
||||
)
|
||||
from metadata.generated.schema.type.entityReference import EntityReference
|
||||
from metadata.ingestion.api.source import InvalidSourceException
|
||||
from metadata.ingestion.source.sql_source import SQLSource
|
||||
from metadata.ingestion.source.sql_source_common import SQLConnectionConfig
|
||||
|
||||
|
||||
class OracleConfig(OracleConnection, SQLConnectionConfig):
|
||||
# defaults
|
||||
oracle_service_name: Optional[str] = None
|
||||
query: Optional[str] = "select * from {}.{} where ROWNUM <= 50"
|
||||
|
||||
@pydantic.validator("oracle_service_name")
|
||||
def check_oracle_service_name(cls, v, values):
|
||||
if values.get("database") and v:
|
||||
raise ValueError(
|
||||
"Please provide database or oracle_service_name but not both"
|
||||
)
|
||||
return v
|
||||
|
||||
def get_connection_url(self):
|
||||
url = super().get_connection_url()
|
||||
if self.oracle_service_name:
|
||||
assert not self.database
|
||||
url = f"{url}service_name={self.oracle_service_name}"
|
||||
return url
|
||||
|
||||
|
||||
class OracleSource(SQLSource):
|
||||
def __init__(self, config, metadata_config):
|
||||
super().__init__(config, metadata_config)
|
||||
|
||||
@classmethod
|
||||
def create(cls, config_dict, metadata_config: OpenMetadataServerConfig):
|
||||
config = OracleConfig.parse_obj(config_dict)
|
||||
config = WorkflowSource.parse_obj(config_dict)
|
||||
connection: OracleConnection = config.serviceConnection.__root__.config
|
||||
if not isinstance(connection, OracleConnection):
|
||||
raise InvalidSourceException(
|
||||
f"Expected OracleConnection, but got {connection}"
|
||||
)
|
||||
if config.sourceConfig.config.sampleDataQuery == "select * from {}.{} limit 50":
|
||||
config.sourceConfig.config.sampleDataQuery = (
|
||||
"select * from {}.{} where ROWNUM <= 50"
|
||||
)
|
||||
return cls(config, metadata_config)
|
||||
|
||||
def _get_database(self, database: str) -> Database:
|
||||
if not database:
|
||||
database = self.service_connection.oracleServiceName
|
||||
return Database(
|
||||
name=database,
|
||||
service=EntityReference(
|
||||
id=self.service.id, type=self.service_connection.type.value
|
||||
),
|
||||
)
|
||||
|
||||
@ -546,6 +546,8 @@ class SQLSource(Source[OMetaDatabaseAndTable]):
|
||||
return columns
|
||||
|
||||
def _get_database(self, database: str) -> Database:
|
||||
if not database:
|
||||
database = "default"
|
||||
return Database(
|
||||
name=database,
|
||||
service=EntityReference(
|
||||
|
||||
@ -28,12 +28,18 @@ from metadata.generated.schema.entity.services.connections.database.db2Connectio
|
||||
from metadata.generated.schema.entity.services.connections.database.hiveConnection import (
|
||||
HiveSQLConnection,
|
||||
)
|
||||
from metadata.generated.schema.entity.services.connections.database.mariaDBConnection import (
|
||||
MariaDBConnection,
|
||||
)
|
||||
from metadata.generated.schema.entity.services.connections.database.mssqlConnection import (
|
||||
MssqlConnection,
|
||||
)
|
||||
from metadata.generated.schema.entity.services.connections.database.mysqlConnection import (
|
||||
MysqlConnection,
|
||||
)
|
||||
from metadata.generated.schema.entity.services.connections.database.oracleConnection import (
|
||||
OracleConnection,
|
||||
)
|
||||
from metadata.generated.schema.entity.services.connections.database.postgresConnection import (
|
||||
PostgresConnection,
|
||||
)
|
||||
@ -93,6 +99,7 @@ def get_connection_url(connection):
|
||||
)
|
||||
|
||||
|
||||
@get_connection_url.register(MariaDBConnection)
|
||||
@get_connection_url.register(PostgresConnection)
|
||||
@get_connection_url.register(RedshiftConnection)
|
||||
@get_connection_url.register(MysqlConnection)
|
||||
@ -112,6 +119,15 @@ def _(connection: MssqlConnection):
|
||||
return get_connection_url_common(connection)
|
||||
|
||||
|
||||
@get_connection_url.register
|
||||
def _(connection: OracleConnection):
|
||||
url = get_connection_url_common(connection)
|
||||
if connection.oracleServiceName:
|
||||
assert not connection.database
|
||||
url = f"{url}/?service_name={connection.oracleServiceName}"
|
||||
return url
|
||||
|
||||
|
||||
@get_connection_url.register
|
||||
def _(connection: SQLiteConnection):
|
||||
"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user