Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow list and tuples as columns names in Append & Merge #450

Merged
merged 1 commit into from
Jun 17, 2022

Conversation

kaxil
Copy link
Collaborator

@kaxil kaxil commented Jun 10, 2022

addresses #439 (comment)

Tt feels tedious and probably most of the times the col names would be the same. This commit renames source_to_target_columns_map param in Append and Merge operator to columns and allows passing either a) list or tuples containing col names b) dict containing source to target mapping.

Before:

append(
    source_table=filtered_data,
    target_table=Table(name="homes_reporting", conn_id=SNOWFLAKE_CONN_ID),
    source_to_target_columns_map={
        "sell": "sell",
        "list": "list",
        "variable": "variable",
        "value": "value",
    },
)

After:

append(
    source_table=filtered_data,
    target_table=Table(name="homes_reporting", conn_id=SNOWFLAKE_CONN_ID),
    columns=["sell", "list", "variable", "value"]
)

ToDo:

  • Add unit tests for passing different types and verify that it is converted to dict
  • Probably a separate task to update docs and add a task in example DAGs with one of list and dict as col names before we release 0.10.0 - Update docs for append & merge for 0.10.0 #466

@kaxil kaxil added this to the 0.10.0 milestone Jun 10, 2022
@codecov
Copy link

codecov bot commented Jun 10, 2022

Codecov Report

Merging #450 (82ae3fe) into main (378fd82) will increase coverage by 0.06%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #450      +/-   ##
==========================================
+ Coverage   90.97%   91.04%   +0.06%     
==========================================
  Files          41       41              
  Lines        1319     1329      +10     
  Branches      168      172       +4     
==========================================
+ Hits         1200     1210      +10     
  Misses         99       99              
  Partials       20       20              
Impacted Files Coverage Δ
src/astro/sql/__init__.py 91.42% <100.00%> (ø)
src/astro/sql/operators/append.py 100.00% <100.00%> (ø)
src/astro/sql/operators/merge.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 378fd82...82ae3fe. Read the comment docs.

@tatiana tatiana added improvement Enhancement or improvement in an existing feature and removed improvement Enhancement or improvement in an existing feature labels Jun 13, 2022
addresses #439 (comment)

Tt feels tedious and probably most of the times the col names would be the same. This commit renames `source_to_target_columns_map` param in Append and Merge operator to `columns` and allows passing either a) list or tuples containing col names b) dict containing source to target mapping.

Before:

```python
append(
        source_table=filtered_data,
        target_table=Table(name="homes_reporting", conn_id=SNOWFLAKE_CONN_ID),
        source_to_target_columns_map={
            "sell": "sell",
            "list": "list",
            "variable": "variable",
            "value": "value",
        },
    )
```

After:

```python
append(
        source_table=filtered_data,
        target_table=Table(name="homes_reporting", conn_id=SNOWFLAKE_CONN_ID),
        columns=["sell", "list", "variable", "value"]
    )
```
task_id: str = "",
**kwargs: Any,
) -> None:
self.source_table = source_table
self.target_table = target_table
self.source_to_target_columns_map = source_to_target_columns_map or {}

if isinstance(columns, (list, tuple)):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @kaxil, nothing major, but can we move lines 36 - 41 to a function and use that function in the append and merge operators just to avoid some code duplication?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, DAMP (“Descriptive and Meaningful Phrases”) approach is better than DRY (“Don’t Repeat Yourself”) as they are hardly 4-5 lines :)

Copy link
Contributor

@sunank200 sunank200 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kaxil kaxil merged commit 4a13cb6 into main Jun 17, 2022
@kaxil kaxil deleted the allow-list-tuple branch June 17, 2022 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants