Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix test
  • Loading branch information
Davies Liu committed Aug 25, 2015
commit 22a966dabb02db94e869b2b9748a1d37fea9fba1
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ object HiveTypeCoercion {

// If input is a numeric type but not decimal, and we expect a decimal type,
// cast the input to decimal.
case (d: NumericType, _: DecimalType) => Cast(e, DecimalType.forType(d))
case (d: NumericType, DecimalType) => Cast(e, DecimalType.forType(d))
// For any other numeric types, implicitly cast to each other, e.g. long -> int, int -> long
case (_: NumericType, target: NumericType) => Cast(e, target)

Expand All @@ -760,7 +760,7 @@ object HiveTypeCoercion {
case (TimestampType, DateType) => Cast(e, DateType)

// Implicit cast from/to string
case (StringType, _: DecimalType) => Cast(e, DecimalType.SYSTEM_DEFAULT)
case (StringType, DecimalType) => Cast(e, DecimalType.SYSTEM_DEFAULT)
case (StringType, target: NumericType) => Cast(e, target)
case (StringType, DateType) => Cast(e, DateType)
case (StringType, TimestampType) => Cast(e, TimestampType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@

package org.apache.spark.sql.catalyst.analysis

import org.apache.spark.sql.catalyst.dsl.expressions._
import org.apache.spark.sql.catalyst.dsl.plans._
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.plans.logical._
import org.apache.spark.sql.types._
import org.apache.spark.sql.catalyst.SimpleCatalystConf
import org.apache.spark.sql.catalyst.dsl.expressions._
import org.apache.spark.sql.catalyst.dsl.plans._

class AnalysisSuite extends AnalysisTest {
import TestRelations._
import org.apache.spark.sql.catalyst.analysis.TestRelations._

test("union project *") {
val plan = (1 to 100)
Expand Down Expand Up @@ -96,7 +95,7 @@ class AnalysisSuite extends AnalysisTest {
assert(pl(1).dataType == DoubleType)
assert(pl(2).dataType == DoubleType)
// StringType will be promoted into Decimal(38, 18)
assert(pl(3).dataType == DecimalType(38, 29))
assert(pl(3).dataType == DecimalType(38, 22))
assert(pl(4).dataType == DoubleType)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ class DecimalPrecisionSuite extends SparkFunSuite with BeforeAndAfter {
checkType(Multiply(i, u), DecimalType(38, 18))
checkType(Multiply(u, u), DecimalType(38, 36))

checkType(Divide(u, d1), DecimalType(38, 21))
checkType(Divide(u, d2), DecimalType(38, 24))
checkType(Divide(u, i), DecimalType(38, 29))
checkType(Divide(u, u), DecimalType(38, 38))
checkType(Divide(u, d1), DecimalType(38, 18))
checkType(Divide(u, d2), DecimalType(38, 19))
checkType(Divide(u, i), DecimalType(38, 23))
checkType(Divide(u, u), DecimalType(38, 18))

checkType(Remainder(d1, u), DecimalType(19, 18))
checkType(Remainder(d2, u), DecimalType(21, 18))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1622,9 +1622,9 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
checkAnswer(sql("select 10.3000 / 3.0"), Row(BigDecimal("3.4333333")))
checkAnswer(sql("select 10.30000 / 30.0"), Row(BigDecimal("0.343333333")))
checkAnswer(sql("select 10.300000000000000000 / 3.00000000000000000"),
Row(BigDecimal("3.4333333333333333333333333333333333333", new MathContext(38))))
Row(BigDecimal("3.433333333333333333333333333", new MathContext(38))))
checkAnswer(sql("select 10.3000000000000000000 / 3.00000000000000000"),
Row(null))
Row(BigDecimal("3.4333333333333333333333333333", new MathContext(38))))
}

test("SPARK-10215 Div of Decimal returns null") {
Expand Down