I want the position of '/' from the string where '/' has repeated multiple times and the length of the string varies.
In Apache drill, the INSTR() will not work to find the Nth occurrence of a character in a string. i.e INSTR('/This/looks/like/homework', '/',1,3) to get the output as 12, this query will not work in Apache drill.
I want the position of '/' on Nth Occurrence in Apache drill.
Please help me with the solution.
This is from drill-user mailing list. Hope it will help you: http://mail-archives.apache.org/mod_mbox/drill-user/201509.mbox/%3CB6A39848-AACB-4AD2-BD62-58C395D6CC9E@maprtech.com%3E
You can use POSTION, STRPOS or LOCATE also to find substring in a string and return the position.
LOCATE is the most useful IMO as it allows you to specify where to starter the search in the string, however none of these have the INSTR or substring-index ability to specify which occurrence of the substring to look for.
A good case for a UDF.
Below is a workaround with subqueries to break down an IP address in the different portions.
You can find all supported Drill string functions here: https://drill.apache.org/docs/string-manipulation/#strpos