Skip to content

[SPARK-50603][SQL] Respect user-provided basePath for streaming file source reads without glob #51267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import org.apache.spark.sql.classic.{DataFrame, Dataset, SparkSession}
import org.apache.spark.sql.connector.read.streaming
import org.apache.spark.sql.connector.read.streaming.{ReadAllAvailable, ReadLimit, ReadMaxBytes, ReadMaxFiles, SupportsAdmissionControl, SupportsTriggerAvailableNow}
import org.apache.spark.sql.errors.QueryExecutionErrors
import org.apache.spark.sql.execution.datasources.{DataSource, InMemoryFileIndex, LogicalRelation}
import org.apache.spark.sql.execution.datasources.{DataSource, FileIndexOptions, InMemoryFileIndex, LogicalRelation}
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types.StructType
import org.apache.spark.util.ArrayImplicits._
Expand Down Expand Up @@ -73,8 +73,9 @@ class FileStreamSource(

private val optionsForInnerDataSource = sourceOptions.optionMapWithoutPath ++ {
val pathOption =
if (!SparkHadoopUtil.get.isGlobPath(new Path(path)) && options.contains("path")) {
Map("basePath" -> path)
if (!SparkHadoopUtil.get.isGlobPath(new Path(path)) && options.contains("path") &&
!CaseInsensitiveMap(options).contains(FileIndexOptions.BASE_PATH_PARAM)) {
Map(FileIndexOptions.BASE_PATH_PARAM -> path)
} else {
Map()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2619,6 +2619,26 @@ class FileStreamSourceSuite extends FileStreamSourceTest {
}
}
}

test("SPARK-50603: respect user-provided basePath without globbing") {
withTempDirs { case (dir, tmp) =>
val partitionFooSubDir = new File(dir, "partition=foo")
partitionFooSubDir.mkdir()

val schema = new StructType().add("value", StringType).add("partition", StringType)
val fileStream = createFileStream("json", s"${dir.getCanonicalPath}/partition=foo",
Some(schema), Map("basePath" -> dir.getCanonicalPath()))
testStream(fileStream)(
// Add data to partition dir
AddTextFileData("{'value': 'abc'}", partitionFooSubDir, tmp),
CheckAnswer(("abc", "foo")),

// Add more data to same partition=foo sub dir
AddTextFileData("{'value': 'def'}", partitionFooSubDir, tmp),
CheckAnswer(("abc", "foo"), ("def", "foo"))
)
}
}
}

@SlowSQLTest
Expand Down