Skip to content

Commit

Permalink
Fix #311 BigQueryType.toTable should only take first child of field t…
Browse files Browse the repository at this point in the history
…o get the type.
  • Loading branch information
andrewsmartin committed Oct 26, 2016
1 parent 282b725 commit ee68f1c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private[types] object TypeProvider {
case List(q"case class $name(..$fields) { ..$body }") =>
val defSchema = q"override def schema: ${p(c, GModel)}.TableSchema = ${p(c, SType)}.schemaOf[$name]"
val defToPrettyString = q"override def toPrettyString(indent: Int = 0): String = ${p(c, s"$SBQ.types.SchemaUtil")}.toPrettyString(this.schema, ${name.toString}, indent)"
val fnTrait = tq"${newTypeName(s"Function${fields.size}")}[..${fields.flatMap(_.children)}, $name]"
val fnTrait = tq"${newTypeName(s"Function${fields.size}")}[..${fields.map(_.children.head)}, $name]"
val traits = if (fields.size <= 22) Seq(fnTrait) else Seq()
val caseClassTree = q"""${caseClass(c)(name, fields, body)}"""
(q"""$caseClassTree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,16 @@ class TypeProviderTest extends FlatSpec with Matchers {
doApply(Record)((3, "a")) shouldEqual Record(3, "a")
}

// This should compile
@BigQueryType.toTable
case class RecordWithDefault(x: Int, y: Int = 2)

it should "work for case class with default params" in {
classOf[Function2[Int, Int, RecordWithDefault]] isAssignableFrom RecordWithDefault.getClass
}

it should "support default argument correctly" in {
RecordWithDefault(10).y shouldEqual 2
}

}

0 comments on commit ee68f1c

Please sign in to comment.