crunch-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Josh Wills <jwi...@cloudera.com>
Subject Re: String concatenation
Date Mon, 30 Jul 2012 16:28:45 GMT
Hey Gauthier,

Very cool-- we don't have a combiner for string concatenation yet and that
would be a great addition. Let's add it as a patch to Crunch-- if this is
your first time submitting code to an Apache project, I can walk you
through it. Our JIRA instance is here:

https://issues.apache.org/jira/browse/CRUNCH

We should create an issue for it and attach your patch to the issue. When
you upload the file, be sure to click the link indicating that you give the
Apache Software Foundation permission to include the code.

If you have more questions, please follow-up with me or on the crunch-dev
mailing list.

J

On Mon, Jul 30, 2012 at 8:47 AM, Gauthier Ambard
<gauthier.ambard@gmail.com>wrote:

> Hi all,
>
> I am using crunch to process some texts (strings): once I have processed
> them, I want to concatenate them.
>
> I haven't found any method for that (concatenate strings) in crunch (or I
> have miss it, which could be very possible). I thought it would be a good
> idea to have a method for that in CombineFn and so I have made mine.
>
> Have I missed an obvious/easier/already implemented/faster way to do it?
> Have I made errors in my implementation?
>
> Thanks
> Gauthier
>
> My code:
>     public static final <K> CombineFn<K, String> STRING_CONCAT() {
>         return aggregatorFactory(STRING_CONCAT);
>     }
>
>     public static class StringConcat implements Aggregator<String> {
>         private StringBuilder sum = new StringBuilder();
>
>         public void reset() {
>             sum = new StringBuilder();
>         }
>
>         public void update(final String next) {
>             sum.append(next).append(' ');
>         }
>
>         public Iterable<String> results() {
>             return ImmutableList.of(sum.toString());
>         }
>     }
>
>     public static AggregatorFactory<String> STRING_CONCAT = new
> AggregatorFactory<String>() {
>         public Aggregator<String> create() {
>             return new StringConcat();
>         }
>     };
>



-- 
Director of Data Science
Cloudera <http://www.cloudera.com>
Twitter: @josh_wills <http://twitter.com/josh_wills>

Mime
View raw message