-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-23817][SQL] Create file source V2 framework and migrate ORC read path #23383
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
5d5f59e
9ac801e
5dd34c4
5f35e75
cdb1f99
c1e1f4b
ba66011
91b146b
91475ca
38a27f2
9bbd87b
38b8af5
c91b84a
2c43797
af9de22
2f7b3c6
91aeafb
5ebeda0
3b50f2d
ea8f178
aff3788
575643b
ac8acdd
13d615b
a1e66f3
c4b94c8
471ff1b
7da03ea
0ce4a30
ff8608e
6e87532
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,94 @@ | ||
/* | ||
* 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.sql.execution | ||
|
||
import org.apache.hadoop.fs.{BlockLocation, FileStatus, LocatedFileStatus, Path} | ||
|
||
import org.apache.spark.sql.SparkSession | ||
import org.apache.spark.sql.catalyst.InternalRow | ||
import org.apache.spark.sql.execution.datasources._ | ||
|
||
object PartitionedFileUtil { | ||
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. Now, we have 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 have renamed |
||
def splitFiles( | ||
sparkSession: SparkSession, | ||
file: FileStatus, | ||
filePath: Path, | ||
isSplitable: Boolean, | ||
maxSplitBytes: Long, | ||
partitionValues: InternalRow): Seq[PartitionedFile] = { | ||
if (isSplitable) { | ||
(0L until file.getLen by maxSplitBytes).map { offset => | ||
val remaining = file.getLen - offset | ||
val size = if (remaining > maxSplitBytes) maxSplitBytes else remaining | ||
val hosts = getBlockHosts(getBlockLocations(file), offset, size) | ||
PartitionedFile(partitionValues, filePath.toUri.toString, offset, size, hosts) | ||
} | ||
} else { | ||
Seq(getPartitionedFile(file, filePath, partitionValues)) | ||
} | ||
} | ||
|
||
def getPartitionedFile( | ||
file: FileStatus, | ||
filePath: Path, | ||
partitionValues: InternalRow): PartitionedFile = { | ||
val hosts = getBlockHosts(getBlockLocations(file), 0, file.getLen) | ||
PartitionedFile(partitionValues, filePath.toUri.toString, 0, file.getLen, hosts) | ||
} | ||
|
||
private def getBlockLocations(file: FileStatus): Array[BlockLocation] = file match { | ||
case f: LocatedFileStatus => f.getBlockLocations | ||
case f => Array.empty[BlockLocation] | ||
} | ||
// Given locations of all blocks of a single file, `blockLocations`, and an `(offset, length)` | ||
// pair that represents a segment of the same file, find out the block that contains the largest | ||
// fraction the segment, and returns location hosts of that block. If no such block can be found, | ||
// returns an empty array. | ||
private def getBlockHosts( | ||
gengliangwang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
blockLocations: Array[BlockLocation], | ||
offset: Long, | ||
length: Long): Array[String] = { | ||
val candidates = blockLocations.map { | ||
// The fragment starts from a position within this block | ||
case b if b.getOffset <= offset && offset < b.getOffset + b.getLength => | ||
b.getHosts -> (b.getOffset + b.getLength - offset).min(length) | ||
|
||
// The fragment ends at a position within this block | ||
case b if offset <= b.getOffset && offset + length < b.getLength => | ||
b.getHosts -> (offset + length - b.getOffset).min(length) | ||
|
||
// The fragment fully contains this block | ||
case b if offset <= b.getOffset && b.getOffset + b.getLength <= offset + length => | ||
b.getHosts -> b.getLength | ||
|
||
// The fragment doesn't intersect with this block | ||
case b => | ||
b.getHosts -> 0L | ||
}.filter { case (hosts, size) => | ||
size > 0L | ||
} | ||
|
||
if (candidates.isEmpty) { | ||
Array.empty[String] | ||
} else { | ||
val (hosts, _) = candidates.maxBy { case (_, size) => size } | ||
hosts | ||
} | ||
} | ||
} | ||
|
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.
Given the overall DSv2 risk, shall we make this
public
and add migration doc officially, @gatorsmile ?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.
the streaming flag is also internal, if we want to change it, let's change them together in a followup PR.