Fixed MSSQL Source (#3877)

Fixed MSSQL Source (#3877)
This commit is contained in:
Mayur Singal 2022-04-06 17:51:46 +05:30 committed by GitHub
parent 4e55ea0154
commit b709a8055e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 46 deletions

View File

@ -28,7 +28,7 @@
"scheme": { "scheme": {
"description": "SQLAlchemy driver scheme options.", "description": "SQLAlchemy driver scheme options.",
"$ref": "#/definitions/mssqlScheme", "$ref": "#/definitions/mssqlScheme",
"default": "mssql+pyodbc" "default": "mssql+pytds"
}, },
"username": { "username": {
"description": "username to connect to the MsSQL. This user should have privileges to read all the metadata in MsSQL.", "description": "username to connect to the MsSQL. This user should have privileges to read all the metadata in MsSQL.",
@ -47,6 +47,10 @@
"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 MsSQL.", "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 MsSQL.",
"type": "string" "type": "string"
}, },
"uriString": {
"description": "Connection URI In case of pyodbc",
"type": "string"
},
"connectionOptions": { "connectionOptions": {
"$ref": "connectionBasicType.json#/definitions/connectionOptions" "$ref": "connectionBasicType.json#/definitions/connectionOptions"
}, },

View File

@ -7,5 +7,5 @@ Provides metadata version information.
from incremental import Version from incremental import Version
__version__ = Version("metadata", 0, 9, 0, dev=10) __version__ = Version("metadata", 0, 9, 0, dev=11)
__all__ = ["__version__"] __all__ = ["__version__"]

View File

@ -1,15 +1,20 @@
{ {
"source": { "source": {
"type": "mssql", "type": "mssql",
"serviceName": "local_mssql",
"serviceConnection": {
"config": { "config": {
"host_port": "localhost:1433", "type": "MSSQL",
"service_name": "local_mssql",
"database": "catalog_test", "database": "catalog_test",
"query": "select top 50 * from [{}].[{}]",
"username": "sa", "username": "sa",
"password": "test!Password", "password": "test!Password",
"table_filter_pattern": { "hostPort": "localhost:1433"
"excludes": ["catalog_test.*"] }
},
"sourceConfig": {
"config": {
"enableDataProfiler": false,
"sampleDataQuery": "select top 50 * from [{}].[{}]"
} }
} }
}, },
@ -17,11 +22,10 @@
"type": "metadata-rest", "type": "metadata-rest",
"config": {} "config": {}
}, },
"metadata_server": { "workflowConfig": {
"type": "metadata-server", "openMetadataServerConfig": {
"config": { "hostPort": "http://localhost:8585/api",
"api_endpoint": "http://localhost:8585/api", "authProvider": "no-auth"
"auth_provider_type": "no-auth"
} }
} }
} }

View File

@ -9,7 +9,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
"""MSSQL source module""" """MSSQL source module"""
from typing import Optional
from metadata.generated.schema.entity.services.connections.database.mssqlConnection import ( from metadata.generated.schema.entity.services.connections.database.mssqlConnection import (
MssqlConnection, MssqlConnection,
@ -17,25 +16,11 @@ from metadata.generated.schema.entity.services.connections.database.mssqlConnect
from metadata.generated.schema.metadataIngestion.workflow import ( from metadata.generated.schema.metadataIngestion.workflow import (
OpenMetadataServerConfig, OpenMetadataServerConfig,
) )
from metadata.generated.schema.metadataIngestion.workflow import (
Source as WorkflowSource,
)
from metadata.ingestion.api.source import InvalidSourceException
from metadata.ingestion.source.sql_source import SQLSource from metadata.ingestion.source.sql_source import SQLSource
from metadata.ingestion.source.sql_source_common import SQLConnectionConfig
class MssqlConfig(MssqlConnection, SQLConnectionConfig):
"""MSSQL config -- extends SQLConnectionConfig class"""
use_pymssql: bool = False
use_pyodbc: bool = False
uri_string: str = ""
duration: Optional[int]
def get_connection_url(self):
if self.use_pyodbc:
self.scheme = self.scheme.mssql_pymssql
return f"{self.scheme}://{self.uri_string}"
if self.use_pymssql:
self.scheme = "mssql+pymssql"
return super().get_connection_url()
class MssqlSource(SQLSource): class MssqlSource(SQLSource):
@ -50,5 +35,10 @@ class MssqlSource(SQLSource):
@classmethod @classmethod
def create(cls, config_dict, metadata_config: OpenMetadataServerConfig): def create(cls, config_dict, metadata_config: OpenMetadataServerConfig):
"""Create class instance""" """Create class instance"""
config = MssqlConfig.parse_obj(config_dict) config: WorkflowSource = WorkflowSource.parse_obj(config_dict)
connection: MssqlConnection = config.serviceConnection.__root__.config
if not isinstance(connection, MssqlConnection):
raise InvalidSourceException(
f"Expected MssqlConnection, but got {connection}"
)
return cls(config, metadata_config) return cls(config, metadata_config)

View File

@ -217,6 +217,8 @@ class SQLSource(Source[OMetaDatabaseAndTable]):
): ):
self.status.filter(schema, "Schema pattern not allowed") self.status.filter(schema, "Schema pattern not allowed")
continue continue
# Fetch tables by default
yield from self.fetch_tables(inspector, schema)
if self.source_config.includeViews: if self.source_config.includeViews:
yield from self.fetch_views(inspector, schema) yield from self.fetch_views(inspector, schema)
if self.source_config.markDeletedTables: if self.source_config.markDeletedTables:

View File

@ -14,6 +14,9 @@ Hosts the singledispatch to build source URLs
from functools import singledispatch from functools import singledispatch
from urllib.parse import quote_plus from urllib.parse import quote_plus
from metadata.generated.schema.entity.services.connections.database.mssqlConnection import (
MssqlConnection,
)
from metadata.generated.schema.entity.services.connections.database.mysqlConnection import ( from metadata.generated.schema.entity.services.connections.database.mysqlConnection import (
MysqlConnection, MysqlConnection,
) )
@ -22,16 +25,7 @@ from metadata.generated.schema.entity.services.connections.database.sqliteConnec
) )
@singledispatch def get_connection_url_common(connection):
def get_connection_url(connection):
raise NotImplemented(
f"Connection URL build not implemented for type {type(connection)}: {connection}"
)
@get_connection_url.register
def _(connection: MysqlConnection):
url = f"{connection.scheme.value}://" url = f"{connection.scheme.value}://"
if connection.username: if connection.username:
@ -58,6 +52,25 @@ def _(connection: MysqlConnection):
return url return url
@singledispatch
def get_connection_url(connection):
raise NotImplemented(
f"Connection URL build not implemented for type {type(connection)}: {connection}"
)
@get_connection_url.register
def _(connection: MysqlConnection):
return get_connection_url_common(connection)
@get_connection_url.register
def _(connection: MssqlConnection):
if connection.scheme.value == connection.scheme.mssql_pyodbc:
return f"{connection.scheme.value}://{connection.uriString}"
return get_connection_url_common(connection)
@get_connection_url.register @get_connection_url.register
def _(connection: SQLiteConnection): def _(connection: SQLiteConnection):
""" """