Skip to content

Instantly share code, notes, and snippets.

View bwmcadams's full-sized avatar

Brendan McAdams bwmcadams

View GitHub Profile
@bwmcadams
bwmcadams / Current$OR.Scala
Created November 6, 2011 21:45
Casbah Query DSL Issues
/**
* Trait to provide the $or method as a bareword operator.
*
* $or ("Foo" -> "bar")
*
* Targets an RValue of (String, Any)* to be converted to a DBObject
*
* TODO - Test that rvalue ends up being an array e.g.:
*
* scala> $or ("foo" -> "bar", "X" -> 5)
/* I'm trying to refactor $and and $or (which are essentially the same code returning a different outer query).
The problem is that currently only "String, Any" pairs work, and I need to be able to combine both those *AND* "Query Expression Objects".
Here's the $or spec right now
*/
"Casbah's DSL $or Operator" should {
"Accept multiple values" in {
val or = $or("foo" -> "bar", "x" -> "y")
implicit def kvPairAsDBObject[A <: Any](kv: (String, A)): DBObject = MongoDBObject(kv)
sealed class NestedListOper(outerField: String) {
def apply[A <% DBObject](fields: A*): DBObject = {
val b = Seq.newBuilder[DBObject]
fields.foreach(x => b += x)
MongoDBObject(outerField -> b.result())
}
}
trait JodaDateTimePrimitive extends BSONDatePrimitive[DateTime] {
def rawValue(bson: Long): DateTime = {
new DateTime(bson)
}
def bsonValue(raw: DateTime): Long = {
raw.getMillis
}
}
@bwmcadams
bwmcadams / Controller.scala
Created November 29, 2011 19:48
Play 2.0 Scala + MongoDB via Salat
package controllers
import play.api._
import play.api.mvc._
import com.novus.salat._
import com.novus.salat.global._
import com.novus.salat.dao._
import util._
@bwmcadams
bwmcadams / ls
Created December 9, 2011 22:28
Scripts to setup Pip and Nose on new binary Python builds
[bamboo@bamboo-agent1 python2]$ ls
nosify.sh pip_me.sh r2.4.6 r2.5.6 r2.6.7 r2.7.2
[error] /Users/brendan/code/mongodb/casbah/casbah-query/src/main/scala/Implicits.scala:151: not found: type scala
[error] @annotation.implicitNotFound("${A} is not a valid query parameter")
[error] ^
[error] /Users/brendan/code/mongodb/casbah/casbah-query/src/main/scala/Implicits.scala:151: not found: type scala
[error] @annotation.implicitNotFound("${A} is not a valid query parameter")
[error] ^
[error] one error found
[error] one error found
[error] {file:/Users/brendan/code/mongodb/casbah/}casbah-query/compile:doc: Scaladoc generation failed
[error] {file:/Users/brendan/code/mongodb/casbah/}casbah-query/compile:compile: Compilation failed
val encoder = new com.mongodb.DefaultDBEncoder()
def encode(doc: DBObject): Long = {
encoder.synchronized {
val start = System.currentTimeMillis()
val encoded = encoder.encode(doc)
val end = System.currentTimeMillis()
end - start
}
}
DeregisterConversionHelpers()
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? r
[info] Loading global plugins from /Users/brendan/.sbt/plugins
[info] Loading project definition from /Users/brendan/code/mongodb/mongo-hadoop/project
[info] Compiling 1 Scala source to /Users/brendan/code/mongodb/mongo-hadoop/project/target/scala-2.9.1/sbt-0.11.2/classes...
[error] Reference to undefined setting:
[error]
[error] {.}/*:hadoop-release from {.}/*:library-dependencies
[error]
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?
CREATE EXTERNAL TABLE scores ( student int, name string, score int )
ROW FORMAT SERDE "com.mongodb.hadoop.hive.BSONSerde"
STORED AS INPUTFORMAT "com.mongodb.hadoop.hive.input.BSONFileInputFormat"
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION "/Users/brendan/code/mongodb/mongo-hadoop/hive/test";
LOAD DATA LOCAL INPATH "scores.bson" INTO TABLE scores;