Skip to content

Commit df3a8d6

Browse files
author
Russell Aronson
committed
Hdfs filterHidden combinator
1 parent 025a52e commit df3a8d6

File tree

2 files changed

+18
-2
lines changed
  • ivory-alien-hdfs/src

2 files changed

+18
-2
lines changed

ivory-alien-hdfs/src/main/scala/com/ambiata/ivory/alien/hdfs/Hdfs.scala

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ case class Hdfs[+A](action: ActionT[IO, Unit, Configuration, A]) {
2727

2828
def |||[AA >: A](other: Hdfs[AA]): Hdfs[AA] =
2929
Hdfs(action ||| other.action)
30+
31+
def filterHidden(implicit ev: A <:< List[Path]): Hdfs[List[Path]] =
32+
map(_.filter(p => !p.getName.startsWith("_") && !p.getName.startsWith(".")))
3033
}
3134

3235
object Hdfs extends ActionTSupport[IO, Unit, Configuration] {

ivory-alien-hdfs/src/test/scala/com/ambiata/ivory/alien/hdfs/HdfsSpec.scala

+15-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class HdfsSpec extends Specification { def is = s2"""
1212
it is possible to recursively glob paths $e1
1313
can create a new dir, changing the name when it already exists $e2
1414
run out of names when trying to change a dir $e3
15+
can filter out hidden files $e4
1516
"""
1617

1718
val basedir = "target/test/HdfsSpec/" + java.util.UUID.randomUUID()
@@ -22,7 +23,7 @@ class HdfsSpec extends Specification { def is = s2"""
2223
dirs.foreach(dir => new File(dir).mkdirs)
2324
files.foreach(f => new File(f).createNewFile)
2425

25-
Hdfs.globFilesRecursively(new Path(basedir)).run(new Configuration) must beOkLike(paths => paths must haveSize(4))
26+
Hdfs.globFilesRecursively(new Path(basedir, "e1")).run(new Configuration) must beOkLike(paths => paths must haveSize(4))
2627
}
2728

2829
def e2 = {
@@ -37,7 +38,7 @@ class HdfsSpec extends Specification { def is = s2"""
3738
}
3839

3940
def e3 = {
40-
val dir = new Path(basedir + "/e2/a/b/c")
41+
val dir = new Path(basedir + "/e3/a/b/c")
4142

4243
val newDir = for {
4344
_ <- Hdfs.mkdir(dir)
@@ -46,4 +47,16 @@ class HdfsSpec extends Specification { def is = s2"""
4647

4748
newDir.run(new Configuration) must beOkLike(path => path must beNone)
4849
}
50+
51+
def e4 = {
52+
val dir = basedir + "/e4/a/b/c"
53+
val nonhidden = Seq(dir+"/f1", dir+"/f2")
54+
val hidden = Seq(dir+"/.hidden", dir+"/_SUCCESS")
55+
val files = nonhidden ++ hidden
56+
57+
new File(dir).mkdirs
58+
files.foreach(f => new File(f).createNewFile)
59+
60+
Hdfs.globFiles(new Path(dir), "*").filterHidden.run(new Configuration) must beOkLike(paths => paths.map(_.getName) must containTheSameElementsAs(nonhidden.map(new Path(_).getName)))
61+
}
4962
}

0 commit comments

Comments
 (0)