Search in sources :

Example 1 with ComparisonExpression

use of org.flyte.api.v1.ComparisonExpression in project flytekit-java by flyteorg.

the class ProtoUtilTest method shouldSerializeBranchNode.

@Test
void shouldSerializeBranchNode() {
    ComparisonExpression comparison = ComparisonExpression.builder().operator(ComparisonExpression.Operator.EQ).leftValue(Operand.ofVar("a")).rightValue(Operand.ofVar("b")).build();
    Condition.ComparisonExpression comparisonProto = Condition.ComparisonExpression.newBuilder().setOperator(Condition.ComparisonExpression.Operator.EQ).setLeftValue(Condition.Operand.newBuilder().setVar("a").build()).setRightValue(Condition.Operand.newBuilder().setVar("b").build()).build();
    IfBlock ifBlock = IfBlock.builder().condition(BooleanExpression.ofComparison(comparison)).thenNode(Node.builder().id("node-1").upstreamNodeIds(ImmutableList.of()).inputs(ImmutableList.of()).build()).build();
    Workflow.IfBlock ifBlockProto = Workflow.IfBlock.newBuilder().setThenNode(Workflow.Node.newBuilder().setId("node-1").build()).setCondition(Condition.BooleanExpression.newBuilder().setComparison(comparisonProto).build()).build();
    IfElseBlock ifElse = IfElseBlock.builder().case_(ifBlock).other(ImmutableList.of(ifBlock)).elseNode(ifBlock.thenNode()).build();
    Workflow.IfElseBlock ifElseProto = Workflow.IfElseBlock.newBuilder().setCase(ifBlockProto).addOther(ifBlockProto).setElseNode(ifBlockProto.getThenNode()).build();
    BranchNode branchNode = BranchNode.builder().ifElse(ifElse).build();
    Workflow.BranchNode branchNodeProto = Workflow.BranchNode.newBuilder().setIfElse(ifElseProto).build();
    assertThat(ProtoUtil.serialize(branchNode), equalTo(branchNodeProto));
}
Also used : Condition(flyteidl.core.Condition) ComparisonExpression(org.flyte.api.v1.ComparisonExpression) IfElseBlock(org.flyte.api.v1.IfElseBlock) BranchNode(org.flyte.api.v1.BranchNode) Workflow(flyteidl.core.Workflow) IfBlock(org.flyte.api.v1.IfBlock) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ComparisonExpression

use of org.flyte.api.v1.ComparisonExpression in project flytekit-java by flyteorg.

the class IdentifierRewriteTest method shouldRewriteBranchNodes.

@Test
void shouldRewriteBranchNodes() {
    ComparisonExpression comparison = ComparisonExpression.builder().operator(ComparisonExpression.Operator.EQ).leftValue(Operand.ofVar("a")).rightValue(Operand.ofVar("b")).build();
    BooleanExpression condition = BooleanExpression.ofComparison(comparison);
    PartialTaskIdentifier partialReference = PartialTaskIdentifier.builder().name("task-name").build();
    PartialTaskIdentifier rewrittenReference = PartialTaskIdentifier.builder().name("task-name").domain("rewritten-domain").version("rewritten-version").project("rewritten-project").build();
    TaskNode partialTaskNode = TaskNode.builder().referenceId(partialReference).build();
    TaskNode rewrittenTaskNode = TaskNode.builder().referenceId(rewrittenReference).build();
    Node partialNode = Node.builder().id("node-1").inputs(ImmutableList.of()).upstreamNodeIds(ImmutableList.of()).taskNode(partialTaskNode).build();
    Node rewrittenNode = Node.builder().id("node-1").inputs(ImmutableList.of()).upstreamNodeIds(ImmutableList.of()).taskNode(rewrittenTaskNode).build();
    IfBlock partialIfBlock = IfBlock.builder().condition(condition).thenNode(partialNode).build();
    IfBlock rewrittenIfBlock = IfBlock.builder().condition(condition).thenNode(rewrittenNode).build();
    BranchNode partialBranchNode = BranchNode.builder().ifElse(IfElseBlock.builder().case_(partialIfBlock).other(ImmutableList.of(partialIfBlock)).elseNode(partialNode).build()).build();
    BranchNode rewrittenBranchNode = BranchNode.builder().ifElse(IfElseBlock.builder().case_(rewrittenIfBlock).other(ImmutableList.of(rewrittenIfBlock)).elseNode(rewrittenNode).build()).build();
    assertThat(rewriter.visitor().visitBranchNode(partialBranchNode), equalTo(rewrittenBranchNode));
}
Also used : ComparisonExpression(org.flyte.api.v1.ComparisonExpression) BooleanExpression(org.flyte.api.v1.BooleanExpression) TaskNode(org.flyte.api.v1.TaskNode) BranchNode(org.flyte.api.v1.BranchNode) TaskNode(org.flyte.api.v1.TaskNode) BranchNode(org.flyte.api.v1.BranchNode) WorkflowNode(org.flyte.api.v1.WorkflowNode) Node(org.flyte.api.v1.Node) PartialTaskIdentifier(org.flyte.api.v1.PartialTaskIdentifier) IfBlock(org.flyte.api.v1.IfBlock) Test(org.junit.jupiter.api.Test)

Aggregations

BranchNode (org.flyte.api.v1.BranchNode)2 ComparisonExpression (org.flyte.api.v1.ComparisonExpression)2 IfBlock (org.flyte.api.v1.IfBlock)2 Test (org.junit.jupiter.api.Test)2 Condition (flyteidl.core.Condition)1 Workflow (flyteidl.core.Workflow)1 BooleanExpression (org.flyte.api.v1.BooleanExpression)1 IfElseBlock (org.flyte.api.v1.IfElseBlock)1 Node (org.flyte.api.v1.Node)1 PartialTaskIdentifier (org.flyte.api.v1.PartialTaskIdentifier)1 TaskNode (org.flyte.api.v1.TaskNode)1 WorkflowNode (org.flyte.api.v1.WorkflowNode)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1