Github user viirya commented on a diff in the pull request: https://github.com/apache/spark/pull/15523#discussion_r85488370 --- Diff: sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala --- @@ -1617,6 +1617,72 @@ class DataFrameSuite extends QueryTest with SharedSQLContext { } } + private def verifyNullabilityInFilterExec( + df: DataFrame, + expr: String, + expectedNonNullableColumns: Seq[String]): Unit = { + val dfWithFilter = df.where(s"isnotnull($expr)").selectExpr(expr) + // In the logical plan, all the output columns of input dataframe are nullable + dfWithFilter.queryExecution.optimizedPlan.collect { + case e: Filter => assert(e.output.forall(_.nullable)) + } + + dfWithFilter.queryExecution.executedPlan.collect { + // When the child expression in isnotnull is null-intolerant (i.e. any null input will + // result in null output), the involved columns are converted to not nullable; + // otherwise, no change should be made. + case e: FilterExec => + assert(e.output.forall { o => + if (expectedNonNullableColumns.contains(o.name)) !o.nullable else o.nullable + }) + } + } + + test("SPARK-17957: no change on nullability in FilterExec output") { + val df = sparkContext.parallelize(Seq( + null.asInstanceOf[java.lang.Integer] -> new java.lang.Integer(3), + new java.lang.Integer(1) -> null.asInstanceOf[java.lang.Integer], + new java.lang.Integer(2) -> new java.lang.Integer(4))).toDF() + + verifyNullabilityInFilterExec(df, + expr = "Rand()", expectedNonNullableColumns = Seq.empty[String]) + verifyNullabilityInFilterExec(df, + expr = "coalesce(_1, _2)", expectedNonNullableColumns = Seq.empty[String]) + verifyNullabilityInFilterExec(df, + expr = "coalesce(_1, 0) + Rand()", expectedNonNullableColumns = Seq.empty[String]) + verifyNullabilityInFilterExec(df, + expr = "cast(coalesce(cast(coalesce(_1, _2) as double), 0.0) as int)", + expectedNonNullableColumns = Seq.empty[String]) + } + + test("SPARK-17957: set nullability to false in FilterExec output") { + val df = sparkContext.parallelize(Seq( + null.asInstanceOf[java.lang.Integer] -> new java.lang.Integer(3), + new java.lang.Integer(1) -> null.asInstanceOf[java.lang.Integer], + new java.lang.Integer(2) -> new java.lang.Integer(4))).toDF() + + verifyNullabilityInFilterExec(df, + expr = "_1 + _2 * 3", expectedNonNullableColumns = Seq("_1", "_2")) + verifyNullabilityInFilterExec(df, + expr = "_1 + _2", expectedNonNullableColumns = Seq("_1", "_2")) + verifyNullabilityInFilterExec(df, + expr = "_1", expectedNonNullableColumns = Seq("_1")) + verifyNullabilityInFilterExec(df, + expr = "_2 + Rand()", expectedNonNullableColumns = Seq("_2")) --- End diff -- Yeah, so I said I will left that to @cloud-fan or others to decide...
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org