forked from mage-ai/mage-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[td] Support MySQL in dbt (mage-ai#1809)
* [td] 0.7.75 * [td] Add dbt mysql support * [td] undo version change * done
- Loading branch information
1 parent
7ec589b
commit 324c3dd
Showing
17 changed files
with
580 additions
and
231 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from mage_ai.data_preparation.models.constants import BlockType | ||
from mage_ai.data_preparation.variable_manager import get_variable | ||
from mage_ai.data_preparation.models.block.sql.utils.shared import ( | ||
interpolate_input, | ||
should_cache_data_from_upstream, | ||
) | ||
from mage_ai.io.config import ConfigKey | ||
from typing import Dict | ||
|
||
|
||
def create_upstream_block_tables( | ||
loader, | ||
block, | ||
cascade_on_drop: bool = False, | ||
configuration: Dict = None, | ||
execution_partition: str = None, | ||
cache_upstream_dbt_models: bool = False, | ||
): | ||
from mage_ai.data_preparation.models.block.dbt.utils import ( | ||
parse_attributes, | ||
source_table_name_for_block, | ||
) | ||
configuration = configuration if configuration else block.configuration | ||
|
||
for idx, upstream_block in enumerate(block.upstream_blocks): | ||
if should_cache_data_from_upstream(block, upstream_block, [ | ||
'data_provider', | ||
], [ | ||
ConfigKey.MYSQL_DATABASE, | ||
ConfigKey.MYSQL_HOST, | ||
ConfigKey.MYSQL_PORT, | ||
]): | ||
if BlockType.DBT == upstream_block.type and not cache_upstream_dbt_models: | ||
continue | ||
|
||
table_name = upstream_block.table_name | ||
|
||
df = get_variable( | ||
upstream_block.pipeline.uuid, | ||
upstream_block.uuid, | ||
'output_0', | ||
partition=execution_partition, | ||
) | ||
|
||
if BlockType.DBT == block.type and BlockType.DBT != upstream_block.type: | ||
table_name = source_table_name_for_block(upstream_block) | ||
|
||
loader.export( | ||
df, | ||
None, | ||
table_name, | ||
cascade_on_drop=cascade_on_drop, | ||
drop_table_on_replace=True, | ||
if_exists='replace', | ||
index=False, | ||
verbose=False, | ||
) | ||
|
||
|
||
def interpolate_input_data(block, query): | ||
return interpolate_input( | ||
block, | ||
query, | ||
lambda db, schema, tn: tn, | ||
) |
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
Oops, something went wrong.