-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into yunyad-remove-redundancy
- Loading branch information
Showing
5 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
62 changes: 62 additions & 0 deletions
62
core/workflow-operator/src/main/scala/edu/uci/ics/amber/operator/ifStatement/IfOpDesc.scala
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,62 @@ | ||
package edu.uci.ics.amber.operator.ifStatement | ||
|
||
import com.fasterxml.jackson.annotation.{JsonProperty, JsonPropertyDescription} | ||
import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaTitle | ||
import edu.uci.ics.amber.core.executor.OpExecWithClassName | ||
import edu.uci.ics.amber.core.virtualidentity.{ExecutionIdentity, WorkflowIdentity} | ||
import edu.uci.ics.amber.core.workflow.{ | ||
InputPort, | ||
OutputPort, | ||
PhysicalOp, | ||
PortIdentity, | ||
SchemaPropagationFunc | ||
} | ||
import edu.uci.ics.amber.operator.LogicalOp | ||
import edu.uci.ics.amber.operator.metadata.{OperatorGroupConstants, OperatorInfo} | ||
import edu.uci.ics.amber.util.JSONUtils.objectMapper | ||
|
||
class IfOpDesc extends LogicalOp { | ||
@JsonProperty(required = true) | ||
@JsonSchemaTitle("Condition State") | ||
@JsonPropertyDescription("name of the state variable to evaluate") | ||
var conditionName: String = _ | ||
|
||
override def getPhysicalOp( | ||
workflowId: WorkflowIdentity, | ||
executionId: ExecutionIdentity | ||
): PhysicalOp = { | ||
PhysicalOp | ||
.oneToOnePhysicalOp( | ||
workflowId, | ||
executionId, | ||
operatorIdentifier, | ||
OpExecWithClassName( | ||
"edu.uci.ics.amber.operator.ifStatement.IfOpExec", | ||
objectMapper.writeValueAsString(this) | ||
) | ||
) | ||
.withInputPorts(operatorInfo.inputPorts) | ||
.withOutputPorts(operatorInfo.outputPorts) | ||
.withParallelizable(false) | ||
.withPropagateSchema( | ||
SchemaPropagationFunc(inputSchemas => | ||
operatorInfo.outputPorts | ||
.map(_.id) | ||
.map(id => id -> inputSchemas(operatorInfo.inputPorts.last.id)) | ||
.toMap | ||
) | ||
) | ||
} | ||
|
||
override def operatorInfo: OperatorInfo = | ||
OperatorInfo( | ||
"If", | ||
"If", | ||
OperatorGroupConstants.CONTROL_GROUP, | ||
inputPorts = List( | ||
InputPort(PortIdentity(), "Condition"), | ||
InputPort(PortIdentity(1), dependencies = List(PortIdentity())) | ||
), | ||
outputPorts = List(OutputPort(PortIdentity(), "False"), OutputPort(PortIdentity(1), "True")) | ||
) | ||
} |
29 changes: 29 additions & 0 deletions
29
core/workflow-operator/src/main/scala/edu/uci/ics/amber/operator/ifStatement/IfOpExec.scala
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,29 @@ | ||
package edu.uci.ics.amber.operator.ifStatement | ||
|
||
import edu.uci.ics.amber.core.executor.OperatorExecutor | ||
import edu.uci.ics.amber.core.marker.State | ||
import edu.uci.ics.amber.core.tuple.{Tuple, TupleLike} | ||
import edu.uci.ics.amber.core.workflow.PortIdentity | ||
import edu.uci.ics.amber.util.JSONUtils.objectMapper | ||
|
||
class IfOpExec(descString: String) extends OperatorExecutor { | ||
private val desc: IfOpDesc = objectMapper.readValue(descString, classOf[IfOpDesc]) | ||
private var outputPort: PortIdentity = PortIdentity(1) // by default, it should be the true port. | ||
|
||
//This function can handle one or more states. | ||
//The state can have mutiple key-value pairs. Keys are not identified by conditionName will be ignored. | ||
//It can accept any value that can be converted to a boolean. For example, Int 1 will be converted to true. | ||
override def processState(state: State, port: Int): Option[State] = { | ||
outputPort = | ||
if (state.get(desc.conditionName).asInstanceOf[Boolean]) PortIdentity(1) else PortIdentity() | ||
Some(state) | ||
} | ||
|
||
override def processTupleMultiPort( | ||
tuple: Tuple, | ||
port: Int | ||
): Iterator[(TupleLike, Option[PortIdentity])] = | ||
Iterator((tuple, Some(outputPort))) | ||
|
||
override def processTuple(tuple: Tuple, port: Int): Iterator[TupleLike] = ??? | ||
} |
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