Skip to content

Commit

Permalink
Merge branch 'release/0.8.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
isnotinvain committed Jun 15, 2015
2 parents 46e6fc1 + 5bea689 commit de4139f
Show file tree
Hide file tree
Showing 18 changed files with 633 additions and 411 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: scala
sudo: false
scala:
- 2.10.4
- 2.11.2
- 2.10.5
- 2.11.5
10 changes: 10 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Bijection #

### 0.8.1
* Simplifies hbase injections with fastAttempt macro: https://github.com/twitter/bijection/pull/220
* Specialize the TBinaryProtocol read path up to ~2x speedups: https://github.com/twitter/bijection/pull/221
* Makes some of the hbase injection tests stricter: https://github.com/twitter/bijection/pull/219
* Migrates hbase bijections to injections because they weren't actually bijections: https://github.com/twitter/bijection/pull/217
* Removes unnecessary HBase injections: https://github.com/twitter/bijection/pull/215
* Fixes flaky test: https://github.com/twitter/bijection/pull/214
* Fixup unidoc: https://github.com/twitter/bijection/pull/213
* Update travis & sbt scala versions to 2.10.5 and 2.11.5: https://github.com/twitter/bijection/pull/212

### 0.8.0
* add twitter util Buf <-> Array[Byte] bijection https://github.com/twitter/bijection/pull/208
* upgrade testing libraries https://github.com/twitter/bijection/pull/207
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Discussion occurs primarily on the [Bijection mailing list](https://groups.googl

## Maven

Bijection modules are available on maven central. The current groupid and version for all modules is, respectively, `"com.twitter"` and `0.8.0`.
Bijection modules are available on maven central. The current groupid and version for all modules is, respectively, `"com.twitter"` and `0.8.1`.

Current published artifacts are

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ class MySqlConversionLaws extends CheckProperties with BaseProperties {
isInjection[NullValue.type, Option[String]]
}
property("Timestamp") {
/** Custom equivalence typeclass for RawValue
* This is here to compare two RawValues generated from Timestamps.
* Because they contain byte arrays, just =='ing them does not work as expected.
*/
/**
* Custom equivalence typeclass for RawValue
* This is here to compare two RawValues generated from Timestamps.
* Because they contain byte arrays, just =='ing them does not work as expected.
*/
implicit val valueEquiv = new scala.math.Equiv[Value] {
override def equiv(a: Value, b: Value) = (a, b) match {
case (RawValue(Type.Timestamp, Charset.Binary, true, bytes1),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,98 @@

package com.twitter.bijection.hbase

import HBaseBijections._
import com.twitter.bijection._
import Injection._
import com.twitter.bijection.AbstractInjection
import com.twitter.bijection.Injection
import com.twitter.bijection.macros.Macros.fastAttempt
import com.twitter.bijection.Tag
import org.apache.hadoop.hbase.io.ImmutableBytesWritable
import org.apache.hadoop.hbase.util.Bytes
import scala.util.Try
import scala.util.Success

/**
* Provides various HBase specific Injections by wrapping org.apache.hadoop.hbase.util.Bytes
* @author Mansur Ashraf
* @since 9/10/13
*/
object HBaseInjections {
import Injection.buildCatchInvert

implicit lazy val string2BytesInj: Injection[String, StringBytes] = fromBijectionRep[String, StringBytes]
implicit lazy val long2BytesInj: Injection[Long, LongBytes] = fromBijectionRep[Long, LongBytes]
implicit lazy val boolean2BytesInj: Injection[Boolean, BooleanBytes] = fromBijectionRep[Boolean, BooleanBytes]
implicit lazy val int2BytesInj: Injection[Int, IntBytes] = fromBijectionRep[Int, IntBytes]
implicit lazy val float2BytesInj: Injection[Float, FloatBytes] = fromBijectionRep[Float, FloatBytes]
implicit lazy val short2BytesInj: Injection[Short, ShortBytes] = fromBijectionRep[Short, ShortBytes]
implicit lazy val double2BytesInj: Injection[Double, DoubleBytes] = fromBijectionRep[Double, DoubleBytes]
implicit lazy val bigdecimal2BytesInj: Injection[BigDecimal, BigDecimalBytes] = fromBijectionRep[BigDecimal, BigDecimalBytes]
implicit lazy val string2BytesWritableInj: Injection[String, ImmutableBytesWritable] = fromBijectionRep[String, ImmutableBytesWritable]
implicit lazy val int2BytesWritableInj: Injection[Int, ImmutableBytesWritable] = fromBijectionRep[Int, ImmutableBytesWritable]
implicit lazy val long2BytesWritableInj: Injection[Long, ImmutableBytesWritable] = fromBijectionRep[Long, ImmutableBytesWritable]
implicit lazy val double2BytesWritableInj: Injection[Double, ImmutableBytesWritable] = fromBijectionRep[Double, ImmutableBytesWritable]
implicit lazy val float2BytesWritableInj: Injection[Float, ImmutableBytesWritable] = fromBijectionRep[Float, ImmutableBytesWritable]
implicit lazy val short2BytesWritableInj: Injection[Short, ImmutableBytesWritable] = fromBijectionRep[Short, ImmutableBytesWritable]
implicit lazy val boolean2BytesWritableInj: Injection[Boolean, ImmutableBytesWritable] = fromBijectionRep[Boolean, ImmutableBytesWritable]
implicit lazy val bigDecimal2BytesWritableInj: Injection[BigDecimal, ImmutableBytesWritable] = fromBijectionRep[BigDecimal, ImmutableBytesWritable]
// Array[Byte] injections
implicit lazy val string2BytesInj: Injection[String, Array[Byte]] =
buildCatchInvert[String, Array[Byte]](Bytes.toBytes)(Bytes.toString)
implicit lazy val long2BytesInj: Injection[Long, Array[Byte]] =
buildCatchInvert[Long, Array[Byte]](Bytes.toBytes)(Bytes.toLong)
implicit lazy val boolean2BytesInj: Injection[Boolean, Array[Byte]] =
buildCatchInvert[Boolean, Array[Byte]](Bytes.toBytes)(Bytes.toBoolean)
implicit lazy val int2BytesInj: Injection[Int, Array[Byte]] =
buildCatchInvert[Int, Array[Byte]](Bytes.toBytes)(Bytes.toInt)
implicit lazy val float2BytesInj: Injection[Float, Array[Byte]] =
buildCatchInvert[Float, Array[Byte]](Bytes.toBytes)(Bytes.toFloat)
implicit lazy val short2BytesInj: Injection[Short, Array[Byte]] =
buildCatchInvert[Short, Array[Byte]](Bytes.toBytes)(Bytes.toShort)
implicit lazy val double2BytesInj: Injection[Double, Array[Byte]] =
buildCatchInvert[Double, Array[Byte]](Bytes.toBytes)(Bytes.toDouble)
implicit lazy val bigDecimal2BytesInj: Injection[BigDecimal, Array[Byte]] =
new AbstractInjection[BigDecimal, Array[Byte]] {
override def apply(a: BigDecimal) = Bytes.toBytes(a.underlying)
override def invert(b: Array[Byte]) = Try(Bytes.toBigDecimal(b)).map(BigDecimal(_))
}

/**
* ImmutableBytesWritable injections avoid copying when possible and use the
* slice (offset and length) of the underlying byte array.
*/
implicit lazy val string2BytesWritableInj =
new ImmutableBytesWritableInjection[String] {
override def invert(b: ImmutableBytesWritable) =
fastAttempt(b)(Bytes.toString(b.get, b.getOffset, b.getLength) match {
case null => sys.error(s"$b decoded to null, which is disallowed.")
case str => str
})
}
implicit lazy val int2BytesWritableInj =
new ImmutableBytesWritableInjection[Int] {
override def invert(b: ImmutableBytesWritable) =
fastAttempt(b)(Bytes.toInt(b.get, b.getOffset, b.getLength))
}
implicit lazy val long2BytesWritableInj =
new ImmutableBytesWritableInjection[Long] {
override def invert(b: ImmutableBytesWritable) =
fastAttempt(b)(Bytes.toLong(b.get, b.getOffset, b.getLength))
}
implicit lazy val double2BytesWritableInj =
new ImmutableBytesWritableInjection[Double] {
override def invert(b: ImmutableBytesWritable) =
fastAttempt(b)(Bytes.toDouble(b.get, b.getOffset))
}
implicit lazy val float2BytesWritableInj =
new ImmutableBytesWritableInjection[Float] {
override def invert(b: ImmutableBytesWritable) =
fastAttempt(b)(Bytes.toFloat(b.get, b.getOffset))
}
implicit lazy val short2BytesWritableInj =
new ImmutableBytesWritableInjection[Short] {
override def invert(b: ImmutableBytesWritable) =
fastAttempt(b)(Bytes.toShort(b.get, b.getOffset, b.getLength))
}
implicit lazy val boolean2BytesWritableInj =
new ImmutableBytesWritableInjection[Boolean] {
override def invert(b: ImmutableBytesWritable) =
fastAttempt(b)(Bytes.toBoolean(b.copyBytes))
}
implicit lazy val bigDecimal2BytesWritableInj =
new ImmutableBytesWritableInjection[BigDecimal] {
override def invert(b: ImmutableBytesWritable) =
fastAttempt(b)(Bytes.toBigDecimal(b.get, b.getOffset, b.getLength))
}
implicit lazy val bytes2BytesWritableInj: Injection[Array[Byte], ImmutableBytesWritable] =
new AbstractInjection[Array[Byte], ImmutableBytesWritable] {
override def apply(a: Array[Byte]) = new ImmutableBytesWritable(a)
override def invert(b: ImmutableBytesWritable) = Try(b.copyBytes)
}

abstract class ImmutableBytesWritableInjection[T](implicit inj: Injection[T, Array[Byte]]) extends AbstractInjection[T, ImmutableBytesWritable] {
override def apply(a: T): ImmutableBytesWritable = new ImmutableBytesWritable(inj(a))
}
}

This file was deleted.

Loading

0 comments on commit de4139f

Please sign in to comment.