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

    https://github.com/apache/spark/pull/7580#discussion_r35293144
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/DataFrameFunctionsSuite.scala ---
    @@ -298,4 +298,28 @@ class DataFrameFunctionsSuite extends QueryTest {
           Seq(Row(2), Row(0), Row(3))
         )
       }
    +
    +  test("array contains function") {
    +    val df = Seq(
    +      (Seq[Int](1, 2), "x"),
    +      (Seq[Int](), "y"),
    +      (null, "z")
    +    ).toDF("a", "b")
    +    checkAnswer(
    +      df.select(array_contains("a", 1)),
    +      Seq(Row(true), Row(false), Row(false))
    +    )
    +    checkAnswer(
    +      df.selectExpr("array_contains(a, 1)"),
    +      Seq(Row(true), Row(false), Row(false))
    +    )
    +    // checkAnswer(
    +    //   df.select(array_contains("a", null)),
    --- End diff --
    
    Unfortunately that did not do the trick. The issue is that this still 
returns an error:
    
    ```scala
    val elementType = left.dataType.asInstanceOf[ArrayType].elementType
          if (!elementType.acceptsType(right.dataType)) {
            TypeCheckResult.TypeCheckFailure(
              s"type of value must match array type " +
                s"${elementType.simpleString}, not " +
                s"${right.dataType.simpleString}")
          } else {
            TypeCheckResult.TypeCheckSuccess
          }
    ```
    
    I think we should leave it `checkInputTypes` alone and only use 
`ExpectsInputTypes` to enforce the argument types to be `Seq(ArrayType, 
AnyDataType)`.
    
    This incurs a performance penalty when based on type information alone the 
value cannot exist in the array (eg testing if a string is in an integer 
array). Since `acceptsTypes` doesn't seem to be loose enough though, this seems 
like the only option.
    
    Based on looking at `ImplicitTypeCasts` and `implicitCast` in 
`HiveTypeCoercion.scala`, it is fairly liberal with casts. Since hive does 
enforce type quality, I think it would be a bad idea to do implicit type 
casting, so only use `ExpectsInputTypes`.


---
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