seznam / euphoria

Euphoria is an open source Java API for creating unified big-data processing flows. It provides an engine independent programming model which can express both batch and stream transformations.
Apache License 2.0
82 stars 11 forks source link

SequenceFileSink builder enhancements #295

Closed davidak09 closed 6 years ago

davidak09 commented 6 years ago

I found some solution to the builder problem, so here's an enhancement proposal. It looks more readable, at least to me. :-)

Inspiration taken from: https://blog.jayway.com/2012/02/07/builder-pattern-with-a-twist/

dmvk commented 6 years ago

Interesting, it seems like a reasonable trade-off between code complexity and usability.

This could be probably also applied to generic type builders, eg.: ReduceByKey

cc @VaclavPlajt

static <IN> KeyBuilder<IN>of(Dataset<IN> input) {
  // ...
}

interface KeyBuilder<IN> {
  <K> ReduceBuilder<IN, K> keyBy(UnaryFunction<IN, K> keyExtractor);
}

interface ReduceBuilder<IN, K> {
  <OUT> FinalBuilder<IN, K, OUT> keyBy(ReduceFunctor<IN, OUT> reducer);
}

interface FinalBuilder<IN, K, OUT> {
  // optinal builders
}

class Builder<IN, K, OUT> extends KeyBuilder<IN>, ReduceBuilder<IN, K>, FinalBuilder<IN, K, OUT> {
}
VaclavPlajt commented 6 years ago

That is a clever solution to our builders problem. I elaborated little bit more. And it seem to suit to our needs. See an example.

dmvk commented 6 years ago

@VaclavPlajt awesome, this should simplify things a lot