replaceAll functionality in UDF does not work for forwardslash #17672
Unanswered
natarajank11
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
trino 407:
`
public static Slice rmesc(@SqlType(StandardTypes.VARCHAR) Slice string)
{
String text = string.toStringUtf8();
return Slices.utf8Slice(text.replaceAll("(\\,)", ",").replaceAll("(\\\\)", "\"));
}
`
The above UDF does not produce the expected value.
trino> select rmesc('\\,'); => \,
trino> select rmesc('\\\\'); => failed: character to be escaped is missing
I tried to reproduce with replace function instead of replaceAll, it works fine as per expectation.
return Slices.utf8Slice(text.replace("\\\\,", ",").replace("\\\\\\\\", "\\"));
This produces correct output,
trino> select rmesc('\\,'); => ,
trino> select rmesc('\\\\'); => \
Beta Was this translation helpful? Give feedback.
All reactions