This is an automated email from the ASF dual-hosted git repository.

aglinxinyuan pushed a commit to branch xinyuan-state-only
in repository https://gitbox.apache.org/repos/asf/texera.git


The following commit(s) were added to refs/heads/xinyuan-state-only by this 
push:
     new 74e2b1da7f update
74e2b1da7f is described below

commit 74e2b1da7fd08bda09dd8deb6edd3b4895e83500
Author: Xinyuan Lin <[email protected]>
AuthorDate: Wed Apr 29 18:35:39 2026 -0700

    update
---
 .../org/apache/texera/amber/core/state/State.scala | 24 +++++++++++++++-------
 .../apache/texera/amber/core/state/package.scala   | 24 ----------------------
 2 files changed, 17 insertions(+), 31 deletions(-)

diff --git 
a/common/workflow-core/src/main/scala/org/apache/texera/amber/core/state/State.scala
 
b/common/workflow-core/src/main/scala/org/apache/texera/amber/core/state/State.scala
index 8452bff354..70d6c92fff 100644
--- 
a/common/workflow-core/src/main/scala/org/apache/texera/amber/core/state/State.scala
+++ 
b/common/workflow-core/src/main/scala/org/apache/texera/amber/core/state/State.scala
@@ -26,6 +26,14 @@ import org.apache.texera.amber.util.JSONUtils.objectMapper
 import java.util.Base64
 import scala.jdk.CollectionConverters.IteratorHasAsScala
 
+final case class State(data: Map[String, Any]) {
+  def apply(key: String): Any = data(key)
+
+  def get(key: String): Option[Any] = data.get(key)
+
+  def updated(key: String, value: Any): State = State(data.updated(key, value))
+}
+
 object StateJson {
   private val StateContent = "content"
   private val BytesTypeMarker = "__texera_type__"
@@ -37,18 +45,20 @@ object StateJson {
   )
 
   def serialize(state: State): Tuple = {
-    val payloadJson = objectMapper.writeValueAsString(toJsonValue(state))
+    val payloadJson = objectMapper.writeValueAsString(toJsonValue(state.data))
     Tuple.builder(schema).addSequentially(Array(payloadJson)).build()
   }
 
   def deserialize(tuple: Tuple): State = {
     val payload = tuple.getField[String](StateContent)
-    objectMapper
-      .readTree(payload)
-      .fields()
-      .asScala
-      .map(entry => entry.getKey -> fromJsonValue(entry.getValue))
-      .toMap
+    State(
+      objectMapper
+        .readTree(payload)
+        .fields()
+        .asScala
+        .map(entry => entry.getKey -> fromJsonValue(entry.getValue))
+        .toMap
+    )
   }
 
   private def toJsonValue(value: Any): Any =
diff --git 
a/common/workflow-core/src/main/scala/org/apache/texera/amber/core/state/package.scala
 
b/common/workflow-core/src/main/scala/org/apache/texera/amber/core/state/package.scala
deleted file mode 100644
index c110f9d814..0000000000
--- 
a/common/workflow-core/src/main/scala/org/apache/texera/amber/core/state/package.scala
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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
-
-package object state {
-  type State = Map[String, Any]
-}

Reply via email to