@@ -3,7 +3,9 @@ package is.hail.expr.ir
33import is .hail .backend .spark .SparkBackend
44import is .hail .collection .implicits .toRichIterator
55import is .hail .io .compress .BGzipInputStream
6- import is .hail .io .fs .{BGZipCompressionCodec , FS , FileStatus , Positioned , PositionedInputStream }
6+ import is .hail .io .fs .{
7+ getCodecFromPath , BGZipCompressionCodec , FS , FileStatus , Positioned , PositionedInputStream ,
8+ }
79import is .hail .io .tabix .{TabixLineIterator , TabixReader }
810import is .hail .types .virtual .{TBoolean , TInt32 , TInt64 , TString , TStruct , Type }
911import is .hail .utils ._
@@ -12,7 +14,7 @@ import is.hail.variant.Locus
1214import scala .annotation .meta .param
1315
1416import org .apache .commons .io .input .{BoundedInputStream , ProxyInputStream }
15- import org .apache .hadoop .io .compress .SplittableCompressionCodec
17+ import org .apache .hadoop .io .compress .SplittableCompressionCodec . READ_MODE
1618import org .apache .spark .{Partition , TaskContext }
1719import org .apache .spark .rdd .RDD
1820import org .apache .spark .sql .Row
@@ -44,31 +46,31 @@ object GenericLines extends Logging {
4446 private var splitCompressed = false
4547 private val is : PositionedInputStream = {
4648 val rawIS = fs.openNoCompression(file)
47- val codec = fs. getCodecFromPath(file, gzAsBGZ)
48- if (codec == null ) {
49- assert(split || filePerPartition)
50- rawIS.seek(start)
51- rawIS
52- } else if (codec == BGZipCompressionCodec ) {
53- assert(split || filePerPartition)
54- splitCompressed = true
55- val bgzIS =
56- new BGzipInputStream (rawIS, start, end, SplittableCompressionCodec . READ_MODE .BYBLOCK )
57- new ProxyInputStream (bgzIS) with Positioned {
58- override def getPosition : Long = bgzIS.getVirtualOffset
59- }
60- } else {
61- assert(! split || filePerPartition)
49+ getCodecFromPath(file, gzAsBGZ) match {
50+ case None =>
51+ assert(split || filePerPartition)
52+ rawIS.seek(start)
53+ rawIS
54+ case Some ( BGZipCompressionCodec ) =>
55+ assert(split || filePerPartition)
56+ splitCompressed = true
57+ val bgzIS =
58+ new BGzipInputStream (rawIS, start, end, READ_MODE .BYBLOCK )
59+ new ProxyInputStream (bgzIS) with Positioned {
60+ override def getPosition : Long = bgzIS.getVirtualOffset
61+ }
62+ case Some (codec) =>
63+ assert(! split || filePerPartition)
6264
63- val delegate =
64- BoundedInputStream
65- .builder()
66- .setInputStream(codec.makeInputStream(rawIS))
67- .get()
65+ val delegate =
66+ BoundedInputStream
67+ .builder()
68+ .setInputStream(codec.makeInputStream(rawIS))
69+ .get()
6870
69- new ProxyInputStream (delegate) with Positioned {
70- override def getPosition : Long = delegate.getCount
71- }
71+ new ProxyInputStream (delegate) with Positioned {
72+ override def getPosition : Long = delegate.getCount
73+ }
7274 }
7375 }
7476
@@ -292,9 +294,9 @@ object GenericLines extends Logging {
292294
293295 val contexts = fileStatuses.flatMap { case (fileListEntry, fileNum) =>
294296 val size = fileListEntry.getLen
295- val codec = fs. getCodecFromPath(fileListEntry.getPath, gzAsBGZ)
297+ val codec = getCodecFromPath(fileListEntry.getPath, gzAsBGZ)
296298
297- val splittable = codec == null || codec == BGZipCompressionCodec
299+ val splittable = codec.isEmpty || codec.contains( BGZipCompressionCodec )
298300 if (splittable && ! filePerPartition) {
299301 var fileNParts = ((totalPartitions.toDouble * size) / totalSize + 0.5 ).toInt
300302 if (fileNParts == 0 )
@@ -306,7 +308,7 @@ object GenericLines extends Logging {
306308 .map { i =>
307309 val start = partScan(i)
308310 var end = partScan(i + 1 )
309- if (codec != null )
311+ if (codec.isDefined )
310312 end = makeVirtualOffset(end, 0 )
311313 Row (i, fileNum, fileListEntry.getPath, start, end, true )
312314 }
0 commit comments