Skip to content
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

Fix partition num when paths contain directories #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 10 additions & 1 deletion src/main/scala/io/druid/indexer/spark/SparkDruidIndexer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,16 @@ object SparkDruidIndexer {
s => {
val p = new Path(s)
val fs = p.getFileSystem(sc.hadoopConfiguration)
fs.getFileStatus(p).getLen
if (fs.getFileStatus(p).isDirectory) {
var sum = 0l
val children = fs.listFiles(p, false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you scala-fy this? This syntax will be off, but something like:

sum += fs.listFiles(p, false).map(_.getLen).sum

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fs.listFiles returns a RemoteIterator, which isn't a subclass of Iterator and as such, there is no implicit converters towards Scala types. I could do something like Iterator.continually(Try { children.next().getLen }).takeWhile(_.isSuccess).map(_.get).sum, but I'm not sure it's better.

Which one you'd prefer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer for Hadoop to do things in a way that is compatible with Scala :-P

barring that, please add a comment to why the manual iteration is needed.

while(children.hasNext) {
sum += children.next().getLen
}
sum
} else {
fs.getFileStatus(p).getLen
}
}
).sum
val startingPartitions = (totalGZSize / (100L << 20)).toInt + 1
Expand Down