bamaer commented on code in PR #9367:
URL: https://github.com/apache/hop/pull/9367#discussion_r4539557596


##########
plugins/transforms/textchunker/src/main/java/org/apache/hop/pipeline/transforms/chunker/TextChunker.java:
##########
@@ -67,8 +66,21 @@ public boolean init() {
     if (!super.init()) {
       return false;
     }
-    data.chunkSize = Const.toInt(resolve(meta.getChunkSize()), -1);
-    data.chunkOverlap = Const.toInt(resolve(meta.getChunkOverlap()), -1);
+    String sizeText = resolve(meta.getChunkSize());
+    String overlapText = resolve(meta.getChunkOverlap());
+    Integer size = TextChunkerMeta.parseNumber(sizeText, 0);
+    Integer overlap = TextChunkerMeta.parseNumber(overlapText, 0);
+    if (size == null) {
+      logError(BaseMessages.getString(PKG, 
"TextChunker.Validation.ChunkSizeNotANumber", sizeText));
+      return false;
+    }
+    if (overlap == null) {
+      logError(
+          BaseMessages.getString(PKG, 
"TextChunker.Validation.OverlapNotANumber", overlapText));
+      return false;
+    }
+    data.chunkSize = size;
+    data.chunkOverlap = overlap;

Review Comment:
   Fixed in 4d2047c: a negative overlap now logs an error and stops the 
transform, same as `abc`.



##########
plugins/transforms/textchunker/src/main/java/org/apache/hop/pipeline/transforms/chunker/TextChunker.java:
##########
@@ -67,8 +66,21 @@ public boolean init() {
     if (!super.init()) {
       return false;
     }
-    data.chunkSize = Const.toInt(resolve(meta.getChunkSize()), -1);
-    data.chunkOverlap = Const.toInt(resolve(meta.getChunkOverlap()), -1);
+    String sizeText = resolve(meta.getChunkSize());

Review Comment:
   Done in 4d2047c: `TextChunkerMeta.validateChunkSettings()` holds the rules, 
and both `check()` and `init()` use it.



##########
plugins/transforms/textchunker/src/main/java/org/apache/hop/pipeline/transforms/chunker/TextChunkerMeta.java:
##########
@@ -326,14 +325,41 @@ public void getFields(
     }
   }
 
+  /**
+   * Adds an output field. When the input already has a field with that name 
the transform writes
+   * its values into that field, so the field takes the transform's type if 
the types differ.
+   */
   private static void addField(IRowMeta row, IValueMeta field, String origin)
       throws HopPluginException {
     String fieldName = field.getName();
-    if (fieldName == null || fieldName.isEmpty() || 
row.indexOfValue(fieldName) >= 0) {
+    if (fieldName == null || fieldName.isEmpty()) {
       return;
     }
     field.setOrigin(origin);
-    row.addValueMeta(field);
+    int index = row.indexOfValue(fieldName);
+    if (index < 0) {
+      row.addValueMeta(field);
+    } else if (row.getValueMeta(index).getType() != field.getType()) {

Review Comment:
   Agreed, fixed in 4d2047c: an existing field now always takes the output 
field's metadata. The test now uses a lazy-conversion (binary string) field and 
checks storage, mask and length.



##########
plugins/transforms/textchunker/src/main/java/org/apache/hop/pipeline/transforms/chunker/TextChunkerMeta.java:
##########
@@ -326,14 +325,41 @@ public void getFields(
     }
   }
 
+  /**
+   * Adds an output field. When the input already has a field with that name 
the transform writes
+   * its values into that field, so the field takes the transform's type if 
the types differ.
+   */
   private static void addField(IRowMeta row, IValueMeta field, String origin)
       throws HopPluginException {
     String fieldName = field.getName();
-    if (fieldName == null || fieldName.isEmpty() || 
row.indexOfValue(fieldName) >= 0) {
+    if (fieldName == null || fieldName.isEmpty()) {
       return;
     }
     field.setOrigin(origin);
-    row.addValueMeta(field);
+    int index = row.indexOfValue(fieldName);
+    if (index < 0) {
+      row.addValueMeta(field);
+    } else if (row.getValueMeta(index).getType() != field.getType()) {
+      row.setValueMeta(index, field);

Review Comment:
   Fixed in 4d2047c: the field is still matched case-insensitively, as 
elsewhere in Hop, but keeps its existing name, so `Chunk_Index` stays 
`Chunk_Index`.



##########
plugins/transforms/textchunker/src/main/java/org/apache/hop/pipeline/transforms/chunker/TextChunkerMeta.java:
##########
@@ -430,6 +466,38 @@ public void check(
     }
   }
 
+  /** Warns when an output field already exists in the input with a different 
type. */
+  private void checkOutputFieldTypes(
+      List<ICheckResult> remarks, TransformMeta transformMeta, IRowMeta prev) {
+    if (prev == null) {
+      return;
+    }
+    IRowMeta output = prev.clone();
+    try {
+      getFields(output, transformMeta.getName(), null, null, null, null);
+    } catch (HopTransformException e) {

Review Comment:
   Done in 4d2047c: it now adds an error remark with the exception message.



##########
plugins/transforms/textchunker/src/main/java/org/apache/hop/pipeline/transforms/chunker/TextChunkerMeta.java:
##########
@@ -430,6 +466,38 @@ public void check(
     }
   }
 
+  /** Warns when an output field already exists in the input with a different 
type. */
+  private void checkOutputFieldTypes(
+      List<ICheckResult> remarks, TransformMeta transformMeta, IRowMeta prev) {
+    if (prev == null) {
+      return;
+    }
+    IRowMeta output = prev.clone();
+    try {
+      getFields(output, transformMeta.getName(), null, null, null, null);
+    } catch (HopTransformException e) {
+      return;
+    }
+    for (String fieldName : getOutputFieldNames()) {

Review Comment:
   Done in 4d2047c, the names go through a `LinkedHashSet`.



##########
integration-tests/transforms/main-0126-text-chunker-invalid-overlap.hwf:
##########
@@ -0,0 +1,126 @@
+<?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-0126-text-chunker-invalid-overlap</name>
+  <name_sync_with_filename>Y</name_sync_with_filename>
+  <description>Text chunker: a chunk overlap that is not a number stops the 
transform instead of running with overlap 0 (#9285)</description>
+  <extended_description/>
+  <workflow_version/>
+  <created_user>-</created_user>
+  <created_date>2026/11/07 12:00:00.000</created_date>
+  <modified_user>-</modified_user>
+  <modified_date>2026/11/07 12:00:00.000</modified_date>
+  <parameters>
+    </parameters>
+  <actions>
+    <action>
+      <name>START</name>
+      <description/>
+      <type>SPECIAL</type>
+      <attributes/>
+      <repeat>N</repeat>
+      <schedulerType>0</schedulerType>
+      <intervalSeconds>0</intervalSeconds>
+      <intervalMinutes>60</intervalMinutes>
+      <hour>12</hour>
+      <minutes>0</minutes>
+      <weekDay>1</weekDay>
+      <DayOfMonth>1</DayOfMonth>
+      <parallel>N</parallel>
+      <xloc>96</xloc>
+      <yloc>80</yloc>
+      <attributes_hac/>
+    </action>
+    <action>
+      
<filename>${PROJECT_HOME}/0126-text-chunker-invalid-overlap.hpl</filename>
+      <params_from_previous>N</params_from_previous>
+      <exec_per_row>N</exec_per_row>
+      <clear_rows>N</clear_rows>
+      <clear_files>N</clear_files>
+      <create_parent_folder>N</create_parent_folder>
+      <set_logfile>N</set_logfile>
+      <set_append_logfile>N</set_append_logfile>
+      <add_date>N</add_date>
+      <add_time>N</add_time>
+      <loglevel>Basic</loglevel>
+      <wait_until_finished>Y</wait_until_finished>
+      <parameters>
+        <pass_all_parameters>Y</pass_all_parameters>
+      </parameters>
+      <run_configuration>local</run_configuration>
+      <name>0126-text-chunker-invalid-overlap.hpl</name>
+      <description>Expected to fail</description>
+      <type>PIPELINE</type>
+      <attributes/>
+      <xloc>320</xloc>
+      <yloc>80</yloc>
+      <parallel>N</parallel>
+      <attributes_hac/>
+    </action>
+    <action>
+      <name>Overlap 'abc' did not fail - Abort</name>
+      <description/>
+      <type>ABORT</type>
+      <attributes/>
+      <message>A chunk overlap of 'abc' did not stop the Text chunker</message>
+      <loglevel>Basic</loglevel>
+      <parallel>N</parallel>
+      <xloc>320</xloc>
+      <yloc>224</yloc>
+      <attributes_hac/>
+    </action>
+    <action>
+      <name>Success</name>
+      <description/>
+      <type>SUCCESS</type>
+      <attributes/>
+      <parallel>N</parallel>
+      <xloc>544</xloc>
+      <yloc>80</yloc>
+      <attributes_hac/>
+    </action>
+  </actions>
+  <hops>
+    <hop>
+      <from>START</from>
+      <to>0126-text-chunker-invalid-overlap.hpl</to>
+      <enabled>Y</enabled>
+      <evaluation>Y</evaluation>
+      <unconditional>Y</unconditional>
+    </hop>
+    <hop>
+      <from>0126-text-chunker-invalid-overlap.hpl</from>
+      <to>Overlap 'abc' did not fail - Abort</to>
+      <enabled>Y</enabled>
+      <evaluation>Y</evaluation>
+      <unconditional>N</unconditional>
+    </hop>
+    <hop>
+      <from>0126-text-chunker-invalid-overlap.hpl</from>

Review Comment:
   Good point. In 4d2047c each run writes its log to a file and a shell action 
greps for the expected message. The workflow now covers both `abc` and `-1`.



-- 
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]

Reply via email to