Support Questions
Find answers, ask questions, and share your expertise

How do I count shortcodes from row in hive?

New Contributor

I have a table which consists of eight column such as A,B,C,....H. Each column have some shortcodes such as U,V,W randomly.Now I need to count the no of U,V,W from each row.Some columns may have null or unknown value also.

Here is a demo:

ABCDEFGH
UWVUW
UUWV
WWUV

Here I need to use HiveQL.

1 REPLY 1

@PRIYATAM SAHA hm, I'm not sure if this is possible with SQL at all, since SQL works on a column basis. You could try reading the dataset into Apache Spark and then counting the values in the matrix like that. Check this question which seems similar to yours: https://stackoverflow.com/questions/31562825/spark-scala-how-to-count-values-in-rows

You load the table into Spark using a HiveContext and then you can work on it using Spark functions. Try that out perhaps and let us know how you get on.