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

aglinxinyuan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/texera.git


The following commit(s) were added to refs/heads/main by this push:
     new 8748b14a36 fix: Duplicate JSONToMap in JSONUtils and JSONUtil   (#4977)
8748b14a36 is described below

commit 8748b14a36aabef6ee02fc109cd407945c5bdd36
Author: Matthew B. <[email protected]>
AuthorDate: Thu May 7 16:13:26 2026 -0700

    fix: Duplicate JSONToMap in JSONUtils and JSONUtil   (#4977)
    
    <!--
    Thanks for sending a pull request (PR)! Here are some tips for you:
    1. If this is your first time, please read our contributor guidelines:
    [Contributing to
    Texera](https://github.com/apache/texera/blob/main/CONTRIBUTING.md)
      2. Ensure you have added or run the appropriate tests for your PR
      3. If the PR is work in progress, mark it a draft on GitHub.
      4. Please write your PR title to summarize what this PR proposes, we
        are following Conventional Commits style for PR titles as well.
      5. Be sure to keep the PR description updated to reflect all changes.
    -->
    
    ### What changes were proposed in this PR?
    `JSONToMap` was duplicated byte-for-byte in `JSONUtils.scala`
    (workflow-core) and `JSONUtil.scala` (workflow-operator). Deleted the
    workflow-operator copy and updated `JSONLScanSourceOpExec` to import
    from `JSONUtils`.
    
    
    ### Any related issues, documentation, discussions?
    
    closes: #4813
    
    ### How was this PR tested?
     Existing `JSONLScanSourceOpExec` tests. No behavior change
    
    ### Was this PR authored or co-authored using generative AI tooling?
    <!--
    If generative AI tooling has been used in the process of authoring this
    PR,
    please include the phrase: 'Generated-by: ' followed by the name of the
    tool
    and its version. If no, write 'No'.
    Please refer to the [ASF Generative Tooling
    Guidance](https://www.apache.org/legal/generative-tooling.html) for
    details.
    -->
    Co-authored by Claude Opus 4.7 in compliance with ASF
---
 .../source/scan/json/JSONLScanSourceOpExec.scala   |  3 +-
 .../amber/operator/source/scan/json/JSONUtil.scala | 72 ----------------------
 2 files changed, 1 insertion(+), 74 deletions(-)

diff --git 
a/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/source/scan/json/JSONLScanSourceOpExec.scala
 
b/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/source/scan/json/JSONLScanSourceOpExec.scala
index c96278c3e3..3c47796892 100644
--- 
a/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/source/scan/json/JSONLScanSourceOpExec.scala
+++ 
b/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/source/scan/json/JSONLScanSourceOpExec.scala
@@ -23,8 +23,7 @@ import 
org.apache.texera.amber.core.executor.SourceOperatorExecutor
 import org.apache.texera.amber.core.storage.DocumentFactory
 import org.apache.texera.amber.core.tuple.AttributeTypeUtils.parseField
 import org.apache.texera.amber.core.tuple.TupleLike
-import org.apache.texera.amber.operator.source.scan.json.JSONUtil.JSONToMap
-import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.apache.texera.amber.util.JSONUtils.{JSONToMap, objectMapper}
 
 import java.io.{BufferedReader, InputStreamReader}
 import java.net.URI
diff --git 
a/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/source/scan/json/JSONUtil.scala
 
b/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/source/scan/json/JSONUtil.scala
deleted file mode 100644
index d5c7f2b4e4..0000000000
--- 
a/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/source/scan/json/JSONUtil.scala
+++ /dev/null
@@ -1,72 +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.operator.source.scan.json
-
-import com.fasterxml.jackson.databind.JsonNode
-
-import scala.jdk.CollectionConverters.IteratorHasAsScala
-
-object JSONUtil {
-
-  /**
-    * this method helps convert JSON into a key-value Map. By default it will 
only
-    * take the first level attributes of the JSON object, and ignore nested 
objects
-    * and arrays. For example:
-    * input JSON {"A" : "a", "B": 1, "C": 2.3, "D" :{"some":"object"}, "E": 
["1", "2"]}
-    * will be converted to Map[String, String]{"A" : "a", "B": "1", "C": 
"2.3"}.
-    *
-    * If flatten mode is enabled, then the nested objects and arrays will be 
converted
-    * to map recursively. The key will be the `parentName[index].childName`. 
For example:
-    * input JSON {"A" : "a", "B": 1, "C": 2.3, "D" :{"some":"object"}, "E": 
["X", "Y"]}
-    * will be converted to Map[String, String]{"A" : "a", "B": "1", "C": "2.3",
-    * "D.some":"object", "E1":"X", "E2":"Y"}.
-    *
-    * @param node       the JSONNode to convert.
-    * @param flatten    a boolean to toggle flatten mode.
-    * @param parentName the parent's name to pass into children's naming 
conversion.
-    * @return a Map[String, String] of all the key value pairs from the given 
JSONNode.
-    */
-  def JSONToMap(
-      node: JsonNode,
-      flatten: Boolean = false,
-      parentName: String = ""
-  ): Map[String, String] = {
-    var result = Map[String, String]()
-    if (node.isObject) {
-      for (key <- node.fieldNames().asScala) {
-        val child: JsonNode = node.get(key)
-        val absoluteKey = (if (parentName.nonEmpty) parentName + "." else "") 
+ key
-        if (flatten && (child.isObject || child.isArray)) {
-          result = result ++ JSONToMap(child, flatten, absoluteKey)
-        } else if (child.isValueNode) {
-          result = result + (absoluteKey -> child.asText())
-        } else {
-          // do nothing
-        }
-      }
-    } else if (node.isArray) {
-      for ((child, i) <- node.elements().asScala.zipWithIndex) {
-        result = result ++ JSONToMap(child, flatten, parentName + (i + 1))
-      }
-    }
-    result
-  }
-
-}

Reply via email to