Skip to content

Commit a460934

Browse files
committed
[query] remove non-primitives from scala fs
1 parent 42504e3 commit a460934

7 files changed

Lines changed: 301 additions & 299 deletions

File tree

‎hail/hail/src/is/hail/expr/ir/GenericLines.scala‎

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package is.hail.expr.ir
22

33
import is.hail.backend.spark.SparkBackend
44
import is.hail.io.compress.BGzipInputStream
5-
import is.hail.io.fs.{BGZipCompressionCodec, FS, FileStatus, Positioned, PositionedInputStream}
5+
import is.hail.io.fs.{getCodecFromPath, BGZipCompressionCodec, FS, FileStatus, Positioned, PositionedInputStream}
66
import is.hail.io.tabix.{TabixLineIterator, TabixReader}
77
import is.hail.types.virtual.{TBoolean, TInt32, TInt64, TString, TStruct, Type}
88
import is.hail.utils._
@@ -43,31 +43,36 @@ object GenericLines extends Logging {
4343
private var splitCompressed = false
4444
private val is: PositionedInputStream = {
4545
val rawIS = fs.openNoCompression(file)
46-
val codec = fs.getCodecFromPath(file, gzAsBGZ)
47-
if (codec == null) {
48-
assert(split || filePerPartition)
49-
rawIS.seek(start)
50-
rawIS
51-
} else if (codec == BGZipCompressionCodec) {
52-
assert(split || filePerPartition)
53-
splitCompressed = true
54-
val bgzIS =
55-
new BGzipInputStream(rawIS, start, end, SplittableCompressionCodec.READ_MODE.BYBLOCK)
56-
new ProxyInputStream(bgzIS) with Positioned {
57-
def getPosition: Long = bgzIS.getVirtualOffset
58-
}
59-
} else {
60-
assert(!split || filePerPartition)
46+
getCodecFromPath(file, gzAsBGZ) match {
47+
case None =>
48+
assert(split || filePerPartition)
49+
rawIS.seek(start)
50+
rawIS
51+
case Some(BGZipCompressionCodec) =>
52+
assert(split || filePerPartition)
53+
splitCompressed = true
54+
val bgzIS =
55+
new BGzipInputStream(
56+
rawIS,
57+
start,
58+
end,
59+
SplittableCompressionCodec.READ_MODE.BYBLOCK,
60+
)
61+
new ProxyInputStream(bgzIS) with Positioned {
62+
def getPosition: Long = bgzIS.getVirtualOffset
63+
}
64+
case Some(codec) =>
65+
assert(!split || filePerPartition)
6166

6267
val delegate =
6368
BoundedInputStream
6469
.builder()
6570
.setInputStream(codec.makeInputStream(rawIS))
6671
.get()
6772

68-
new ProxyInputStream(delegate) with Positioned {
69-
override def getPosition: Long = delegate.getCount
70-
}
73+
new ProxyInputStream(delegate) with Positioned {
74+
override def getPosition: Long = delegate.getCount
75+
}
7176
}
7277
}
7378

@@ -291,9 +296,9 @@ object GenericLines extends Logging {
291296

292297
val contexts = fileStatuses.flatMap { case (fileListEntry, fileNum) =>
293298
val size = fileListEntry.getLen
294-
val codec = fs.getCodecFromPath(fileListEntry.getPath, gzAsBGZ)
299+
val codec = getCodecFromPath(fileListEntry.getPath, gzAsBGZ)
295300

296-
val splittable = codec == null || codec == BGZipCompressionCodec
301+
val splittable = codec.isEmpty || codec.contains(BGZipCompressionCodec)
297302
if (splittable && !filePerPartition) {
298303
var fileNParts = ((totalPartitions.toDouble * size) / totalSize + 0.5).toInt
299304
if (fileNParts == 0)
@@ -305,7 +310,7 @@ object GenericLines extends Logging {
305310
.map { i =>
306311
val start = partScan(i)
307312
var end = partScan(i + 1)
308-
if (codec != null)
313+
if (codec.isDefined)
309314
end = makeVirtualOffset(end, 0)
310315
Row(i, fileNum, fileListEntry.getPath, start, end, true)
311316
}

‎hail/hail/src/is/hail/expr/ir/MatrixWriter.scala‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import is.hail.expr.ir.lowering.TableStage
99
import is.hail.expr.ir.streams.StreamProducer
1010
import is.hail.io._
1111
import is.hail.io.bgen.BgenSettings
12-
import is.hail.io.fs.FS
12+
import is.hail.io.fs.{getCodecExtension, FS}
1313
import is.hail.io.gen.{BgenWriter, ExportGen}
1414
import is.hail.io.index.StagedIndexWriter
1515
import is.hail.io.plink.{BitPacker, ExportPlink}
@@ -755,7 +755,7 @@ case class MatrixVCFWriter(
755755

756756
ExportVCF.checkFormatSignature(tm.entryType)
757757

758-
val ext = ctx.fs.getCodecExtension(path)
758+
val ext = getCodecExtension(path)
759759

760760
val folder = if (exportType == ExportType.CONCATENATED)
761761
ctx.createTmpPath("write-vcf-concatenated")
@@ -1271,7 +1271,7 @@ case class VCFExportFinalizer(
12711271
def writeMetadata(writeAnnotations: => IEmitCode, cb: EmitCodeBuilder, region: Value[Region])
12721272
: Unit = {
12731273
val ctx: ExecuteContext = cb.emb.ctx
1274-
val ext = ctx.fs.getCodecExtension(outputPath)
1274+
val ext = getCodecExtension(outputPath)
12751275

12761276
val annotations = writeAnnotations.getOrAssert(cb).asBaseStruct
12771277

‎hail/hail/src/is/hail/expr/ir/TableWriter.scala‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import is.hail.expr.ir.functions.StringFunctions
1010
import is.hail.expr.ir.lowering.{LowererUnsupportedOperation, TableStage}
1111
import is.hail.expr.ir.streams.StreamProducer
1212
import is.hail.io.{AbstractTypedCodecSpec, BufferSpec, OutputBuffer, TypedCodecSpec}
13-
import is.hail.io.fs.FS
13+
import is.hail.io.fs.{getCodecExtension, FS}
1414
import is.hail.io.index.StagedIndexWriter
1515
import is.hail.rvd.{AbstractRVDSpec, IndexSpec, RVDPartitioner, RVDSpecMaker}
1616
import is.hail.types._
@@ -689,7 +689,7 @@ case class TableTextWriter(
689689
override def lower(ctx: ExecuteContext, ts: TableStage, r: RTable): IR = {
690690
require(exportType != ExportType.PARALLEL_COMPOSABLE)
691691

692-
val ext = ctx.fs.getCodecExtension(path)
692+
val ext = getCodecExtension(path)
693693

694694
val folder = if (exportType == ExportType.CONCATENATED)
695695
ctx.createTmpPath("write-table-concatenated")
@@ -813,7 +813,7 @@ case class TableTextFinalizer(
813813
def writeMetadata(writeAnnotations: => IEmitCode, cb: EmitCodeBuilder, region: Value[Region])
814814
: Unit = {
815815
val ctx: ExecuteContext = cb.emb.ctx
816-
val ext = ctx.fs.getCodecExtension(outputPath)
816+
val ext = getCodecExtension(outputPath)
817817
val partPaths = writeAnnotations.getOrFatal(cb, "write annotations cannot be missing!")
818818
val files = partPaths.castTo(cb, region, SJavaArrayString(true), false).asInstanceOf[
819819
SJavaArrayStringValue

0 commit comments

Comments
 (0)