title: Average count of elements in a set in hive?
body: <p><a href="https://i.stack.imgur.com/UaWDQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UaWDQ.png" alt="enter image description here"></a></p>
  
  <p>I have two columns id and segment. Segment is comma separated set of strings. I need to find average number of segments in all the table. One way to do it is by using two separate queries -</p>
  
  <pre><code>A - select count(*) from table_name;
  B - select count(*) from table_name LATERAL VIEW explode(split(segment, ',') lTable AS singleSegment where segment != ""
  avg = B/A
  </code></pre>
  
  <p>Answer would be 8/4 = 2 in the above case.</p>
  
  <p>Is there a better way to achieve this ?</p>