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

[pkg/ottl] Add rename function #31769

Closed

Conversation

aleksmaus
Copy link
Contributor

@aleksmaus aleksmaus commented Mar 14, 2024

Description:

Add alternative function to avoid double step rename(map, field, target_field, [Optional] ignore_missing = true, [Optional] conflict_strategy = upsert)

rename(target, source_map, source_key, 
    [Optional] ignore_missing = true, [Optional] conflict_strategy = upsert)

Related to [pkg/ottl] Add rename function

Documentation:
The rename function documentation block in readme.

Testing:
Unit tests.

Manual testing with transform, example:

processors:
  transform:
    error_mode: ignore
    log_statements:
      - context: log
        statements: 
          - rename(attributes, "session", "newsession")

Add alternative function to avoid double step rename(map, field, target_field, [Optional] ignore_missing = true, [Optional] conflict_strategy = replace)
@aleksmaus aleksmaus requested a review from a team March 14, 2024 19:48
Copy link

linux-foundation-easycla bot commented Mar 14, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@TylerHelmuth
Copy link
Member

@aleksmaus please open an issue for us to discuss the problem this PR solves.

@aleksmaus
Copy link
Contributor Author

@aleksmaus please open an issue for us to discuss the problem this PR solves.

Thank you for the prompt response. Will open an issue over the weekend. Need to think more about all the use cases, think I might be not covering one or two with the current implementation.

@aleksmaus
Copy link
Contributor Author

Reverted the latest changes back to to the initial rename function implementation, updated README.md

rename

rename(map, field, targetField, Optional[ignore_missing], Optional[conflict_strategy] )

The rename function renames the map field to targetField.

map is a path expression to a pcommon.Map type field. field is a string value of the map key that is being renamed. targetField is a string value that the field is renamed to.

This combines what previously required two calls of set following with delete_key in one function call.

How the rename function behaves is controlled by the optional ignore_missing and conflict_strategy arguments.

ignore_missing is optional boolean argument, that specifies what happens when the field is missing from the map. It is set to true by default.

  • The true value results in no changes to the map if the field key doesn't exists in the map
  • The false value results in error if the field key doesn't exists in the map

conflict_strategy is an optional string paramater that specifies the conflict resolution strategy for the targetField.
Valid values are upsert, fail, and insert. By default, it is set to upsert.

  • The upsert overwrites the targetField if it is already present.
  • The fail returns an error if targetField is already present, otherwise creates new field.
  • The insert results in no changes to the map if targetField is already present.

Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Apr 16, 2024
Copy link
Contributor

github-actions bot commented May 1, 2024

Closed as inactive. Feel free to reopen if this PR is still being worked on.

@github-actions github-actions bot closed this May 1, 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.

3 participants