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

hansva 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 0c8167d95d Use trim type applied in transform and ignore field 
trimtype, fixes #6208 (#6346)
0c8167d95d is described below

commit 0c8167d95d9dd45c22873854dd8b880b27cd238f
Author: Hans Van Akelyen <[email protected]>
AuthorDate: Mon Jan 12 16:39:42 2026 +0100

    Use trim type applied in transform and ignore field trimtype, fixes #6208 
(#6346)
---
 .../transforms/0004-concat-with-trim.hpl           | 284 +++++++++++++++++++++
 .../datasets/golden-concat-with-trim.csv           |   3 +
 .../transforms/main-0004-concat-fields.hwf         |   4 +
 .../metadata/dataset/golden-concat-with-trim.json  |  40 +++
 .../unit-test/0004-concat-with-trim UNIT.json      |  43 ++++
 .../transforms/concatfields/ConcatFields.java      |  12 +-
 6 files changed, 384 insertions(+), 2 deletions(-)

diff --git a/integration-tests/transforms/0004-concat-with-trim.hpl 
b/integration-tests/transforms/0004-concat-with-trim.hpl
new file mode 100644
index 0000000000..c9821e01e0
--- /dev/null
+++ b/integration-tests/transforms/0004-concat-with-trim.hpl
@@ -0,0 +1,284 @@
+<?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>0004-concat-with-trim</name>
+    <name_sync_with_filename>Y</name_sync_with_filename>
+    <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>2021/01/15 11:20:00.108</created_date>
+    <modified_user>-</modified_user>
+    <modified_date>2021/01/15 11:20:00.108</modified_date>
+  </info>
+  <notepads>
+    <notepad>
+      <backgroundcolorblue>251</backgroundcolorblue>
+      <backgroundcolorgreen>232</backgroundcolorgreen>
+      <backgroundcolorred>201</backgroundcolorred>
+      <bordercolorblue>90</bordercolorblue>
+      <bordercolorgreen>58</bordercolorgreen>
+      <bordercolorred>14</bordercolorred>
+      <fontbold>N</fontbold>
+      <fontcolorblue>90</fontcolorblue>
+      <fontcolorgreen>58</fontcolorgreen>
+      <fontcolorred>14</fontcolorred>
+      <fontitalic>N</fontitalic>
+      <fontname>.AppleSystemUIFont</fontname>
+      <fontsize>13</fontsize>
+      <height>20</height>
+      <xloc>180</xloc>
+      <yloc>243</yloc>
+      <note>This concat should left trim the first field and trim both the 
second field</note>
+      <width>20</width>
+    </notepad>
+  </notepads>
+  <order>
+    <hop>
+      <from>concat with nothing</from>
+      <to>OUTPUT</to>
+      <enabled>Y</enabled>
+    </hop>
+    <hop>
+      <from>Dummy (do nothing)</from>
+      <to>concat with nothing</to>
+      <enabled>Y</enabled>
+    </hop>
+    <hop>
+      <from>dummy data</from>
+      <to>Set trim type to both on meta</to>
+      <enabled>Y</enabled>
+    </hop>
+    <hop>
+      <from>Set trim type to both on meta</from>
+      <to>Dummy (do nothing)</to>
+      <enabled>Y</enabled>
+    </hop>
+  </order>
+  <transform>
+    <name>Dummy (do nothing)</name>
+    <type>Dummy</type>
+    <description/>
+    <distribute>Y</distribute>
+    <custom_distribution/>
+    <copies>1</copies>
+    <partitioning>
+      <method>none</method>
+      <schema_name/>
+    </partitioning>
+    <attributes/>
+    <GUI>
+      <xloc>464</xloc>
+      <yloc>80</yloc>
+    </GUI>
+  </transform>
+  <transform>
+    <name>OUTPUT</name>
+    <type>Dummy</type>
+    <description/>
+    <distribute>Y</distribute>
+    <custom_distribution/>
+    <copies>1</copies>
+    <partitioning>
+      <method>none</method>
+      <schema_name/>
+    </partitioning>
+    <attributes/>
+    <GUI>
+      <xloc>800</xloc>
+      <yloc>80</yloc>
+    </GUI>
+  </transform>
+  <transform>
+    <name>Set trim type to both on meta</name>
+    <type>UserDefinedJavaClass</type>
+    <description/>
+    <distribute>Y</distribute>
+    <custom_distribution/>
+    <copies>1</copies>
+    <partitioning>
+      <method>none</method>
+      <schema_name/>
+    </partitioning>
+    <definitions>
+      <definition>
+        <class_type>TRANSFORM_CLASS</class_type>
+        <class_name>Processor</class_name>
+        <class_source>import org.apache.hop.core.exception.HopException;
+import org.apache.hop.core.row.IValueMeta;
+
+public boolean processRow() throws HopException {
+  
+  // Get the next input row
+  Object[] r = getRow();
+  
+  // If no more rows, we're done
+  if (r == null) {
+    setOutputDone();
+    return false;
+  }
+  
+  // On first row, set up output row metadata with trim type
+  if (first) {
+    first = false;
+    
+    // Clone the input row structure
+    data.outputRowMeta = getInputRowMeta().clone();
+    
+    // Set trim type to BOTH on all string fields
+    for (int i = 0; i &lt; data.outputRowMeta.size(); i++) {
+      IValueMeta valueMeta = data.outputRowMeta.getValueMeta(i);
+      
+      // Only set trim type on String fields
+      if (valueMeta.getType() == IValueMeta.TYPE_STRING) {
+        valueMeta.setTrimType(IValueMeta.TRIM_TYPE_BOTH);
+      }
+    }
+  }
+  
+  // Pass the row through with updated metadata
+  putRow(data.outputRowMeta, r);
+  
+  return true;
+}</class_source>
+      </definition>
+    </definitions>
+    <fields>
+    </fields>
+    <clear_result_fields>N</clear_result_fields>
+    <info_transforms/>
+    <target_transforms/>
+    <usage_parameters/>
+    <attributes/>
+    <GUI>
+      <xloc>256</xloc>
+      <yloc>80</yloc>
+    </GUI>
+  </transform>
+  <transform>
+    <name>concat with nothing</name>
+    <type>ConcatFields</type>
+    <description/>
+    <distribute>Y</distribute>
+    <custom_distribution/>
+    <copies>1</copies>
+    <partitioning>
+      <method>none</method>
+      <schema_name/>
+    </partitioning>
+    <ConcatFields>
+      <removeSelectedFields>N</removeSelectedFields>
+      <targetFieldLength>500</targetFieldLength>
+      <targetFieldName>fields</targetFieldName>
+    </ConcatFields>
+    <enclosure>"</enclosure>
+    <fields>
+      <field>
+        <length>-1</length>
+        <name>fields</name>
+        <precision>-1</precision>
+        <trim_type>left</trim_type>
+        <type>String</type>
+      </field>
+      <field>
+        <length>-1</length>
+        <name>to</name>
+        <precision>-1</precision>
+        <trim_type>none</trim_type>
+        <type>String</type>
+      </field>
+      <field>
+        <length>-1</length>
+        <name>concat</name>
+        <precision>-1</precision>
+        <trim_type>none</trim_type>
+        <type>String</type>
+      </field>
+    </fields>
+    <force_enclosure>N</force_enclosure>
+    <attributes/>
+    <GUI>
+      <xloc>640</xloc>
+      <yloc>80</yloc>
+    </GUI>
+  </transform>
+  <transform>
+    <name>dummy data</name>
+    <type>DataGrid</type>
+    <description/>
+    <distribute>Y</distribute>
+    <custom_distribution/>
+    <copies>1</copies>
+    <partitioning>
+      <method>none</method>
+      <schema_name/>
+    </partitioning>
+    <data>
+      <line>
+        <item>data   </item>
+        <item>with</item>
+        <item>spaces   </item>
+      </line>
+      <line>
+        <item>    data   </item>
+        <item>with   </item>
+        <item>spaces</item>
+      </line>
+    </data>
+    <fields>
+      <field>
+        <length>-1</length>
+        <precision>-1</precision>
+        <set_empty_string>N</set_empty_string>
+        <name>fields</name>
+        <type>String</type>
+      </field>
+      <field>
+        <length>-1</length>
+        <precision>-1</precision>
+        <set_empty_string>N</set_empty_string>
+        <name>to</name>
+        <type>String</type>
+      </field>
+      <field>
+        <length>-1</length>
+        <precision>-1</precision>
+        <set_empty_string>N</set_empty_string>
+        <name>concat</name>
+        <type>String</type>
+      </field>
+    </fields>
+    <attributes/>
+    <GUI>
+      <xloc>96</xloc>
+      <yloc>80</yloc>
+    </GUI>
+  </transform>
+  <transform_error_handling>
+  </transform_error_handling>
+  <attributes/>
+</pipeline>
diff --git a/integration-tests/transforms/datasets/golden-concat-with-trim.csv 
b/integration-tests/transforms/datasets/golden-concat-with-trim.csv
new file mode 100644
index 0000000000..e2975aeba3
--- /dev/null
+++ b/integration-tests/transforms/datasets/golden-concat-with-trim.csv
@@ -0,0 +1,3 @@
+fields,to,concat,fields_1
+"data   ",with,"spaces   ","data   withspaces   "
+"    data   ","with   ",spaces,data   with   spaces
diff --git a/integration-tests/transforms/main-0004-concat-fields.hwf 
b/integration-tests/transforms/main-0004-concat-fields.hwf
index 5f056d5ef0..f219d12d15 100644
--- a/integration-tests/transforms/main-0004-concat-fields.hwf
+++ b/integration-tests/transforms/main-0004-concat-fields.hwf
@@ -36,6 +36,7 @@ limitations under the License.
       <type>SPECIAL</type>
       <attributes/>
       <DayOfMonth>1</DayOfMonth>
+      <doNotWaitOnFirstExecution>N</doNotWaitOnFirstExecution>
       <hour>12</hour>
       <intervalMinutes>60</intervalMinutes>
       <intervalSeconds>0</intervalSeconds>
@@ -66,6 +67,9 @@ limitations under the License.
         <test_name>
           <name>0004-concat-some-fields UNIT</name>
         </test_name>
+        <test_name>
+          <name>0004-concat-with-trim UNIT</name>
+        </test_name>
       </test_names>
       <parallel>N</parallel>
       <xloc>224</xloc>
diff --git 
a/integration-tests/transforms/metadata/dataset/golden-concat-with-trim.json 
b/integration-tests/transforms/metadata/dataset/golden-concat-with-trim.json
new file mode 100644
index 0000000000..dc04e50fc8
--- /dev/null
+++ b/integration-tests/transforms/metadata/dataset/golden-concat-with-trim.json
@@ -0,0 +1,40 @@
+{
+  "base_filename": "golden-concat-with-trim.csv",
+  "name": "golden-concat-with-trim",
+  "description": "",
+  "dataset_fields": [
+    {
+      "field_comment": "",
+      "field_length": -1,
+      "field_type": 2,
+      "field_precision": -1,
+      "field_name": "fields",
+      "field_format": ""
+    },
+    {
+      "field_comment": "",
+      "field_length": -1,
+      "field_type": 2,
+      "field_precision": -1,
+      "field_name": "to",
+      "field_format": ""
+    },
+    {
+      "field_comment": "",
+      "field_length": -1,
+      "field_type": 2,
+      "field_precision": -1,
+      "field_name": "concat",
+      "field_format": ""
+    },
+    {
+      "field_comment": "",
+      "field_length": 500,
+      "field_type": 2,
+      "field_precision": -1,
+      "field_name": "fields_1",
+      "field_format": ""
+    }
+  ],
+  "folder_name": ""
+}
\ No newline at end of file
diff --git 
a/integration-tests/transforms/metadata/unit-test/0004-concat-with-trim 
UNIT.json 
b/integration-tests/transforms/metadata/unit-test/0004-concat-with-trim 
UNIT.json
new file mode 100644
index 0000000000..59065f1f92
--- /dev/null
+++ b/integration-tests/transforms/metadata/unit-test/0004-concat-with-trim 
UNIT.json   
@@ -0,0 +1,43 @@
+{
+  "database_replacements": [],
+  "autoOpening": true,
+  "description": "",
+  "persist_filename": "",
+  "test_type": "UNIT_TEST",
+  "variableValues": [],
+  "basePath": "${HOP_UNIT_TESTS_FOLDER}",
+  "golden_data_sets": [
+    {
+      "field_mappings": [
+        {
+          "transform_field": "fields",
+          "data_set_field": "fields"
+        },
+        {
+          "transform_field": "to",
+          "data_set_field": "to"
+        },
+        {
+          "transform_field": "concat",
+          "data_set_field": "concat"
+        },
+        {
+          "transform_field": "fields_1",
+          "data_set_field": "fields_1"
+        }
+      ],
+      "field_order": [
+        "fields",
+        "to",
+        "concat",
+        "fields_1"
+      ],
+      "data_set_name": "golden-concat-with-trim",
+      "transform_name": "OUTPUT"
+    }
+  ],
+  "input_data_sets": [],
+  "name": "0004-concat-with-trim UNIT",
+  "trans_test_tweaks": [],
+  "pipeline_filename": "./0004-concat-with-trim.hpl"
+}
\ No newline at end of file
diff --git 
a/plugins/transforms/concatfields/src/main/java/org/apache/hop/pipeline/transforms/concatfields/ConcatFields.java
 
b/plugins/transforms/concatfields/src/main/java/org/apache/hop/pipeline/transforms/concatfields/ConcatFields.java
index 49eb7d900e..580b061dbf 100644
--- 
a/plugins/transforms/concatfields/src/main/java/org/apache/hop/pipeline/transforms/concatfields/ConcatFields.java
+++ 
b/plugins/transforms/concatfields/src/main/java/org/apache/hop/pipeline/transforms/concatfields/ConcatFields.java
@@ -186,9 +186,17 @@ public class ConcatFields extends 
BaseTransform<ConcatFieldsMeta, ConcatFieldsDa
       targetField.append(nullString);
     } else {
       if (trimType != null) {
+        // Get the raw string value without applying the incoming field's trim 
type
+        // by temporarily setting trim type to NONE
+        int originalTrimType = valueMeta.getTrimType();
+        valueMeta.setTrimType(IValueMeta.TRIM_TYPE_NONE);
+        String stringValue = valueMeta.getString(valueData);
+        // Restore the original trim type
+        valueMeta.setTrimType(originalTrimType);
+
+        // Apply only the configured trim type from the transform
         targetField.append(
-            Const.trimToType(
-                valueMeta.getString(valueData), 
ValueMetaBase.getTrimTypeByCode(trimType)));
+            Const.trimToType(stringValue, 
ValueMetaBase.getTrimTypeByCode(trimType)));
       }
     }
     if (meta.isForceEnclosure()) {

Reply via email to