-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQL database: included_columns option
- Loading branch information
Showing
6 changed files
with
138 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import sqlalchemy as sa | ||
import humanize | ||
from typing import Any | ||
import os | ||
|
||
import dlt | ||
from dlt.common import pendulum | ||
|
@@ -328,6 +329,29 @@ def type_adapter(sql_type: TypeEngine[Any]) -> TypeEngine[Any]: | |
print(info) | ||
|
||
|
||
def specify_columns_to_load() -> None: | ||
"""Run the SQL database source with a subset of table columns loaded""" | ||
pipeline = dlt.pipeline( | ||
pipeline_name="dummy", | ||
destination="postgres", | ||
dataset_name="dummy", | ||
) | ||
|
||
# Columns can be specified per table in env var (json array) or in `.dlt/config.toml` | ||
os.environ["SOURCES__SQL_DATABASE__FAMILY__INCLUDED_COLUMNS"] = ( | ||
'["rfam_acc", "description"]' | ||
) | ||
|
||
sql_alchemy_source = sql_database( | ||
"mysql+pymysql://[email protected]:4497/Rfam?&binary_prefix=true", | ||
backend="pyarrow", | ||
reflection_level="full_with_precision", | ||
).with_resources("family", "genome") | ||
|
||
info = pipeline.run(sql_alchemy_source) | ||
print(info) | ||
|
||
|
||
if __name__ == "__main__": | ||
# Load selected tables with different settings | ||
# load_select_tables_from_database() | ||
|
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