Skip to content
Closed
Prev Previous commit
Next Next commit
Some test and bug fixes
  • Loading branch information
mateiz committed Nov 1, 2014
commit 2118c0dcd8d021f876a438bc87f2b30cf432a9b7
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ trait HiveTypeCoercion {
}
}


// scalastyle:off
/**
* Calculates and propagates precision for fixed-precision decimals. Hive has a number of
* rules for this based on the SQL standard and MS SQL:
Expand Down Expand Up @@ -313,6 +313,7 @@ trait HiveTypeCoercion {
* - FLOAT and DOUBLE cause fixed-length decimals to turn into DOUBLE (this is the same as Hive,
* but note that unlimited decimals are considered bigger than doubles in WidenTypes)
*/
// scalastyle:on
object DecimalPrecision extends Rule[LogicalPlan] {
import scala.math.{max, min}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object Literal {
case s: Short => Literal(s, ShortType)
case s: String => Literal(s, StringType)
case b: Boolean => Literal(b, BooleanType)
case d: BigDecimal => Literal(d, DecimalType.Unlimited)
case d: BigDecimal => Literal(Decimal(d), DecimalType.Unlimited)
case d: Decimal => Literal(d, DecimalType.Unlimited)
case t: Timestamp => Literal(t, TimestampType)
case d: Date => Literal(d, DateType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object DataType {
// NOTE: Map fields must be sorted in alphabetical order to keep consistent with the Python side.
private def parseDataType(json: JValue): DataType = json match {
case JString(name) =>
PrimitiveType.nameToType(name) // TODO: Doesn't work for fixed-precision decimal
PrimitiveType.nameToType(name)

case JSortedObject(
("containsNull", JBool(n)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ case class BroadcastHashJoin(

@transient
private val broadcastFuture = future {
val input: Array[Row] = buildPlan.executeCollect()
// Note that we use .execute().collect() because we don't want to convert data to Scala types
val input: Array[Row] = buildPlan.execute().map(_.copy()).collect()
val hashed = HashedRelation(input.iterator, buildSideKeyGenerator, input.length)
sparkContext.broadcast(hashed)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ private[sql] object JsonRDD extends Logging {
case IntegerType => value.asInstanceOf[IntegerType.JvmType]
case LongType => toLong(value)
case DoubleType => toDouble(value)
case DecimalType() => toDecimal(value) // TODO: fix precision and scale
case DecimalType() => toDecimal(value)
case BooleanType => value.asInstanceOf[BooleanType.JvmType]
case NullType => null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ScalaReflectionRelationSuite extends FunSuite {

assert(sql("SELECT * FROM reflectData").collect().head ===
Seq("a", 1, 1L, 1.toFloat, 1.toDouble, 1.toShort, 1.toByte, true,
BigDecimal(1), new Timestamp(12345), Seq(1,2,3)))
BigDecimal(1), new Date(12345), new Timestamp(12345), Seq(1,2,3)))
}

test("query case class RDD with nulls") {
Expand Down