DataFu: The WD-40 of Big Data
If Pig is the “duct tape for big data“, then DataFu is the WD-40. Or something.
No, seriously, DataFu is a collection of Pig UDFs for data analysis on Hadoop. DataFu includes routines for common statistics tasks (e.g., median, variance), PageRank, set operations, and bag operations.
It’s helpful to understand the history of the library. Over the years, we developed several routines that were used across LinkedIn and were thrown together into an internal package we affectionately called “littlepiggy.” The unfortunate part, and this is true of many such efforts, is that the UDFs were ill-documented, ill-organized, and easily got broken when someone made a change. Along came PigUnit, which allowed UDF testing, so we spent the time to clean up these routines by adding documentation and rigorous unit tests. From this “datafoo” package, we thought this would help the community at large, and there you have DataFu.
So what can this library do for you? Let’s look at one of the classical examples that showcase the power and flexibility of Pig: sessionizing a click steam.
A = load ‘clicks’;
B = group A by user;
C = foreach B {
C1 = order A by timestamp;
generate user, Sessonize(C1);
}
D = group C by session_id;
E = foreach D generate group as session_id, (MAX(C.timestamp) - MIN(C.timestamp)) as session_length;
F = group E all;
G = foreach F generate
AVG(E.session_length) as avg_session_length,
SQRT(VAR(E.session_length)) as sd_session_length,
MEDIAN(E.session_length) as median_session_length,
Q75(E.session_length) as session_length_75pct,
Q90(E.session_length) as session_length_90pct,
Q95(E.session_length) as session_length_95pct;
(In fact, this is basically the example for the Accumulator interface that was added in Pig 0.6.)
Here, we’re just computing some summary statistics on a sessionized click stream. Pig does the heavy lifting of transforming your query into MapReduce goodness, but DataFu fills in the gaps by providing the missing routines for every italicized function.
You can grab sample data and code you can run on your own for this sessionization example below.