Xiao-zhen-Liu commented on code in PR #8639: URL: https://github.com/apache/texera/pull/8639#discussion_r4126398998
########## common/workflow-core/src/main/scala/org/apache/texera/amber/core/executor/LateBoundExecutor.scala: ########## @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.texera.amber.core.executor + +import com.fasterxml.jackson.core.JsonPointer +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.{ArrayNode, JsonNodeFactory, ObjectNode} +import org.apache.texera.amber.core.state.State +import org.apache.texera.amber.core.state.StateReferencing.SIDECAR_PROPERTY +import org.apache.texera.amber.core.tuple.{Tuple, TupleLike} +import org.apache.texera.amber.core.workflow.PortIdentity +import org.apache.texera.amber.util.JSONUtils.objectMapper + +import java.lang.reflect.InvocationTargetException +import scala.collection.mutable +import scala.jdk.CollectionConverters.IteratorHasAsScala +import scala.util.Try + +/** + * What a worker holds for an operator whose descriptor's `stateReferences` sidecar maps the JSON + * pointer of each placeholder to a loop variable. + * + * Unbound, it keeps and forwards each state message. It binds when the real executor is first + * needed, at a tuple or a finishing port: a channel carries its state messages ahead of its + * tuples, so every message has arrived by then. Their values are merged, a later one winning, so + * in a nested loop, whose inner body receives the outer loop's state first, an inner variable + * shadows an outer one of the same name. Each placeholder takes its variable's value, coerced to + * the placeholder's JSON type; the real executor is built through the normal factory path, + * opened, and shown the kept messages in order, as it would have seen them without references + * (what it returns for them is dropped: they were already forwarded as received). It is never + * rebound: workers are recreated for each iteration. + */ +class LateBoundExecutor private[executor] ( Review Comment: When we discussed this, the plan was to keep `$n` as a placeholder in the operator's setting and set it when the state arrives. This class does something else: it stands in for the operator, keeps the state messages, and builds the real executor only at the first tuple, from a copy of the descriptor with the values written in. Why is the wrapper needed? What goes wrong if the value is set in the operator's setting when the state arrives? The wrapper also changes the lifecycle of every operator that refers to a loop variable: `open()` runs at the first tuple instead of when the worker starts, `produceStateOnStart` is skipped, and the wrapper forwards the states that arrive before the first tuple itself, so what the operator returns for them is dropped. If the wrapper stays, please say why in the PR description. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
