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 function STR_SPLIT #513

Merged
merged 3 commits into from
Feb 16, 2025
Merged

New function STR_SPLIT #513

merged 3 commits into from
Feb 16, 2025

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"

@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.

@uklimaschewski
Copy link
Collaborator

Sorry for the late answer, this fell totally off my table.
I think having a STR_SPLIT and STR_SPLIT_REGEXis a good idea. I'd prefer these instead of having STR_SUBSTRING_AFTERand STR_SUBSTRING_BEFORE.

If you modify your PR accordingly, or open a new one I'd be happy to merge it.

@oswaldobapvicjr oswaldobapvicjr changed the title New functions STR_SUBSTRING_AFTER and STR_SUBSTRING_BEFORE New function STR_SPLIT Feb 16, 2025
@oswaldobapvicjr
Copy link
Contributor Author

I've just implemented the function STR_SPLIT(string, separator) but I'm now unsure about the need for a 2nd function (STR_SPLIT_REGEX), so I wonder if we may implement it in the future if we find a good use case for it. What do you think?

@uklimaschewski uklimaschewski merged commit e5caee3 into ezylang:main Feb 16, 2025
3 checks passed
@uklimaschewski
Copy link
Collaborator

Thank you very much! Adding the STR_SPLIT_REGEX function can be done anytime. I'll wait for a release a little while, mybe I or someone finds some time to add it - shouldn't be too much effort.

@oswaldobapvicjr oswaldobapvicjr deleted the pr-12 branch February 16, 2025 12:12
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