-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MINOR: Mysql Lineage Support Main (#18780)
* MINOR: Mysql Lineage Support Main * fix test * fix test --------- Co-authored-by: Teddy <teddy.crepineau@gmail.com>
- Loading branch information
Showing
15 changed files
with
258 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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 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
43 changes: 43 additions & 0 deletions
43
ingestion/src/metadata/ingestion/source/database/mysql/queries.py
This file contains 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,43 @@ | ||
# Copyright 2021 Collate | ||
# Licensed 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. | ||
""" | ||
SQL Queries used during ingestion | ||
""" | ||
import textwrap | ||
|
||
MYSQL_SQL_STATEMENT = textwrap.dedent( | ||
""" | ||
SELECT | ||
NULL `database_name`, | ||
argument `query_text`, | ||
event_time `start_time`, | ||
NULL `end_time`, | ||
NULL `duration`, | ||
NULL `schema_name`, | ||
NULL `query_type`, | ||
NULL `user_name`, | ||
NULL `aborted` | ||
FROM mysql.general_log | ||
WHERE command_type = 'Query' | ||
AND event_time between '{start_time}' and '{end_time}' | ||
AND argument NOT LIKE '/* {{"app": "OpenMetadata", %%}} */%%' | ||
AND argument NOT LIKE '/* {{"app": "dbt", %%}} */%%' | ||
{filters} | ||
ORDER BY event_time desc | ||
LIMIT {result_limit}; | ||
""" | ||
) | ||
|
||
MYSQL_TEST_GET_QUERIES = textwrap.dedent( | ||
""" | ||
SELECT `argument` from mysql.general_log limit 1; | ||
""" | ||
) |
46 changes: 46 additions & 0 deletions
46
ingestion/src/metadata/ingestion/source/database/mysql/query_parser.py
This file contains 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,46 @@ | ||
# Copyright 2021 Collate | ||
# Licensed 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. | ||
""" | ||
Mysql query parser module | ||
""" | ||
from abc import ABC | ||
from typing import Optional | ||
|
||
from metadata.generated.schema.entity.services.connections.database.mysqlConnection import ( | ||
MysqlConnection, | ||
) | ||
from metadata.generated.schema.metadataIngestion.workflow import ( | ||
Source as WorkflowSource, | ||
) | ||
from metadata.ingestion.api.steps import InvalidSourceException | ||
from metadata.ingestion.ometa.ometa_api import OpenMetadata | ||
from metadata.ingestion.source.database.query_parser_source import QueryParserSource | ||
|
||
|
||
class MysqlQueryParserSource(QueryParserSource, ABC): | ||
""" | ||
Mysql base for Usage and Lineage | ||
""" | ||
|
||
filters: str | ||
|
||
@classmethod | ||
def create( | ||
cls, config_dict, metadata: OpenMetadata, pipeline_name: Optional[str] = None | ||
): | ||
"""Create class instance""" | ||
config: WorkflowSource = WorkflowSource.model_validate(config_dict) | ||
connection: MysqlConnection = config.serviceConnection.root.config | ||
if not isinstance(connection, MysqlConnection): | ||
raise InvalidSourceException( | ||
f"Expected MysqlConnection, but got {connection}" | ||
) | ||
return cls(config, metadata) |
8 changes: 7 additions & 1 deletion
8
ingestion/src/metadata/ingestion/source/database/mysql/service_spec.py
This file contains 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 |
---|---|---|
@@ -1,4 +1,10 @@ | ||
from metadata.ingestion.source.database.mysql.lineage import MysqlLineageSource | ||
from metadata.ingestion.source.database.mysql.metadata import MysqlSource | ||
from metadata.ingestion.source.database.mysql.usage import MysqlUsageSource | ||
from metadata.utils.service_spec.default import DefaultDatabaseSpec | ||
|
||
ServiceSpec = DefaultDatabaseSpec(metadata_source_class=MysqlSource) | ||
ServiceSpec = DefaultDatabaseSpec( | ||
metadata_source_class=MysqlSource, | ||
lineage_source_class=MysqlLineageSource, | ||
usage_source_class=MysqlUsageSource, | ||
) |
24 changes: 24 additions & 0 deletions
24
ingestion/src/metadata/ingestion/source/database/mysql/usage.py
This file contains 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,24 @@ | ||
# Copyright 2021 Collate | ||
# Licensed 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. | ||
""" | ||
MYSQL usage module | ||
""" | ||
from metadata.ingestion.source.database.mysql.queries import MYSQL_SQL_STATEMENT | ||
from metadata.ingestion.source.database.mysql.query_parser import MysqlQueryParserSource | ||
from metadata.ingestion.source.database.usage_source import UsageSource | ||
|
||
|
||
class MysqlUsageSource(MysqlQueryParserSource, UsageSource): | ||
sql_stmt = MYSQL_SQL_STATEMENT | ||
filters = "" | ||
|
||
def format_query(self, query: bytes) -> str: | ||
return query.decode(errors="ignore").replace("\\n", "\n") |
This file contains 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 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 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 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 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 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 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 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 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