diff --git a/core/src/main/scala/org/apache/spark/rdd/InputFileNameHolder.scala b/core/src/main/scala/org/apache/spark/rdd/InputFileNameHolder.scala index f40d4c8e0a4d0e66f6fb06ce469ee6d41437b5bf..960c91a154db16bc7a79ea116773c02d04d05bb1 100644 --- a/core/src/main/scala/org/apache/spark/rdd/InputFileNameHolder.scala +++ b/core/src/main/scala/org/apache/spark/rdd/InputFileNameHolder.scala @@ -22,6 +22,8 @@ import org.apache.spark.unsafe.types.UTF8String /** * This holds file names of the current Spark task. This is used in HadoopRDD, * FileScanRDD, NewHadoopRDD and InputFileName function in Spark SQL. + * + * The returned value should never be null but empty string if it is unknown. */ private[spark] object InputFileNameHolder { /** @@ -32,9 +34,15 @@ private[spark] object InputFileNameHolder { override protected def initialValue(): UTF8String = UTF8String.fromString("") } + /** + * Returns the holding file name or empty string if it is unknown. + */ def getInputFileName(): UTF8String = inputFileName.get() - private[spark] def setInputFileName(file: String) = inputFileName.set(UTF8String.fromString(file)) + private[spark] def setInputFileName(file: String) = { + require(file != null, "The input file name cannot be null") + inputFileName.set(UTF8String.fromString(file)) + } private[spark] def unsetInputFileName(): Unit = inputFileName.remove() diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/InputFileName.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/InputFileName.scala index b7fb285133bfcde67f8d84ea81b2709c7bf1aee4..d412336699d8011069bec284c296edbc006cf9bc 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/InputFileName.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/InputFileName.scala @@ -30,7 +30,7 @@ import org.apache.spark.unsafe.types.UTF8String usage = "_FUNC_() - Returns the name of the current file being read if available.") case class InputFileName() extends LeafExpression with Nondeterministic { - override def nullable: Boolean = true + override def nullable: Boolean = false override def dataType: DataType = StringType