Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17880#discussion_r115125344
  
    --- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/NullExpressionsSuite.scala
 ---
    @@ -87,24 +91,82 @@ class NullExpressionsSuite extends SparkFunSuite with 
ExpressionEvalHelper {
         }
       }
     
    -  test("SPARK-16602 Nvl should support numeric-string cases") {
    -    def analyze(expr: Expression): Expression = {
    -      val relation = LocalRelation()
    -      SimpleAnalyzer.execute(Project(Seq(Alias(expr, "c")()), 
relation)).expressions.head
    -    }
    -
    +  test("coalesce -check return datatype") {
         val intLit = Literal.create(1, IntegerType)
         val doubleLit = Literal.create(2.2, DoubleType)
         val stringLit = Literal.create("c", StringType)
         val nullLit = Literal.create(null, NullType)
    +    val floatNullLit = Literal.create(null, FloatType)
    +    val floatLit = Literal.create(1.0f, FloatType)
    +
    +    assert(analyze(Coalesce(Seq(nullLit))).dataType == NullType)
    +    assert(analyze(Coalesce(Seq(floatNullLit))).dataType == FloatType)
    +    assert(analyze(Coalesce(Seq(nullLit, intLit))).dataType == IntegerType)
    +    assert(analyze(Coalesce(Seq(nullLit, floatNullLit, intLit))).dataType 
== FloatType)
    +    assert(analyze(Coalesce(Seq(nullLit, intLit, floatLit))).dataType == 
FloatType)
    +    assert(analyze(Coalesce(Seq(nullLit, floatLit, doubleLit))).dataType 
== DoubleType)
    +    assert(analyze(Coalesce(Seq(nullLit, intLit, floatLit, 
doubleLit))).dataType == DoubleType)
    +    assert(analyze(Coalesce(Seq(nullLit, floatNullLit, doubleLit, 
stringLit))).
    +      dataType == StringType)
    +    assert(analyze(Coalesce(Seq(nullLit, intLit, floatLit, doubleLit, 
stringLit))).
    +      dataType == StringType)
    +  }
     
    +  test("SPARK-16602 Nvl should support numeric-string cases") {
    +    val intLit = Literal.create(1, IntegerType)
    +    val doubleLit = Literal.create(2.2, DoubleType)
    +    val stringLit = Literal.create("c", StringType)
    +    val nullLit = Literal.create(null, NullType)
    +    val floatNullLit = Literal.create(null, FloatType)
    +    val floatLit = Literal.create(1.01f, FloatType)
    +    val timestampLit = Literal.create("2017-04-12", TimestampType)
    +    val decimalLit = Literal.create(10.2, DecimalType(20, 2))
    +
    +    assert(analyze(new Nvl(decimalLit, stringLit)).dataType == StringType)
    +    assert(analyze(new Nvl(doubleLit, decimalLit)).dataType == DoubleType)
    +    assert(analyze(new Nvl(decimalLit, doubleLit)).dataType == DoubleType)
    +    assert(analyze(new Nvl(decimalLit, floatLit)).dataType == DoubleType)
    +    assert(analyze(new Nvl(floatLit, decimalLit)).dataType == DoubleType)
    +
    +    assert(analyze(new Nvl(timestampLit, stringLit)).dataType == 
StringType)
         assert(analyze(new Nvl(intLit, doubleLit)).dataType == DoubleType)
         assert(analyze(new Nvl(intLit, stringLit)).dataType == StringType)
         assert(analyze(new Nvl(stringLit, doubleLit)).dataType == StringType)
    +    assert(analyze(new Nvl(doubleLit, stringLit)).dataType == StringType)
     
         assert(analyze(new Nvl(nullLit, intLit)).dataType == IntegerType)
         assert(analyze(new Nvl(doubleLit, nullLit)).dataType == DoubleType)
         assert(analyze(new Nvl(nullLit, stringLit)).dataType == StringType)
    +
    +    assert(analyze(new Nvl(floatLit, stringLit)).dataType == StringType)
    +    assert(analyze(new Nvl(floatLit, doubleLit)).dataType == DoubleType)
    +    assert(analyze(new Nvl(floatNullLit, intLit)).dataType == FloatType)
    +  }
    +
    +  test("Nvl2 -check return datatype") {
    --- End diff --
    
    The same for this. It is being covered by the test case `test("type 
coercion for If")` in `TypeCoercionSuite`. If you want, you can improve that 
test case.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to