Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a OrderedSerialization.viaTransform with no dependencies, and a B… #1329

Merged
merged 7 commits into from
Jun 18, 2015

Conversation

ianoc
Copy link
Collaborator

@ianoc ianoc commented Jun 18, 2015

…ijectedOrderedSerialization in scalding core

…ijectedOrderedSerialization in scalding core
def viaTransform[T, U](
packFn: T => U,
unpackFn: U => T)(implicit otherOrdSer: OrderedSerialization[U]): OrderedSerialization[T] =
new OrderedSerialization[T] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a new type like TransformedOrderedSerialization? Might be useful for optimizing serialization chains, or maybe this is not applicable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how we could use that feature right now? we could always add that in later though if we find a use

@rubanm
Copy link
Contributor

rubanm commented Jun 18, 2015

LGTM

import com.twitter.bijection.Bijection

object BijectedOrderedSerialization {
implicit def fromBijection[T, U](implicit bij: Bijection[T, U], ordSer: OrderedSerialization[U]) =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when taking an implicit Bijection, we need to use the ImplicitBijection type because it handles the fact that Bijection[U, T] would also work here.

import com.twitter.scalding.serialization.OrderedSerialization
import com.twitter.bijection.ImplicitBijection

object BijectedOrderedSerialization {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Thinking out loud about usage in a scalding job, user will at the very least need to know that she has a type that does not have OrdSer and there is a Bijection from that Type to another Type for which OrdSer does exist and will have to import that bijection. We are slightly moving away from AutoMagically making this work by importing 'RequiredBinaryComparator' but not sure if there is a better way? We should probably improve our error message when we encounter a Type with no OrdSer and nudge user toward this approach.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its only ever going to be best effort in the default case I think, if you have a complex JVM type this isn't a good solution either. Though there is a reasonable notion that for new jobs we should force them to re-write in compatible types for the performance improvements... but hard to put in an error message that should write an injection. They probably should write an ordered serialization I suppose... Its a reasonably advanced thing to have to deal with

@johnynek
Copy link
Collaborator

LGTM, merge when green.

implicit def fromBijection[T, U](implicit bij: ImplicitBijection[T, U], ordSer: OrderedSerialization[U]) =
OrderedSerialization.viaTransform[T, U](bij.apply(_), bij.invert(_))

implicit def fromInjection[T, U](implicit bij: Injection[T, U], ordSer: OrderedSerialization[U]) =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like you did not import Injection. Maybe even more coffee? :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my meager defense i got sidetracked and didn't drink the extra coffee yet ;)

@ianoc
Copy link
Collaborator Author

ianoc commented Jun 18, 2015

Fixes #1326

johnynek added a commit that referenced this pull request Jun 18, 2015
…ization

Add a OrderedSerialization.viaTransform with no dependencies, and a B…
@johnynek johnynek merged commit 12b1407 into develop Jun 18, 2015
@ianoc ianoc deleted the ioconnell/bijectedOrderedSerialization branch July 2, 2015 23:32
@ianoc ianoc mentioned this pull request Aug 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants