diff --git a/hail/src/main/scala/is/hail/expr/types/TableType.scala b/hail/src/main/scala/is/hail/expr/types/TableType.scala index f9755260d2a..717dbe3aedf 100644 --- a/hail/src/main/scala/is/hail/expr/types/TableType.scala +++ b/hail/src/main/scala/is/hail/expr/types/TableType.scala @@ -1,6 +1,7 @@ package is.hail.expr.types import is.hail.expr.ir._ +import is.hail.expr.types.physical.{PStruct, PType} import is.hail.expr.types.virtual.{TStruct, Type} import is.hail.rvd.RVDType import is.hail.utils._ @@ -12,7 +13,9 @@ class TableTypeSerializer extends CustomSerializer[TableType](format => ( { case tt: TableType => JString(tt.toString) })) case class TableType(rowType: TStruct, key: IndexedSeq[String], globalType: TStruct) extends BaseType { - lazy val canonicalRVDType = RVDType(rowType.physicalType, key) + lazy val canonicalPType = PType.canonical(rowType).asInstanceOf[PStruct] + lazy val canonicalRVDType = RVDType(canonicalPType, key) + key.foreach {k => if (!rowType.hasField(k)) throw new RuntimeException(s"key field $k not in row type: $rowType") diff --git a/hail/src/main/scala/is/hail/io/plink/LoadPlink.scala b/hail/src/main/scala/is/hail/io/plink/LoadPlink.scala index 79da4e913fe..0713c34231e 100644 --- a/hail/src/main/scala/is/hail/io/plink/LoadPlink.scala +++ b/hail/src/main/scala/is/hail/io/plink/LoadPlink.scala @@ -4,6 +4,7 @@ import is.hail.HailContext import is.hail.annotations._ import is.hail.expr.ir.{LowerMatrixIR, MatrixHybridReader, MatrixRead, MatrixReader, MatrixValue, PruneDeadFields, TableRead, TableValue} import is.hail.expr.types._ +import is.hail.expr.types.physical.{PBoolean, PFloat64, PString, PStruct} import is.hail.expr.types.virtual._ import is.hail.io.vcf.LoadVCF import is.hail.rvd.{RVD, RVDContext, RVDType} @@ -44,14 +45,14 @@ object LoadPlink { """^-?(?:\d+|\d*\.\d+)(?:[eE]-?\d+)?$""".r def parseFam(filename: String, ffConfig: FamFileConfig, - fs: FS): (IndexedSeq[Row], TStruct) = { + fs: FS): (IndexedSeq[Row], PStruct) = { val delimiter = unescapeString(ffConfig.delimiter) - val phenoSig = if (ffConfig.isQuantPheno) ("quant_pheno", TFloat64()) else ("is_case", TBoolean()) + val phenoSig = if (ffConfig.isQuantPheno) ("quant_pheno", PFloat64()) else ("is_case", PBoolean()) - val signature = TStruct(("id", TString()), ("fam_id", TString()), ("pat_id", TString()), - ("mat_id", TString()), ("is_female", TBoolean()), phenoSig) + val signature = PStruct(("id", PString()), ("fam_id", PString()), ("pat_id", PString()), + ("mat_id", PString()), ("is_female", PBoolean()), phenoSig) val idBuilder = new ArrayBuilder[String] val structBuilder = new ArrayBuilder[Row] @@ -181,7 +182,7 @@ case class MatrixPLINKReader( val fullMatrixType: MatrixType = MatrixType( globalType = TStruct.empty(), colKey = Array("s"), - colType = saSignature, + colType = saSignature.virtualType, rowType = TStruct( "locus" -> TLocus.schemaFromRG(referenceGenome), "alleles" -> TArray(TString()), @@ -210,7 +211,7 @@ case class MatrixPLINKReader( nPartitions.getOrElse(sc.defaultMinPartitions))) val kType = requestedType.canonicalRVDType.kType - val rvRowType = requestedType.rowType + val rvRowType = requestedType.canonicalPType val hasRsid = requestedType.rowType.hasField("rsid") val hasCmPos = requestedType.rowType.hasField("cm_position") @@ -260,7 +261,7 @@ case class MatrixPLINKReader( if (skipInvalidLociLocal && !rgLocal.forall(_.isValidLocus(contig, pos))) None else { - rvb.start(rvRowType.physicalType) + rvb.start(rvRowType) rvb.startStruct() rvb.addAnnotation(kType.types(0).virtualType, Locus.annotation(contig, pos, rgLocal)) rvb.startArray(2) @@ -268,7 +269,7 @@ case class MatrixPLINKReader( rvb.addString(alt) rvb.endArray() if (hasRsid) - rvb.addAnnotation(rvRowType.types(2), rsid) + rvb.addAnnotation(rvRowType.types(2).virtualType, rsid) if (hasCmPos) rvb.addDouble(cmPos) if (!dropSamples) diff --git a/hail/src/main/scala/is/hail/table/Table.scala b/hail/src/main/scala/is/hail/table/Table.scala index fcd30cabee6..d87df7681f1 100644 --- a/hail/src/main/scala/is/hail/table/Table.scala +++ b/hail/src/main/scala/is/hail/table/Table.scala @@ -62,10 +62,10 @@ object Table { delimiter: String = "\\t", missingValue: String = "NA"): String = { val ffConfig = FamFileConfig(isQuantPheno, delimiter, missingValue) - val (data, typ) = LoadPlink.parseFam(path, ffConfig, HailContext.sFS) + val (data, ptyp) = LoadPlink.parseFam(path, ffConfig, HailContext.sFS) val jv = JSONAnnotationImpex.exportAnnotation( - Row(typ.toString, data), - TStruct("type" -> TString(), "data" -> TArray(typ))) + Row(ptyp.toString, data), + TStruct("type" -> TString(), "data" -> TArray(ptyp.virtualType))) JsonMethods.compact(jv) }