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

Feature/bijected source sink #886

Merged
merged 3 commits into from
May 29, 2014
Merged

Feature/bijected source sink #886

merged 3 commits into from
May 29, 2014

Conversation

ianoc
Copy link
Collaborator

@ianoc ianoc commented May 29, 2014

Use case is that you have a Source on disk that you want to treat as a different type and have a bijection between those types. Allows reading/writing through the bijection


object BijectedSourceSink {
type SourceSink[T] = TypedSource[T] with TypedSink[T]
def apply[T, U](parent: SourceSink[T], transformer: Bijection[T, U]) = new BijectedSourceSink(parent, transformer)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should transformer here be implicit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thats a good question, no particular reason why not... will update

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated as an implicit, and updated the tests with the cleaner workflow that results

def apply[T, U](parent: SourceSink[T])(implicit transformer: Bijection[T, U]) = new BijectedSourceSink(parent)(transformer)
}

class BijectedSourceSink[T, U](parent: BijectedSourceSink.SourceSink[T])(implicit transformer: Bijection[T, U]) extends TypedSource[U] with TypedSink[U] {
Copy link
Contributor

Choose a reason for hiding this comment

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

extends BijectedSourceSink.SourceSink[U]?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

had tried that, it didn't like extending off the class defined type for some reason

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks awesome. I wonder if implicit transformer: Bijection[T, U])
would have serialization issues or should be lazy?

On Thu, May 29, 2014 at 1:09 PM, ianoc notifications@github.com wrote:

In
scalding-core/src/main/scala/com/twitter/scalding/typed/BijectedSourceSink.scala:

+*/
+package com.twitter.scalding.typed
+
+import cascading.flow.FlowDef
+import cascading.pipe.Pipe
+
+import com.twitter.bijection.Bijection
+import com.twitter.scalding._
+
+
+object BijectedSourceSink {

  • type SourceSink[T] = TypedSource[T] with TypedSink[T]
  • def apply[T, U](parent: SourceSink[T])(implicit transformer: Bijection[T, U]) = new BijectedSourceSink(parent)(transformer)
    +}

+class BijectedSourceSink[T, U](parent: BijectedSourceSink.SourceSink[T])(implicit transformer: Bijection[T, U]) extends TypedSource[U] with TypedSink[U] {

had tried that, it didn't like extending off the class defined type for
some reason


Reply to this email directly or view it on GitHub
https://github.com/twitter/scalding/pull/886/files#r13195197.

@rubanm
Copy link
Contributor

rubanm commented May 29, 2014

tight!

jcoveney added a commit that referenced this pull request May 29, 2014
Add a bijected source sink which allows composing a bijection with a typedsink
@jcoveney jcoveney merged commit a77a029 into develop May 29, 2014
@jcoveney jcoveney deleted the feature/BijectedSourceSink branch May 29, 2014 18:42

object BijectedSourceSink {
type SourceSink[T] = TypedSource[T] with TypedSink[T]
def apply[T, U](parent: SourceSink[T])(implicit transformer: Bijection[T, U]) = new BijectedSourceSink(parent)(transformer)
Copy link
Collaborator

Choose a reason for hiding this comment

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

you should take ImplicitBijection here, not Bijection. This is a trick to deal with the fact that Bijection[A, B] and Bijection[B, A] are equivalent, but confuse implicit resolution.

Copy link
Collaborator

Choose a reason for hiding this comment

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

type on a public method.

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.

None yet

6 participants