Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Case study not an INTRO Showing some code, but not describing the syntax (reference at the end)

Clojure is fully interoperable with Java In this way we get the benefit of many simultaneous streams of work. - Optimizations (join optimizations, for example) - New Features - Adapters and Interfaces to other technologies (e.g. Sink taps for HBase or MySql)

How to express the solution Too much control: Full java program (a lot of overhead to deal with before being able to express your business logic) Too little control: external query language. Either evolve into a turing complete language, or use string manipulation to construct queries -------- A case study of a problem we had. Going to talk about the probelm

the three types of solutions and what they might look like and, of course, I&amp;apos;ll go into the most detail for eh Cascalog solution

if we were doing this with sql, this would be 7 different group by clauses. Our data has 6 dimensions, so 63 aggregations

It&amp;apos;s always possible to compute any agg from the original data set, but we can do better. Using A, B and C as the dimensions. Each node in the tree is a possible rollup. More efficient to make a child node from its parent, rather than the original data. Aggregations with lower cardinality are preferred. [fewer records to aggregate]

To look at something we&amp;apos;re all familiar with, consider how you would do this for a relational database.

first query is based on orig. data second is on a previous agg

Where group_avg is some UDF that can do an average given a series of previous averages and a count from a previous grouping.

DRY principle

- determine table names for INSERT and FROM. - determine column lists and when to use UDF avg vs. standard avg. - Determine which previous aggregate table to use as a source.

alternative is a custom map/reduce program Not going in to much detail here. Too low level. You have to do everything yourself. Limited compos-ability, only what you build yourself. Choose and name the output path Select the best previous aggregation as the input path Determine which fields need to be aggregated for this run and set up the Job Conf.

In this way we get the benefit of many simultaneous streams of work. - Optimizations (join optimizations, for example) - New Features - Adapters and Interfaces to other technologies (e.g. Sink taps for HBase or MySql)

An internal DSL extends the language, but you still have the full power of the host language. none of the functions care about the contents or length of the DIMS vector [A,B,C] yields [A,B] [A,C] [B,C] For key a,b,c select dimensions [B,C] yields &amp;quot;*,b,c&amp;quot;

notice &amp;lt;- instead of ?&amp;lt;-, which means just create the query, don&amp;apos;t execute it, for now. make-qry constructs a single job, to do 1 aggregation

generate-query-tree is also responsible for choosing the best previous aggregation to use for the current rollup.

All of the functions we&amp;apos;ve seen are testable with unit test or integration tests. 2 tests Sample input data Expected Results

Becomes main function input-dir and output-dir are command line arguments to the program. They are paths in HDFS, for example. Could be local file system or S3 paths instead. Or, since this runs on top of Caascading,you coudl output to a database tap or Hbase, for example.

Lastly, I had never used Clojure or any functional language before starting with Cascalog.

Cascalog internal dsl_preso

1.
Cascalog
An example for a complex workflow
Marc Limotte
Metamarkets Group
October 27, 2010

2.
What is Cascalog?
• An internal DSL (domain specific language) for map/reduce
• Implemented in Clojure (a functional language that runs on
the Java VM)
• Several layers of abstraction up-- based on Cascading (an
API for building of Hadoop m/r jobs)

3.
The Three Bears: Choosing a Solution
• Start with a problem or business requirement
• Interested here in the class of problems that require
programmatic query construction:
o Java program on top of Hadoop API (too much control)
o External DSLs (too little control)
o An internal DSL (just right)

8.
Alternative Problem Formulation
There is another way to solve this problem.
• For each input record
– Map task outputs a key for each possible agg
– Use map-side aggregation (combiner)
• Simpler
• In our tests, much slower
• Memory contention? aggregating on a large number
of keys.

10.
Not terrible, but...
Write code in another language to manipulate Query strings.
You have to work with two different languages.
• Different naming conventions
• Different semantics for escaping special characters, etc
• Your IDE will probably only help you with the outer language
(syntax highlighting, syntax verification, formatting, etc).
• Limits composability (UDFs are composable, but not the
control flow)
• Complicates abstraction

11.
Solution 2: Java Map / Reduce
• Control logic to launch each of 63 jobs
• Map
o Parameterizable for data source (previous aggregation)
and which fields to collapse, could be passed in the
JobConf
• Reduce
o Compute avg using previous group avg and count