-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a9c041
commit 434d558
Showing
12 changed files
with
125 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.spotify.scio.smb | ||
|
||
import com.spotify.scio.io.{KeyedIO, TapOf, TapT, TestIO} | ||
|
||
final case class SMBIO[K, T](id: String, keyBy: T => K) extends KeyedIO[K, T] with TestIO[(K, T)] { | ||
override val tapT: TapT.Aux[(K, T), (K, T)] = TapOf[(K, T)] | ||
override def testId: String = s"SMBIO($id)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
scio-smb/src/test/scala/com/spotify/scio/smb/SortMergeBucketTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.spotify.scio.smb | ||
|
||
import com.spotify.scio.ContextAndArgs | ||
import com.spotify.scio.avro.{Account, Address, User} | ||
import com.spotify.scio.io.{CustomIO, TextIO} | ||
import com.spotify.scio.testing.PipelineSpec | ||
import org.apache.beam.sdk.extensions.smb.{AvroSortedBucketIO, TargetParallelism} | ||
import org.apache.beam.sdk.values.TupleTag | ||
|
||
import java.util.Collections | ||
|
||
object SmbJob { | ||
|
||
def main(cmdlineArgs: Array[String]) = { | ||
val (sc, args) = ContextAndArgs(cmdlineArgs) | ||
|
||
sc.sortMergeJoin( | ||
classOf[Integer], | ||
AvroSortedBucketIO | ||
.read(new TupleTag[User]("lhs"), classOf[User]) | ||
.from(args("users")), | ||
AvroSortedBucketIO | ||
.read(new TupleTag[Account]("rhs"), classOf[Account]) | ||
.from(args("accounts")), | ||
TargetParallelism.max() | ||
).values | ||
.map { case (u, a) => s"${u.getLastName}=${a.getAmount}" } | ||
.saveAsTextFile(args("output")) | ||
|
||
sc.run().waitUntilDone() | ||
} | ||
|
||
} | ||
|
||
class SortMergeBucketTest extends PipelineSpec { | ||
|
||
"SMB" should "be able to mock input and output" in { | ||
val account: Account = new Account(1, "type", "name", 12.5, null) | ||
val address = new Address("street1", "street2", "city", "state", "01234", "Sweden") | ||
val user = | ||
new User(1, "lastname", "firstname", "[email protected]", Collections.emptyList(), address) | ||
|
||
JobTest[SmbJob.type] | ||
.args( | ||
"--users=users", | ||
"--accounts=accounts", | ||
"--output=output" | ||
) | ||
.keyedInput(SMBIO[Integer, User]("users", _.getId), Seq(user)) | ||
// input is also possible but error prone as key must be given manually | ||
.input(SMBIO[Integer, Account]("accounts", _.getId), Seq(account.getId -> account)) | ||
.output(TextIO("output"))(_ should containInAnyOrder(Seq("lastname=12.5"))) | ||
.run() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters