-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[query] Expand ReadValue beyond hail EType deserialization (#12948)
This represents a small redesign of ValueWriter as well. Add deserializers, subclasses of ValueReader and have ReadValue use them. A ValueReader deserializes a single hail value from an input stream. This change also alters the semantics of ValueWriters. Both readers and writers no longer manage their own I/O resources. It is the responsibility of 'callers' to do so instead. However programmers must be careful as we need to create input/output buffers to perform native serialization/deserialization. For InputBuffers in particular, the underlying stream may be left in an unusable state.
- Loading branch information
1 parent
0aaf389
commit 532e688
Showing
18 changed files
with
117 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package is.hail.expr.ir | ||
|
||
import is.hail.annotations.Region | ||
import is.hail.asm4s._ | ||
import is.hail.io.{AbstractTypedCodecSpec, BufferSpec, TypedCodecSpec} | ||
import is.hail.types.TypeWithRequiredness | ||
import is.hail.types.encoded._ | ||
import is.hail.types.physical._ | ||
import is.hail.types.physical.stypes.{SCode, SType, SValue} | ||
import is.hail.types.physical.stypes.concrete.SStackStruct | ||
import is.hail.types.virtual._ | ||
import is.hail.utils._ | ||
|
||
import org.json4s.{DefaultFormats, Extraction, Formats, JValue, ShortTypeHints} | ||
|
||
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, InputStream, OutputStream} | ||
|
||
object ValueReader { | ||
implicit val formats: Formats = new DefaultFormats() { | ||
override val typeHints = ShortTypeHints(List( | ||
classOf[ETypeValueReader], | ||
classOf[AbstractTypedCodecSpec], | ||
classOf[TypedCodecSpec]), | ||
typeHintFieldName = "name" | ||
) + BufferSpec.shortTypeHints | ||
} + | ||
new TStructSerializer + | ||
new TypeSerializer + | ||
new PTypeSerializer + | ||
new ETypeSerializer | ||
} | ||
|
||
abstract class ValueReader { | ||
def unionRequiredness(requestedType: Type, requiredness: TypeWithRequiredness): Unit | ||
|
||
def readValue(cb: EmitCodeBuilder, t: Type, region: Value[Region], is: Value[InputStream]): SValue | ||
|
||
def toJValue: JValue = Extraction.decompose(this)(ValueReader.formats) | ||
} | ||
|
||
|
||
final case class ETypeValueReader(spec: AbstractTypedCodecSpec) extends ValueReader { | ||
def unionRequiredness(requestedType: Type, requiredness: TypeWithRequiredness): Unit = | ||
requiredness.fromPType(spec.encodedType.decodedPType(requestedType)) | ||
|
||
def readValue(cb: EmitCodeBuilder, t: Type, region: Value[Region], is: Value[InputStream]): SValue = { | ||
val decoder = spec.encodedType.buildDecoder(t, cb.emb.ecb) | ||
val ib = cb.memoize(spec.buildCodeInputBuffer(is)) | ||
val ret = decoder.apply(cb, region, ib) | ||
ret | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.