I have a Hive table that keeps track of the state of an object moving through process steps. The table looks like this:
hive> desc journeys;
object_id string
journey_statuses array<string>
Here is a typical recording example:
12345678 ["A","A","A","B","B","B","C","C","C","C","D"]
Entries in the table were generated using Hive 0.13 collect_list, and the statuses are in order (if the order is not important, I would use it collect_set). For each object_id, I would like to shorten the trip in order to return the statuses of the path in the order in which they appear.
I wrote a quick Python script that reads from stdin:
import sys
import itertools
for line in sys.stdin:
inputList = eval(line.strip())
readahead = iter(inputList)
next(readahead)
result = []
for id, (a, b) in enumerate(itertools.izip(inputList, readahead)):
if id == 0:
result.append(a)
if a != b:
result.append(b)
print result
I planned to use this in a Hive call transform. It seems to work on local startup:
$ echo '["A","A","A","B","B","B","C","C","C","C","D"]' | python abbreviate_list.py
['A', 'B', 'C', 'D']
However, when I add a file and try to execute inside Hive, an error is returned:
hive> add file abbreviateList.py;
Added resource: abbreviateList.py
hive> select
> object_id,
> transform(journey_statuses) using 'python abbreviateList.py' as journey_statuses_abbreviated
> from journeys;
NoViableAltException( ... wall of Java error messages ... )
FAILED: ParseException line 3:2 cannot recognize input near 'transform' '(' 'journey_statuses' in select expression
, ?