-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-33298][CORE] Decouple file naming from FileCommitProtocol #32881
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
Changes from all commits
14f4879
93fe5bd
fef7946
e221b85
9878f2e
ddc6955
f716efe
8341ebc
db2594d
0f3df0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.internal.io | ||
|
|
||
| import org.apache.hadoop.fs.Path | ||
| import org.apache.hadoop.mapreduce.TaskAttemptContext | ||
|
|
||
| /** | ||
| * A [[FileNamingProtocol]] implementation to write output data in batch processing. | ||
| */ | ||
| class BatchFileNamingProtocol(jobId: String) extends FileNamingProtocol with Serializable { | ||
|
|
||
| override def getTaskTempPath( | ||
| taskContext: TaskAttemptContext, fileContext: FileContext): String = { | ||
| // The file name looks like part-00000-2dd664f9-d2c4-4ffe-878f-c6c70c1fb0cb_00003-c000.parquet | ||
| // Note that %05d does not truncate the split number, so if we have more than 100000 tasks, | ||
| // the file name is fine and won't overflow. | ||
| val split = taskContext.getTaskAttemptID.getTaskID.getId | ||
| val prefix = fileContext.prefix.getOrElse("") | ||
| val ext = fileContext.ext | ||
| val filename = f"${prefix}part-$split%05d-$jobId$ext" | ||
|
|
||
| fileContext.relativeDir.map { | ||
| d => new Path(d, filename).toString | ||
| }.getOrElse(filename) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.internal.io | ||
|
|
||
| import org.apache.hadoop.mapreduce.TaskAttemptContext | ||
|
|
||
| /** | ||
| * An interface to define how a single Spark job names its outputs. Two notes: | ||
| * | ||
| * 1. Implementations must be serializable, as the instance instantiated on the driver | ||
| * will be used for tasks on executors. | ||
| * 2. An instance should not be reused across multiple Spark jobs. | ||
| * | ||
| * The proper way to call is: | ||
| * | ||
| * As part of each task's execution, whenever a new output file needs be created, executor calls | ||
| * [[getTaskTempPath]] to get a valid relative file path before commit. | ||
| */ | ||
| abstract class FileNamingProtocol { | ||
|
|
||
| /** | ||
| * Gets the relative path should be used for the output file. | ||
| * | ||
| * Important: it is the caller's responsibility to add uniquely identifying content to | ||
| * "fileContext" if a task is going to write out multiple files to the same directory. The file | ||
| * naming protocol only guarantees that files written by different tasks will not conflict. | ||
| */ | ||
| def getTaskTempPath(taskContext: TaskAttemptContext, fileContext: FileContext): String | ||
| } | ||
|
|
||
| /** | ||
| * The context for Spark output file. This is used by [[FileNamingProtocol]] to create file path. | ||
| * | ||
| * @param ext Source specific file extension, e.g. ".snappy.parquet". | ||
| * @param relativeDir Relative directory of file. Can be used for writing dynamic partitions. | ||
| * E.g., "a=1/b=2" is directory for partition (a=1, b=2). | ||
| * @param prefix file prefix. | ||
| */ | ||
| final case class FileContext( | ||
| ext: String, | ||
| relativeDir: Option[String], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not very sure about it. It seems more clear to me to let
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the information in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And the API can be simply named
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This API is only to abstract the naming differences between batch and streaming file writing. If that's not necessary, maybe we can remove this abstraction entirely.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm cleaning this up in #33002 |
||
| prefix: Option[String]) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1405,9 +1405,9 @@ object QueryExecutionErrors { | |
| s"Multiple streaming queries are concurrently using $path", e) | ||
| } | ||
|
|
||
| def addFilesWithAbsolutePathUnsupportedError(commitProtocol: String): Throwable = { | ||
| def addFilesWithAbsolutePathUnsupportedError(protocol: String): Throwable = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this change?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cloud-fan - sorry, this does not need. Was calling it from naming protocol as well in one iteration. Will change. |
||
| new UnsupportedOperationException( | ||
| s"$commitProtocol does not support adding files with an absolute path") | ||
| s"$protocol does not support adding files with an absolute path") | ||
| } | ||
|
|
||
| def microBatchUnsupportedByDataSourceError(srcName: String): Throwable = { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: I can see that, this API makes the code simpler, but it makes the semantic a bit more complicated. What if the final path doesn't have the same file name as the
relativePath? Maybe it's better to havefileName: String, targetDir: String. Then the semantic is pretty here: the impl should commit the new file to the target dir.