title: Assessing from the end of a split array in Hive
body: <p>I need to split a tag that looks something like "B1/AHU/_1/RoomTemp", "B1/AHU/_1/109/Temp", so with a variable with a variable number of fields. I am interested in getting the last field, or sometimes the last but one. I was disappointed to find that negative indexes do not count from the right and allow me to select the last element of an array in Hive as they do in Python. </p>
  
  <pre><code>select tag,split(tag,'[/]')[ -1] from sensor
  </code></pre>
  
  <p>I was more surprised when this did not work either:</p>
  
  <pre><code>select tag,split(tag,'[/]')[ size(split(tag,'[\]'))-1 ] from sensor
  </code></pre>
  
  <p>Both times giving me an error along the lines of this:</p>
  
  <pre><code>FAILED: SemanticException 1:27 Non-constant expressions for array indexes not supported. 
  Error encountered near token '1'
  </code></pre>
  
  <p>So any ideas? I am kind of new to Hive. Regex's maybe? Or is there some syntactic sugar I am not aware of?</p>