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.
[dy] Add sensor templates for sql databases (mage-ai#2219)
* [dy] Add mysql * [dy] Formatting
- Loading branch information
Showing
8 changed files
with
177 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from mage_ai.data_preparation.repo_manager import get_repo_path | ||
from mage_ai.io.bigquery import BigQuery | ||
from mage_ai.io.config import ConfigFileLoader | ||
from os import path | ||
|
||
if 'sensor' not in globals(): | ||
from mage_ai.data_preparation.decorators import sensor | ||
|
||
|
||
@sensor | ||
def query_bigquery_and_check_condition(**kwargs) -> bool: | ||
""" | ||
Template code for checking the results of a BigQuery query. | ||
Specify your configuration settings in 'io_config.yaml'. | ||
Return: True if the sensor should complete, False if it should | ||
keep waiting | ||
""" | ||
|
||
config_path = path.join(get_repo_path(), 'io_config.yaml') | ||
config_profile = 'default' | ||
|
||
query = 'Your BigQuery query' # Specify your SQL query here | ||
|
||
loader = BigQuery.with_config(ConfigFileLoader(config_path, config_profile)) | ||
df = loader.load(query) | ||
|
||
# Add your checks here | ||
if df.empty: | ||
return False | ||
|
||
return True |
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,33 @@ | ||
from mage_ai.data_preparation.repo_manager import get_repo_path | ||
from mage_ai.io.config import ConfigFileLoader | ||
from mage_ai.io.mysql import MySQL | ||
from os import path | ||
|
||
if 'sensor' not in globals(): | ||
from mage_ai.data_preparation.decorators import sensor | ||
|
||
|
||
@sensor | ||
def query_mysql_and_check_condition(**kwargs) -> bool: | ||
""" | ||
Template code for checking the results of a MySQL query. | ||
Specify your configuration settings in 'io_config.yaml'. | ||
Return: True if the sensor should complete, False if it should | ||
keep waiting | ||
""" | ||
|
||
config_path = path.join(get_repo_path(), 'io_config.yaml') | ||
config_profile = 'default' | ||
|
||
query = 'Your MySQL query' # Specify your SQL query here | ||
|
||
with MySQL.with_config( | ||
ConfigFileLoader(config_path, config_profile)) as loader: | ||
df = loader.load(query) | ||
|
||
# Add your checks here | ||
if df.empty: | ||
return False | ||
|
||
return True |
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,33 @@ | ||
from mage_ai.data_preparation.repo_manager import get_repo_path | ||
from mage_ai.io.config import ConfigFileLoader | ||
from mage_ai.io.postgres import Postgres | ||
from os import path | ||
|
||
if 'sensor' not in globals(): | ||
from mage_ai.data_preparation.decorators import sensor | ||
|
||
|
||
@sensor | ||
def query_postgres_and_check_condition(**kwargs) -> bool: | ||
""" | ||
Template code for checking the results of a Postgres query. | ||
Specify your configuration settings in 'io_config.yaml'. | ||
Return: True if the sensor should complete, False if it should | ||
keep waiting | ||
""" | ||
|
||
config_path = path.join(get_repo_path(), 'io_config.yaml') | ||
config_profile = 'default' | ||
|
||
query = 'Your Postgres query' # Specify your SQL query here | ||
|
||
with Postgres.with_config( | ||
ConfigFileLoader(config_path, config_profile)) as loader: | ||
df = loader.load(query) | ||
|
||
# Add your checks here | ||
if df.empty: | ||
return False | ||
|
||
return True |
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,33 @@ | ||
from mage_ai.data_preparation.repo_manager import get_repo_path | ||
from mage_ai.io.config import ConfigFileLoader | ||
from mage_ai.io.redshift import Redshift | ||
from os import path | ||
|
||
if 'sensor' not in globals(): | ||
from mage_ai.data_preparation.decorators import sensor | ||
|
||
|
||
@sensor | ||
def query_redshift_and_check_condition(**kwargs) -> bool: | ||
""" | ||
Template code for checking the results of a Redshift query. | ||
Specify your configuration settings in 'io_config.yaml'. | ||
Return: True if the sensor should complete, False if it should | ||
keep waiting | ||
""" | ||
|
||
config_path = path.join(get_repo_path(), 'io_config.yaml') | ||
config_profile = 'default' | ||
|
||
query = 'Your Redshift query' # Specify your SQL query here | ||
|
||
with Redshift.with_config( | ||
ConfigFileLoader(config_path, config_profile)) as loader: | ||
df = loader.load(query) | ||
|
||
# Add your checks here | ||
if df.empty: | ||
return False | ||
|
||
return True |
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,33 @@ | ||
from mage_ai.data_preparation.repo_manager import get_repo_path | ||
from mage_ai.io.config import ConfigFileLoader | ||
from mage_ai.io.snowflake import Snowflake | ||
from os import path | ||
|
||
if 'sensor' not in globals(): | ||
from mage_ai.data_preparation.decorators import sensor | ||
|
||
|
||
@sensor | ||
def query_snowflake_and_check_condition(**kwargs) -> bool: | ||
""" | ||
Template code for checking the results of a Snowflake query. | ||
Specify your configuration settings in 'io_config.yaml'. | ||
Return: True if the sensor should complete, False if it should | ||
keep waiting | ||
""" | ||
|
||
config_path = path.join(get_repo_path(), 'io_config.yaml') | ||
config_profile = 'default' | ||
|
||
query = 'Your Snowflake query' # Specify your SQL query here | ||
|
||
with Snowflake.with_config( | ||
ConfigFileLoader(config_path, config_profile)) as loader: | ||
df = loader.load(query) | ||
|
||
# Add your checks here | ||
if df.empty: | ||
return False | ||
|
||
return True |
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