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 4b330aeb3a Filter rows clears the descending sort flag on the previous 
transform's row metadata, fixes  #9294 (#9295)
4b330aeb3a is described below

commit 4b330aeb3abef3fc79189c6517ec174ed1a3e588
Author: Hans Van Akelyen <[email protected]>
AuthorDate: Fri Nov 6 06:46:16 2026 +0100

    Filter rows clears the descending sort flag on the previous transform's row 
metadata, fixes  #9294 (#9295)
---
 .../pipeline/transforms/filterrows/FilterRows.java |  7 ++--
 .../transforms/filterrows/FilterRowsData.java      |  4 +++
 .../transforms/filterrows/FilterRowsTest.java      | 42 ++++++++++++++++++++++
 3 files changed, 51 insertions(+), 2 deletions(-)

diff --git 
a/plugins/transforms/filterrows/src/main/java/org/apache/hop/pipeline/transforms/filterrows/FilterRows.java
 
b/plugins/transforms/filterrows/src/main/java/org/apache/hop/pipeline/transforms/filterrows/FilterRows.java
index c28a9adde6..a2d0cdd58b 100644
--- 
a/plugins/transforms/filterrows/src/main/java/org/apache/hop/pipeline/transforms/filterrows/FilterRows.java
+++ 
b/plugins/transforms/filterrows/src/main/java/org/apache/hop/pipeline/transforms/filterrows/FilterRows.java
@@ -74,7 +74,10 @@ public class FilterRows extends 
BaseTransform<FilterRowsMeta, FilterRowsData> {
       first = false;
 
       data.outputRowMeta = getInputRowMeta().clone();
-      meta.getFields(getInputRowMeta(), getTransformName(), null, null, this, 
metadataProvider);
+      // getFields() clears sortedDescending on the condition fields, or the 
comparisons would be
+      // inverted. Do that on a private copy: getInputRowMeta() is shared with 
the hop.
+      data.conditionRowMeta = getInputRowMeta().clone();
+      meta.getFields(data.conditionRowMeta, getTransformName(), null, null, 
this, metadataProvider);
 
       // if filter refers to non-existing fields, throw exception
       checkNonExistingFields();
@@ -119,7 +122,7 @@ public class FilterRows extends 
BaseTransform<FilterRowsMeta, FilterRowsData> {
       }
     }
 
-    boolean keep = keepRow(getInputRowMeta(), r); // Keep this row?
+    boolean keep = keepRow(data.conditionRowMeta, r); // Keep this row?
     if (!data.chosesTargetTransforms) {
       if (keep) {
         putRow(data.outputRowMeta, r); // copy row to output rowset(s)
diff --git 
a/plugins/transforms/filterrows/src/main/java/org/apache/hop/pipeline/transforms/filterrows/FilterRowsData.java
 
b/plugins/transforms/filterrows/src/main/java/org/apache/hop/pipeline/transforms/filterrows/FilterRowsData.java
index f5ba59c5aa..612c7ec153 100644
--- 
a/plugins/transforms/filterrows/src/main/java/org/apache/hop/pipeline/transforms/filterrows/FilterRowsData.java
+++ 
b/plugins/transforms/filterrows/src/main/java/org/apache/hop/pipeline/transforms/filterrows/FilterRowsData.java
@@ -27,6 +27,10 @@ import org.apache.hop.pipeline.transform.ITransformData;
 public class FilterRowsData extends BaseTransformData implements 
ITransformData {
 
   public IRowMeta outputRowMeta;
+
+  /** The input row metadata with sortedDescending cleared, to evaluate the 
condition with. */
+  public IRowMeta conditionRowMeta;
+
   public IRowSet trueRowSet;
   public IRowSet falseRowSet;
   public boolean chosesTargetTransforms;
diff --git 
a/plugins/transforms/filterrows/src/test/java/org/apache/hop/pipeline/transforms/filterrows/FilterRowsTest.java
 
b/plugins/transforms/filterrows/src/test/java/org/apache/hop/pipeline/transforms/filterrows/FilterRowsTest.java
index 23254bcdb2..e2fa364028 100644
--- 
a/plugins/transforms/filterrows/src/test/java/org/apache/hop/pipeline/transforms/filterrows/FilterRowsTest.java
+++ 
b/plugins/transforms/filterrows/src/test/java/org/apache/hop/pipeline/transforms/filterrows/FilterRowsTest.java
@@ -25,6 +25,11 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNotSame;
 import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
 
 import java.math.BigDecimal;
 import java.sql.Timestamp;
@@ -33,6 +38,7 @@ import java.util.Date;
 import java.util.stream.Stream;
 import org.apache.hop.core.Condition;
 import org.apache.hop.core.HopEnvironment;
+import org.apache.hop.core.row.IRowMeta;
 import org.apache.hop.core.row.IValueMeta;
 import org.apache.hop.core.row.RowMeta;
 import org.apache.hop.core.row.ValueMetaAndData;
@@ -235,6 +241,42 @@ class FilterRowsTest {
     assertFalse(runtimeCondition.evaluate(rowMeta, new Object[] 
{iso.parse("2022-01-02")}));
   }
 
+  @Test
+  void descendingFieldIsComparedAscendingWithoutChangingTheSharedInputMeta() 
throws Exception {
+    Condition.CValue ten = new Condition.CValue();
+    ten.setName("constant");
+    ten.setType("Integer");
+    ten.setText("10");
+    ten.setNullValue(false);
+    ten.setLength(-1);
+    ten.setPrecision(-1);
+
+    Condition condition = new Condition();
+    condition.setLeftValueName("value");
+    condition.setFunction(SMALLER);
+    condition.setRightValue(ten);
+
+    FilterRows transform = spy(createTransform(condition));
+    assertTrue(transform.init());
+
+    RowMeta inputRowMeta = new RowMeta();
+    ValueMetaInteger value = new ValueMetaInteger("value");
+    value.setSortedDescending(true);
+    inputRowMeta.addValueMeta(value);
+    transform.setInputRowMeta(inputRowMeta);
+
+    Object[] row = new Object[] {5L};
+    doReturn(row).when(transform).getRow();
+    doNothing().when(transform).putRow(any(IRowMeta.class), 
any(Object[].class));
+
+    transform.processRow();
+
+    // 5 < 10: kept, so the descending sort order did not invert the comparison
+    verify(transform).putRow(any(IRowMeta.class), any(Object[].class));
+    // the hop's row metadata is shared with the previous transform and stays 
untouched
+    assertTrue(inputRowMeta.getValueMeta(0).isSortedDescending());
+  }
+
   private static Stream<Arguments> variableValueTypes() throws Exception {
     ValueMetaDate dateMeta = new ValueMetaDate("value");
     dateMeta.setConversionMask("yyyy-MM-dd");

Reply via email to