Skip to content
Snippets Groups Projects
Commit da66b974 authored by Takuya UESHIN's avatar Takuya UESHIN Committed by Reynold Xin
Browse files

[SPARK-18583][SQL] Fix nullability of InputFileName.


## What changes were proposed in this pull request?

The nullability of `InputFileName` should be `false`.

## How was this patch tested?

Existing tests.

Author: Takuya UESHIN <ueshin@happy-camper.st>

Closes #16007 from ueshin/issues/SPARK-18583.

(cherry picked from commit a88329d4)
Signed-off-by: default avatarReynold Xin <rxin@databricks.com>
parent 906d82c4
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,8 @@ import org.apache.spark.unsafe.types.UTF8String ...@@ -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, * This holds file names of the current Spark task. This is used in HadoopRDD,
* FileScanRDD, NewHadoopRDD and InputFileName function in Spark SQL. * 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 { private[spark] object InputFileNameHolder {
/** /**
...@@ -32,9 +34,15 @@ private[spark] object InputFileNameHolder { ...@@ -32,9 +34,15 @@ private[spark] object InputFileNameHolder {
override protected def initialValue(): UTF8String = UTF8String.fromString("") override protected def initialValue(): UTF8String = UTF8String.fromString("")
} }
/**
* Returns the holding file name or empty string if it is unknown.
*/
def getInputFileName(): UTF8String = inputFileName.get() 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() private[spark] def unsetInputFileName(): Unit = inputFileName.remove()
......
...@@ -30,7 +30,7 @@ import org.apache.spark.unsafe.types.UTF8String ...@@ -30,7 +30,7 @@ import org.apache.spark.unsafe.types.UTF8String
usage = "_FUNC_() - Returns the name of the current file being read if available.") usage = "_FUNC_() - Returns the name of the current file being read if available.")
case class InputFileName() extends LeafExpression with Nondeterministic { case class InputFileName() extends LeafExpression with Nondeterministic {
override def nullable: Boolean = true override def nullable: Boolean = false
override def dataType: DataType = StringType override def dataType: DataType = StringType
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment