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

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


The following commit(s) were added to refs/heads/main by this push:
     new 7b405e0e6b Neo4j: a Graph value converts from the JSON text it is 
written as, fixes #9559 (#9562)
7b405e0e6b is described below

commit 7b405e0e6b494237863bd060b8736b8d8b2ed82d
Author: Hans Van Akelyen <[email protected]>
AuthorDate: Thu Nov 19 08:10:32 2026 +0100

    Neo4j: a Graph value converts from the JSON text it is written as, fixes 
#9559 (#9562)
---
 .../transforms/0130-graph-convert.hpl              | 198 +++++++++++++++++++++
 .../datasets/golden-0130-graph-convert.csv         |   4 +
 .../transforms/main-0130-graph-convert.hwf         |  80 +++++++++
 .../dataset/golden-0130-graph-convert.json         |  24 +++
 .../unit-test/0130-graph-convert UNIT.json         |  32 ++++
 .../hop/neo4j/core/value/ValueMetaGraph.java       |  29 +++
 .../hop/neo4j/core/value/ValueMetaGraphTest.java   | 105 +++++++++++
 7 files changed, 472 insertions(+)

diff --git a/integration-tests/transforms/0130-graph-convert.hpl 
b/integration-tests/transforms/0130-graph-convert.hpl
new file mode 100644
index 0000000000..d57320cccf
--- /dev/null
+++ b/integration-tests/transforms/0130-graph-convert.hpl
@@ -0,0 +1,198 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+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.
+
+-->
+<pipeline>
+  <info>
+    <name>0130-graph-convert</name>
+    <name_sync_with_filename>Y</name_sync_with_filename>
+    <description>Select values converts text holding a graph to a Graph field 
and back (#9559)</description>
+    <extended_description/>
+    <pipeline_version/>
+    <pipeline_type>Normal</pipeline_type>
+    <parameters>
+    </parameters>
+    <capture_transform_performance>N</capture_transform_performance>
+    
<transform_performance_capturing_delay>1000</transform_performance_capturing_delay>
+    
<transform_performance_capturing_size_limit>100</transform_performance_capturing_size_limit>
+    <created_user>-</created_user>
+    <created_date>2026/11/18 12:00:00.000</created_date>
+    <modified_user>-</modified_user>
+    <modified_date>2026/11/18 12:00:00.000</modified_date>
+  </info>
+  <notepads>
+  </notepads>
+  <order>
+    <hop>
+      <from>text</from>
+      <to>text to graph</to>
+      <enabled>Y</enabled>
+    </hop>
+    <hop>
+      <from>text to graph</from>
+      <to>graph to text</to>
+      <enabled>Y</enabled>
+    </hop>
+    <hop>
+      <from>graph to text</from>
+      <to>validate</to>
+      <enabled>Y</enabled>
+    </hop>
+  </order>
+  <transform>
+    <name>text</name>
+    <type>DataGrid</type>
+    <description/>
+    <distribute>Y</distribute>
+    <custom_distribution/>
+    <copies>1</copies>
+    <partitioning>
+      <method>none</method>
+      <schema_name/>
+    </partitioning>
+    <fields>
+      <field>
+        <set_empty_string>N</set_empty_string>
+        <length>-1</length>
+        <name>id</name>
+        <precision>-1</precision>
+        <type>Integer</type>
+      </field>
+      <field>
+        <set_empty_string>N</set_empty_string>
+        <length>-1</length>
+        <name>text</name>
+        <precision>-1</precision>
+        <type>String</type>
+      </field>
+    </fields>
+    <data>
+      <line>
+        <item>1</item>
+        
<item>{"relationships":[{"property_set":null,"sourceNodeId":"n1","id":"r1","label":"KNOWS","targetNodeId":"n2","properties":[{"id":"since","type":"Integer","value":1843}]}],"nodes":[{"property_set":null,"id":"n1","properties":[{"id":"name","type":"String","value":"Ada","primary":true}],"labels":["Person"]},{"property_set":null,"id":"n2","properties":[{"id":"name","type":"String","value":"Grace","primary":true}],"labels":["Person"]}],"source_transform":null,"source_pipeline":null}</item>
+      </line>
+      <line>
+        <item>2</item>
+        
<item>{"relationships":[],"nodes":[{"property_set":null,"id":"n9","properties":[],"labels":["Thing"]}],"source_transform":null,"source_pipeline":null}</item>
+      </line>
+      <line>
+        <item>3</item>
+        <item/>
+      </line>
+    </data>
+    <attributes/>
+    <GUI>
+      <xloc>96</xloc>
+      <yloc>96</yloc>
+    </GUI>
+  </transform>
+  <transform>
+    <name>text to graph</name>
+    <type>SelectValues</type>
+    <description/>
+    <distribute>Y</distribute>
+    <custom_distribution/>
+    <copies>1</copies>
+    <partitioning>
+      <method>none</method>
+      <schema_name/>
+    </partitioning>
+    <fields>
+      <select_unspecified>N</select_unspecified>
+      <meta>
+        <name>text</name>
+        <rename>graph</rename>
+        <type>Graph</type>
+        <length>-2</length>
+        <precision>-2</precision>
+        <conversion_mask/>
+        <date_format_lenient>false</date_format_lenient>
+        <date_format_locale/>
+        <date_format_timezone/>
+        <lenient_string_to_number>false</lenient_string_to_number>
+        <encoding/>
+        <decimal_symbol/>
+        <grouping_symbol/>
+        <currency_symbol/>
+        <storage_type/>
+      </meta>
+    </fields>
+    <attributes/>
+    <GUI>
+      <xloc>288</xloc>
+      <yloc>96</yloc>
+    </GUI>
+  </transform>
+  <transform>
+    <name>graph to text</name>
+    <type>SelectValues</type>
+    <description/>
+    <distribute>Y</distribute>
+    <custom_distribution/>
+    <copies>1</copies>
+    <partitioning>
+      <method>none</method>
+      <schema_name/>
+    </partitioning>
+    <fields>
+      <select_unspecified>N</select_unspecified>
+      <meta>
+        <name>graph</name>
+        <rename>text_out</rename>
+        <type>String</type>
+        <length>-2</length>
+        <precision>-2</precision>
+        <conversion_mask/>
+        <date_format_lenient>false</date_format_lenient>
+        <date_format_locale/>
+        <date_format_timezone/>
+        <lenient_string_to_number>false</lenient_string_to_number>
+        <encoding/>
+        <decimal_symbol/>
+        <grouping_symbol/>
+        <currency_symbol/>
+        <storage_type/>
+      </meta>
+    </fields>
+    <attributes/>
+    <GUI>
+      <xloc>480</xloc>
+      <yloc>96</yloc>
+    </GUI>
+  </transform>
+  <transform>
+    <name>validate</name>
+    <type>Dummy</type>
+    <description/>
+    <distribute>Y</distribute>
+    <custom_distribution/>
+    <copies>1</copies>
+    <partitioning>
+      <method>none</method>
+      <schema_name/>
+    </partitioning>
+    <attributes/>
+    <GUI>
+      <xloc>672</xloc>
+      <yloc>96</yloc>
+    </GUI>
+  </transform>
+  <transform_error_handling>
+  </transform_error_handling>
+  <attributes/>
+</pipeline>
diff --git 
a/integration-tests/transforms/datasets/golden-0130-graph-convert.csv 
b/integration-tests/transforms/datasets/golden-0130-graph-convert.csv
new file mode 100644
index 0000000000..cf41306e40
--- /dev/null
+++ b/integration-tests/transforms/datasets/golden-0130-graph-convert.csv
@@ -0,0 +1,4 @@
+id,text_out
+1,"{""relationships"":[{""property_set"":null,""sourceNodeId"":""n1"",""id"":""r1"",""label"":""KNOWS"",""targetNodeId"":""n2"",""properties"":[{""id"":""since"",""type"":""Integer"",""value"":1843}]}],""nodes"":[{""property_set"":null,""id"":""n1"",""properties"":[{""id"":""name"",""type"":""String"",""value"":""Ada"",""primary"":true}],""labels"":[""Person""]},{""property_set"":null,""id"":""n2"",""properties"":[{""id"":""name"",""type"":""String"",""value"":""Grace"",""primary"":true}
 [...]
+2,"{""relationships"":[],""nodes"":[{""property_set"":null,""id"":""n9"",""properties"":[],""labels"":[""Thing""]}],""source_transform"":null,""source_pipeline"":null}"
+3,
diff --git a/integration-tests/transforms/main-0130-graph-convert.hwf 
b/integration-tests/transforms/main-0130-graph-convert.hwf
new file mode 100644
index 0000000000..607d97e908
--- /dev/null
+++ b/integration-tests/transforms/main-0130-graph-convert.hwf
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+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.
+
+-->
+<workflow>
+  <name>main-0130-graph-convert</name>
+  <name_sync_with_filename>Y</name_sync_with_filename>
+  <description/>
+  <extended_description/>
+  <workflow_version/>
+  <created_user>-</created_user>
+  <created_date>2026/11/18 12:00:00.000</created_date>
+  <modified_user>-</modified_user>
+  <modified_date>2026/11/18 12:00:00.000</modified_date>
+  <parameters>
+    </parameters>
+  <actions>
+    <action>
+      <name>Start</name>
+      <description/>
+      <type>SPECIAL</type>
+      <attributes/>
+      <DayOfMonth>1</DayOfMonth>
+      <doNotWaitOnFirstExecution>N</doNotWaitOnFirstExecution>
+      <hour>12</hour>
+      <intervalMinutes>60</intervalMinutes>
+      <intervalSeconds>0</intervalSeconds>
+      <minutes>0</minutes>
+      <repeat>N</repeat>
+      <schedulerType>0</schedulerType>
+      <weekDay>1</weekDay>
+      <parallel>N</parallel>
+      <xloc>96</xloc>
+      <yloc>64</yloc>
+      <attributes_hac/>
+    </action>
+    <action>
+      <name>0130-graph-convert UNIT</name>
+      <description/>
+      <type>RunPipelineTests</type>
+      <attributes/>
+      <test_names>
+        <test_name>
+          <name>0130-graph-convert UNIT</name>
+        </test_name>
+      </test_names>
+      <parallel>N</parallel>
+      <xloc>288</xloc>
+      <yloc>64</yloc>
+      <attributes_hac/>
+    </action>
+  </actions>
+  <hops>
+    <hop>
+      <from>Start</from>
+      <to>0130-graph-convert UNIT</to>
+      <enabled>Y</enabled>
+      <evaluation>Y</evaluation>
+      <unconditional>Y</unconditional>
+    </hop>
+  </hops>
+  <notepads>
+  </notepads>
+  <attributes/>
+</workflow>
diff --git 
a/integration-tests/transforms/metadata/dataset/golden-0130-graph-convert.json 
b/integration-tests/transforms/metadata/dataset/golden-0130-graph-convert.json
new file mode 100644
index 0000000000..a8a2582e54
--- /dev/null
+++ 
b/integration-tests/transforms/metadata/dataset/golden-0130-graph-convert.json
@@ -0,0 +1,24 @@
+{
+  "base_filename": "golden-0130-graph-convert.csv",
+  "name": "golden-0130-graph-convert",
+  "description": "The graph text comes back unchanged after a round trip 
through a Graph field; empty text stays empty",
+  "dataset_fields": [
+    {
+      "field_comment": "",
+      "field_length": -1,
+      "field_type": 5,
+      "field_precision": -1,
+      "field_name": "id",
+      "field_format": ""
+    },
+    {
+      "field_comment": "",
+      "field_length": -1,
+      "field_type": 2,
+      "field_precision": -1,
+      "field_name": "text_out",
+      "field_format": ""
+    }
+  ],
+  "folder_name": ""
+}
diff --git a/integration-tests/transforms/metadata/unit-test/0130-graph-convert 
UNIT.json b/integration-tests/transforms/metadata/unit-test/0130-graph-convert 
UNIT.json
new file mode 100644
index 0000000000..9b9a7ecf7e
--- /dev/null
+++ b/integration-tests/transforms/metadata/unit-test/0130-graph-convert 
UNIT.json      
@@ -0,0 +1,32 @@
+{
+  "database_replacements": [],
+  "autoOpening": true,
+  "description": "",
+  "persist_filename": "",
+  "test_type": "UNIT_TEST",
+  "variableValues": [],
+  "basePath": "${HOP_UNIT_TESTS_FOLDER}",
+  "golden_data_sets": [
+    {
+      "field_mappings": [
+        {
+          "transform_field": "id",
+          "data_set_field": "id"
+        },
+        {
+          "transform_field": "text_out",
+          "data_set_field": "text_out"
+        }
+      ],
+      "field_order": [
+        "id"
+      ],
+      "data_set_name": "golden-0130-graph-convert",
+      "transform_name": "validate"
+    }
+  ],
+  "input_data_sets": [],
+  "name": "0130-graph-convert UNIT",
+  "trans_test_tweaks": [],
+  "pipeline_filename": "./0130-graph-convert.hpl"
+}
diff --git 
a/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/core/value/ValueMetaGraph.java
 
b/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/core/value/ValueMetaGraph.java
index 3df46e383f..eae0609b19 100644
--- 
a/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/core/value/ValueMetaGraph.java
+++ 
b/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/core/value/ValueMetaGraph.java
@@ -20,6 +20,7 @@ package org.apache.hop.neo4j.core.value;
 
 import org.apache.hop.core.exception.HopException;
 import org.apache.hop.core.exception.HopValueException;
+import org.apache.hop.core.row.IValueMeta;
 import org.apache.hop.core.row.ValueDataUtil;
 import org.apache.hop.core.row.value.ValueMetaBase;
 import org.apache.hop.core.row.value.ValueMetaPlugin;
@@ -212,6 +213,34 @@ public class ValueMetaGraph extends ValueMetaBase {
     }
   }
 
+  /**
+   * A graph from another value: a graph is copied, text is read as the JSON 
{@link #getString}
+   * writes. An engine that moves rows between machines as text (native Spark) 
gets its graph back
+   * this way.
+   */
+  @Override
+  public Object convertData(IValueMeta meta2, Object data2) throws 
HopValueException {
+    if (data2 == null) {
+      return null;
+    }
+    if (meta2 != null && meta2.getType() == TYPE_GRAPH) {
+      return new GraphData((GraphData) data2);
+    }
+    if (meta2 != null && meta2.isString()) {
+      String json = meta2.getString(data2);
+      if (json == null || json.isEmpty()) {
+        return null;
+      }
+      try {
+        return new GraphData(json);
+      } catch (Exception e) {
+        throw new HopValueException(
+            toString() + " : unable to read a graph from text '" + json + "'", 
e);
+      }
+    }
+    throw new HopValueException(toString() + " : unable to convert " + meta2 + 
" data to a graph");
+  }
+
   @Override
   public Object cloneValueData(Object object) throws HopValueException {
     if (object == null) {
diff --git 
a/plugins/tech/neo4j/src/test/java/org/apache/hop/neo4j/core/value/ValueMetaGraphTest.java
 
b/plugins/tech/neo4j/src/test/java/org/apache/hop/neo4j/core/value/ValueMetaGraphTest.java
new file mode 100644
index 0000000000..c8cb53d1e8
--- /dev/null
+++ 
b/plugins/tech/neo4j/src/test/java/org/apache/hop/neo4j/core/value/ValueMetaGraphTest.java
@@ -0,0 +1,105 @@
+/*
+ * 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.hop.neo4j.core.value;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.hop.core.exception.HopValueException;
+import org.apache.hop.core.row.IValueMeta;
+import org.apache.hop.core.row.value.ValueMetaInteger;
+import org.apache.hop.core.row.value.ValueMetaString;
+import org.apache.hop.neo4j.core.data.GraphData;
+import org.apache.hop.neo4j.core.data.GraphNodeData;
+import org.apache.hop.neo4j.core.data.GraphPropertyData;
+import org.apache.hop.neo4j.core.data.GraphPropertyDataType;
+import org.apache.hop.neo4j.core.data.GraphRelationshipData;
+import org.junit.jupiter.api.Test;
+
+/** A graph comes back from the text an engine carries it as. */
+class ValueMetaGraphTest {
+
+  private static GraphData graph() {
+    List<GraphPropertyData> properties = new ArrayList<>();
+    properties.add(new GraphPropertyData("name", "Neo", 
GraphPropertyDataType.String, true));
+    GraphNodeData neo = new GraphNodeData("n1", List.of("Person"), properties);
+    GraphNodeData trinity = new GraphNodeData("n2", List.of("Person"), new 
ArrayList<>());
+    GraphRelationshipData knows =
+        new GraphRelationshipData("r1", "KNOWS", new ArrayList<>(), "n1", 
"n2");
+    return new GraphData(List.of(neo, trinity), List.of(knows));
+  }
+
+  @Test
+  void aGraphComesBackFromItsText() throws Exception {
+    ValueMetaGraph valueMeta = new ValueMetaGraph("graph");
+    GraphData graph = graph();
+    String text = valueMeta.getString(graph);
+
+    Object back = valueMeta.convertData(new ValueMetaString("text"), text);
+
+    assertEquals(text, ((GraphData) back).toJsonString());
+  }
+
+  /** Text file input, CSV input and the like read a Graph field this way. */
+  @Test
+  void aGraphIsReadFromText() throws Exception {
+    ValueMetaGraph valueMeta = new ValueMetaGraph("graph");
+    String text = valueMeta.getString(graph());
+
+    Object read =
+        valueMeta.convertDataFromString(
+            text, new ValueMetaString("text"), null, null, 
IValueMeta.TRIM_TYPE_NONE);
+
+    assertEquals(text, ((GraphData) read).toJsonString());
+  }
+
+  @Test
+  void aGraphIsCopied() throws Exception {
+    ValueMetaGraph valueMeta = new ValueMetaGraph("graph");
+    GraphData graph = graph();
+
+    Object copy = valueMeta.convertData(new ValueMetaGraph("other"), graph);
+
+    assertEquals(graph.toJsonString(), ((GraphData) copy).toJsonString());
+    assertNotSame(graph, copy);
+  }
+
+  @Test
+  void emptyTextIsNoGraph() throws Exception {
+    ValueMetaGraph valueMeta = new ValueMetaGraph("graph");
+
+    assertNull(valueMeta.convertData(new ValueMetaString("text"), ""));
+    assertNull(valueMeta.convertData(new ValueMetaString("text"), null));
+  }
+
+  @Test
+  void textThatIsNoGraphOrAnotherTypeIsAnError() {
+    ValueMetaGraph valueMeta = new ValueMetaGraph("graph");
+
+    assertThrows(
+        HopValueException.class,
+        () -> valueMeta.convertData(new ValueMetaString("text"), "not json"));
+    assertThrows(
+        HopValueException.class, () -> valueMeta.convertData(new 
ValueMetaInteger("n"), 1L));
+  }
+}

Reply via email to