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

feat(mappers): Stream name can now be accessed in __alias__ context of stream maps #2701

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

holly-evans
Copy link

@holly-evans holly-evans commented Oct 3, 2024

Description

Allow users to reference the stream name in stream maps alias fields, under a special key:

{
    "stream_maps": {
        "*": {
            "__alias__": "'raw_' + __stream_name__"
        },
}

Related


📚 Documentation preview 📚: https://meltano-sdk--2701.org.readthedocs.build/en/2701/

Copy link

codspeed-hq bot commented Oct 3, 2024

CodSpeed Performance Report

Merging #2701 will not alter performance

Comparing holly-evans:issue-2283-use-stream-name-in-alias (40ffd19) with main (9bf104e)

Summary

✅ 6 untouched benchmarks

Copy link

codecov bot commented Oct 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.50%. Comparing base (9bf104e) to head (40ffd19).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2701   +/-   ##
=======================================
  Coverage   90.50%   90.50%           
=======================================
  Files          62       62           
  Lines        4994     4994           
  Branches      974      974           
=======================================
  Hits         4520     4520           
  Misses        328      328           
  Partials      146      146           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 856 to 862
except simpleeval.NameNotDefined:
logging.debug(
"Failed to evaluate simpleeval expression %(expr) - "
"falling back to original expression",
extra={"expr": expr},
)
result: str = expr
Copy link
Author

@holly-evans holly-evans Oct 3, 2024

Choose a reason for hiding this comment

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

I am swallowing NameNotDefined errors here to support existing __alias__ configurations. Since __alias__ was not previously evaluated, it contains plain strings - which the evaluator tries to read as python objects.

For instance, { "__alias__": "aliased_stream" } will produce NameNotDefined. It would need single quotes to avoid this, like { "__alias__": "'aliased_stream'" }, which is a breaking change. Instead I'm just passing the expression as a string in these cases.

Please let me know what you think

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this makes sense. Thanks for being mindful of breaking changes 🙂

@edgarrmondragon edgarrmondragon self-assigned this Oct 3, 2024
Copy link
Collaborator

@edgarrmondragon edgarrmondragon left a comment

Choose a reason for hiding this comment

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

This looks great, thanks @holly-evans!

singer_sdk/mapper.py Outdated Show resolved Hide resolved
Co-authored-by: Edgar Ramírez Mondragón <16805946+edgarrmondragon@users.noreply.github.com>
@edgarrmondragon edgarrmondragon changed the title feat(mappers): Access stream name in alias feat(mappers): Stream name can now be accessed in __alias__ context of stream maps Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Access stream name in __alias__
2 participants