{"id":19604571,"url":"https://github.com/prateek/crunch-example","last_synced_at":"2026-05-11T12:32:44.554Z","repository":{"id":16080920,"uuid":"18825511","full_name":"prateek/crunch-example","owner":"prateek","description":null,"archived":false,"fork":false,"pushed_at":"2014-11-25T16:14:01.000Z","size":236,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-26T16:19:21.199Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prateek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-16T03:25:44.000Z","updated_at":"2017-11-12T03:08:52.000Z","dependencies_parsed_at":"2022-09-11T17:53:47.365Z","dependency_job_id":null,"html_url":"https://github.com/prateek/crunch-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/prateek/crunch-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prateek%2Fcrunch-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prateek%2Fcrunch-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prateek%2Fcrunch-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prateek%2Fcrunch-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prateek","download_url":"https://codeload.github.com/prateek/crunch-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prateek%2Fcrunch-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32894782,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-10T13:40:02.631Z","status":"online","status_checked_at":"2026-05-11T02:00:05.975Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T09:37:22.019Z","updated_at":"2026-05-11T12:32:44.535Z","avatar_url":"https://github.com/prateek.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Crunch-Example #\n\nThis is a sample project demonstrating the use of the `Kite Morphline SDK`, and `Apache Crunch`.\n\n## Sample Input ##\nCSV input, compressed using gzip, with the following structure:\n\n```csv\nid, name, age, salary, years_spent, title, department\n```\n\n## Example 1: Find average salary per department ##\nThis is a facetious example. It is created to demonstrate the scaffolding required around getting the two frameworks (`Morphline` and `Crunch`) rolling along.\n\nThe first example is a the Crunch equivalent of the following SQL query -\n\n```sql\nSELECT\n    department\n  , AVERAGE( salary)\nFROM\n  table\nGROUP BY\n  department\n```\n\nThe equivalent Crunch code (*sans* the scaffolding Morphline assisted text-\u003eAvro conversion, which can be found in `MorphlineDoFn.java`) is provided below. It has minimal boilerplate code, especially when compared to MapReduce code, while still maintaining static typing and extensibility. Sufficed to say, I'm a fan.\n\n```java\n    PCollection\u003cString\u003e lines = getPipeline().read( From.textFile( args[0] ) );\n    PTable\u003cString, Double\u003e summaries = lines\n        .parallelDo( \"GenerateAvroRecords\",\n            new MorphlineDoFn(), Avros.reflects(EmployeeRecord.class) )\n        .by(\"ExtractDepartment\",\n            new MapFn\u003c EmployeeRecord, String \u003e () {\n              public String map( EmployeeRecord record ) {\n                return record.getDepartment();\n              }\n            }, Avros.strings())\n        .mapValues( \"ExtractSalaries\",\n            new MapFn\u003c EmployeeRecord, Pair\u003c Double, Long \u003e \u003e() {\n              public Pair\u003cDouble, Long\u003e map( EmployeeRecord e ) {\n                return Pair.of( e.getSalary(), 1L);\n              }\n            },\n            Avros.pairs(Avros.doubles(), Avros.longs()))\n        .groupByKey()\n        .combineValues(\n            Aggregators.pairAggregator( Aggregators.SUM_DOUBLES(), Aggregators.SUM_LONGS()))\n        .mapValues( \"ComputeAverage\",\n            new MapFn\u003c Pair\u003c Double, Long \u003e, Double \u003e() {\n              public Double map( Pair\u003c Double, Long \u003e p ) {\n                return p.first() / p.second();\n              }\n            },\n            Avros.doubles());\n\n    summaries.write(\n        At.avroFile(args[1], EmployeeSummary.class), Target.WriteMode.APPEND );\n```\n\n## Usage: ##\n\n```sh\n\n$ git clone github.com/prateek/crunch-example.git\n$ cd crunch-example\n$ mvn package\n$ ./setup-data.sh\n$ ./run.sh\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprateek%2Fcrunch-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprateek%2Fcrunch-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprateek%2Fcrunch-example/lists"}