Skip to content

Commit 05617b0

Browse files
committed
[query] remove non-primitives from scala fs
1 parent cea5bde commit 05617b0

File tree

7 files changed

+304
-302
lines changed

7 files changed

+304
-302
lines changed

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

Lines changed: 31 additions & 26 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,30 +43,35 @@ object GenericLines {
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

62-
val delegate =
63-
new BoundedInputStream.Builder()
64-
.setInputStream(codec.makeInputStream(rawIS))
65-
.get()
67+
val delegate =
68+
new BoundedInputStream.Builder()
69+
.setInputStream(codec.makeInputStream(rawIS))
70+
.get()
6671

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

@@ -290,9 +295,9 @@ object GenericLines {
290295

291296
val contexts = fileStatuses.flatMap { case (fileListEntry, fileNum) =>
292297
val size = fileListEntry.getLen
293-
val codec = fs.getCodecFromPath(fileListEntry.getPath, gzAsBGZ)
298+
val codec = getCodecFromPath(fileListEntry.getPath, gzAsBGZ)
294299

295-
val splittable = codec == null || codec == BGZipCompressionCodec
300+
val splittable = codec.isEmpty || codec.contains(BGZipCompressionCodec)
296301
if (splittable && !filePerPartition) {
297302
var fileNParts = ((totalPartitions.toDouble * size) / totalSize + 0.5).toInt
298303
if (fileNParts == 0)
@@ -304,7 +309,7 @@ object GenericLines {
304309
.map { i =>
305310
val start = partScan(i)
306311
var end = partScan(i + 1)
307-
if (codec != null)
312+
if (codec.isDefined)
308313
end = makeVirtualOffset(end, 0)
309314
Row(i, fileNum, fileListEntry.getPath, start, end, true)
310315
}

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)