I’m having a table x it contain the column resource_name
in this column I’m having data like NASRI(SRI).
I’m applying initcap on this column it’s giving output Nasri(sri)
. But my expected output is Nasri(Sri)
.
How I can achieve the desired result?
Thank you
Advertisement
Answer
One possible solution is to use split()
with concat_ws()
. If value does not contain ‘()’, then it will also work correctly. Demo with ():
hive> select concat_ws('(',initcap(split('NASRI(SRI)','\(')[0]), initcap(split('NASRI(SRI)','\(')[1]) ); OK Nasri(Sri) Time taken: 0.974 seconds, Fetched: 1 row(s)
And for value without () it also works good:
hive> select concat_ws('(',initcap(split('NASRI','\(')[0]), initcap(split('NASRI','\(')[1]) ); OK Nasri Time taken: 0.697 seconds, Fetched: 1 row(s)