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

New functions STR_SUBSTRING_AFTER and STR_SUBSTRING_BEFORE #513

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

Conversation

oswaldobapvicjr
Copy link
Contributor

This push introduces new string functions:

  • STR_SUBSTRING_AFTER(string, separator)
  • STR_SUBSTRING_BEFORE(string, separator)

Examples:

  • STR_SUBSTRING_AFTER("file.json", ".")
    • returns "json"
  • STR_SUBSTRING_BEFORE("2024/10/23", "/")
    • returns "2024"

Copy link

sonarcloud bot commented Oct 24, 2024

@oswaldobapvicjr oswaldobapvicjr changed the title New functions STR_SUBSTRING_AFTER/BEFORE New functions STR_SUBSTRING_AFTER and STR_SUBSTRING_BEFORE Oct 24, 2024
@uklimaschewski
Copy link
Collaborator

Why not defining a single method STR_SPLIT(string, separator)? It could return an array of strings (similar to String.split(String regex)).

Using STR_SPLIT("file.json", ".")[1] would return "json".
Using STR_SPLIT("2024/10/23", "/")[0] would return "2024".

You would even have much more possibilities.

I am just unsure of using a regex or just a simple string as separator is better.

@oswaldobapvicjr
Copy link
Contributor Author

oswaldobapvicjr commented Nov 19, 2024

@uklimaschewski, the functions STR_SUBSTRING_AFTER and STR_SUBSTRING_BEFORE were inspired by those provided by leading tools such as XPath (W3C), Microsoft Excel, and MuleSoft by Salesforce so I wonder it could be good here too, for simplicity and assimilation. However, I agree that the same result could be obtained using STR_SPLIT.

Regarding the doubt whether to use a regex or a separator, why not implement both? ;)

  • STR_SPLIT("file.json", ".") would return "json" (simple and direct for everyone)
  • STR_SPLIT_REGEX("file.json", "\\.") would also return "json", but since it's regex-based, it offers more possibilities for users that are familiar with regex.

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.

2 participants