Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip writing empty stages & skip loading stages without uid-s #282

Merged
merged 2 commits into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@

package com.salesforce.op

import com.salesforce.op.OpWorkflowModelReadWriteShared.FieldNames
import com.salesforce.op.OpWorkflowModelReadWriteShared.FieldNames._
import com.salesforce.op.features.{FeatureJsonHelper, OPFeature, TransientFeature}
import com.salesforce.op.filters.{FeatureDistribution, RawFeatureFilterResults}
import com.salesforce.op.stages.OpPipelineStageReadWriteShared._
import com.salesforce.op.stages.{OpPipelineStageReader, _}
import com.salesforce.op.stages._
import org.apache.spark.ml.util.MLReader
import org.json4s.JsonAST.{JArray, JNothing, JValue}
import org.json4s.jackson.JsonMethods.parse
Expand Down Expand Up @@ -133,14 +132,16 @@ class OpWorkflowModelReader(val workflowOpt: Option[OpWorkflow]) extends MLReade

private def loadStages(workflow: OpWorkflow, json: JValue, path: String): Seq[OPStage] = {
val stagesJs = (json \ Stages.entryName).extract[JArray].arr
val recoveredStages = stagesJs.map(j => {
val stageUid = (j \ FieldNames.Uid.entryName).extract[String]
val originalStage = workflow.stages.find(_.uid == stageUid)
originalStage match {
case Some(os) => new OpPipelineStageReader(os).loadFromJson(j, path = path).asInstanceOf[OPStage]
case None => throw new RuntimeException(s"Workflow does not contain a stage with uid: $stageUid")
val recoveredStages = stagesJs.flatMap { j =>
val stageUidOpt = (j \ Uid.entryName).extractOpt[String]
stageUidOpt.map { stageUid =>
val originalStage = workflow.stages.find(_.uid == stageUid)
originalStage match {
case Some(os) => new OpPipelineStageReader(os).loadFromJson(j, path = path).asInstanceOf[OPStage]
case None => throw new RuntimeException(s"Workflow does not contain a stage with uid: $stageUid")
}
}
})
}
val generators = workflow.rawFeatures.map(_.originStage)
generators ++ recoveredStages
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ class OpWorkflowModelWriter(val model: OpWorkflowModel) extends MLWriter {
*/
private def stagesJArray(path: String): JArray = {
val stages: Seq[OpPipelineStageBase] = model.stages
val stagesJson: Seq[JObject] = stages.map(_.write.asInstanceOf[OpPipelineStageWriter].writeToJson(path))
val stagesJson: Seq[JObject] = stages
.map(_.write.asInstanceOf[OpPipelineStageWriter].writeToJson(path))
.filter(_.children.nonEmpty)
JArray(stagesJson.toList)
}

Expand Down