-
Notifications
You must be signed in to change notification settings - Fork 155
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 chill-algebird project by copying AlgebirdSerializers from of scaldi... #177
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d59bfdb
add chill-algebird project by copying AlgebirdSerializers from of sca…
koertkuipers c92d127
add AlgebirdRegistrar that registers serializers
koertkuipers 50baafd
AlgebirdRegistrar does all algebird registrations currently found in …
koertkuipers ede7955
add some basic unit tests
koertkuipers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
chill-algebird/src/main/scala/com/twitter/chill/algebird/AlgebirdSerializers.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,118 @@ | ||
/* | ||
Copyright 2012 Twitter, Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.twitter.chill.algebird | ||
|
||
import com.esotericsoftware.kryo.Kryo | ||
import com.esotericsoftware.kryo.{Serializer => KSerializer} | ||
import com.esotericsoftware.kryo.io.{Input, Output} | ||
|
||
import com.twitter.algebird.{AveragedValue, DecayedValue, HLL, HyperLogLog, | ||
HyperLogLogMonoid, Moments, SpaceSaver, SSOne, SSMany} | ||
|
||
import scala.collection.mutable.{Map => MMap} | ||
import scala.collection.immutable.SortedMap | ||
|
||
class AveragedValueSerializer extends KSerializer[AveragedValue] { | ||
setImmutable(true) | ||
def write(kser: Kryo, out : Output, s : AveragedValue) { | ||
out.writeLong(s.count, true) | ||
out.writeDouble(s.value) | ||
} | ||
def read(kser : Kryo, in : Input, cls : Class[AveragedValue]) : AveragedValue = | ||
AveragedValue(in.readLong(true), in.readDouble) | ||
} | ||
|
||
class MomentsSerializer extends KSerializer[Moments] { | ||
setImmutable(true) | ||
def write(kser: Kryo, out : Output, s : Moments) { | ||
out.writeLong(s.m0, true) | ||
out.writeDouble(s.m1) | ||
out.writeDouble(s.m2) | ||
out.writeDouble(s.m3) | ||
out.writeDouble(s.m4) | ||
} | ||
def read(kser : Kryo, in : Input, cls : Class[Moments]) : Moments = { | ||
Moments(in.readLong(true), | ||
in.readDouble, | ||
in.readDouble, | ||
in.readDouble, | ||
in.readDouble) | ||
} | ||
} | ||
|
||
|
||
class DecayedValueSerializer extends KSerializer[DecayedValue] { | ||
setImmutable(true) | ||
def write(kser: Kryo, out : Output, s : DecayedValue) { | ||
out.writeDouble(s.value) | ||
out.writeDouble(s.scaledTime) | ||
} | ||
def read(kser : Kryo, in : Input, cls : Class[DecayedValue]) : DecayedValue = | ||
DecayedValue(in.readDouble, in.readDouble) | ||
} | ||
|
||
class HLLSerializer extends KSerializer[HLL] { | ||
setImmutable(true) | ||
def write(kser: Kryo, out : Output, s : HLL) { | ||
val bytes = HyperLogLog.toBytes(s) | ||
out.writeInt(bytes.size, true) | ||
out.writeBytes(bytes) | ||
} | ||
def read(kser : Kryo, in : Input, cls : Class[HLL]) : HLL = { | ||
HyperLogLog.fromBytes(in.readBytes(in.readInt(true))) | ||
} | ||
} | ||
|
||
class HLLMonoidSerializer extends KSerializer[HyperLogLogMonoid] { | ||
setImmutable(true) | ||
val hllMonoids = MMap[Int,HyperLogLogMonoid]() | ||
def write(kser: Kryo, out : Output, mon : HyperLogLogMonoid) { | ||
out.writeInt(mon.bits, true) | ||
} | ||
def read(kser : Kryo, in : Input, cls : Class[HyperLogLogMonoid]) : HyperLogLogMonoid = { | ||
val bits = in.readInt(true) | ||
hllMonoids.getOrElseUpdate(bits, new HyperLogLogMonoid(bits)) | ||
} | ||
} | ||
|
||
// class SpaceSaverSerializer[T] extends KSerializer[SpaceSaver[T]] { | ||
// setImmutable(true) | ||
// def write(kser: Kryo, out: Output, s: SpaceSaver[T]) { | ||
// s match { | ||
// case (one: SSOne[_]) => { | ||
// out.writeByte(1) | ||
// out.writeInt(one.capacity, true) | ||
// kser.writeClassAndObject(out, one.item) | ||
// } | ||
// case (many: SSMany[_]) => { | ||
// out.writeByte(2) | ||
// out.writeInt(many.capacity, true) | ||
// kser.writeClassAndObject(out, many.counters) | ||
// kser.writeClassAndObject(out, many.bucketsOption) | ||
// } | ||
// } | ||
// } | ||
// def read(kser: Kryo, in: Input, cls: Class[SpaceSaver[T]]): SpaceSaver[T] = { | ||
// in.readByte match { | ||
// case 1 => SSOne[T](in.readInt(true), kser.readClassAndObject(in).asInstanceOf[T]) | ||
// case 2 => SSMany[T]( | ||
// in.readInt(true), | ||
// kser.readClassAndObject(in).asInstanceOf[Map[T, (Long, Long)]], | ||
// kser.readClassAndObject(in).asInstanceOf[Option[SortedMap[Long, Set[T]]]] | ||
// ) | ||
// } | ||
// } | ||
// } |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this need to be commented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, until this is in algebird release:
twitter/algebird#289
On Fri, Mar 14, 2014 at 1:26 PM, P. Oscar Boykin
notifications@github.comwrote:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was merged