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 75d6b525ef track number of rows affected by a merge statement, fixes 
#8386
75d6b525ef is described below

commit 75d6b525efd040f99533a98eab4c56bf2822f4ae
Author: Hans Van Akelyen <[email protected]>
AuthorDate: Sat Sep 19 18:38:23 2026 +0200

    track number of rows affected by a merge statement, fixes #8386
---
 .../org/apache/hop/core/database/Database.java     |  46 +++--
 .../hop/core/database/SqlQueryClassifier.java      |  18 ++
 .../org/apache/hop/core/database/DatabaseTest.java |  76 +++++++
 .../hop/core/database/SqlQueryClassifierTest.java  |  33 +++
 .../ROOT/pages/pipeline/transforms/execsql.adoc    |   4 +
 .../ROOT/pages/pipeline/transforms/execsqlrow.adoc |   4 +
 .../database/0019-execute-sqlscript-merge.hpl      | 228 +++++++++++++++++++++
 .../database/main-0019-execute-sqlscript.hwf       |  67 ++++++
 .../pipeline/transforms/execsqlrow/ExecSqlRow.java |   8 +
 .../hop/pipeline/transforms/sql/ExecSql.java       |   9 +
 10 files changed, 480 insertions(+), 13 deletions(-)

diff --git a/core/src/main/java/org/apache/hop/core/database/Database.java 
b/core/src/main/java/org/apache/hop/core/database/Database.java
index c8cd1fe566..21ff73bbc5 100644
--- a/core/src/main/java/org/apache/hop/core/database/Database.java
+++ b/core/src/main/java/org/apache/hop/core/database/Database.java
@@ -1542,24 +1542,14 @@ public class Database implements IVariables, 
ILoggingObject, AutoCloseable {
           count = stmt.getUpdateCount();
         }
       }
-      String upperSql = sql.toUpperCase();
-      if (!resultSet && count > 0) {
+      if (!resultSet) {
         // if the result is a resultset, we don't do anything with it!
         // You should have called something else!
-        if (upperSql.startsWith("INSERT")) {
-          result.setNrLinesOutput(count);
-        } else if (!databaseMeta.isSupportsCustomUpdateStmt() && 
upperSql.startsWith("UPDATE")) {
-          result.setNrLinesUpdated(count);
-        } else if (databaseMeta.isSupportsCustomUpdateStmt() && 
upperSql.contains("UPDATE")) {
-          result.setNrLinesUpdated(count);
-        } else if (!databaseMeta.isSupportsCustomDeleteStmt() && 
upperSql.startsWith("DELETE")) {
-          result.setNrLinesDeleted(count);
-        } else if (databaseMeta.isSupportsCustomDeleteStmt() && 
upperSql.contains("DELETE")) {
-          result.setNrLinesDeleted(count);
-        }
+        countAffectedRows(result, sql, count);
       }
 
       // See if a cache needs to be cleared...
+      String upperSql = sql.toUpperCase();
       if (upperSql.startsWith("ALTER TABLE")
           || upperSql.startsWith("DROP TABLE")
           || upperSql.startsWith("CREATE TABLE")) {
@@ -1574,6 +1564,36 @@ public class Database implements IVariables, 
ILoggingObject, AutoCloseable {
     return result;
   }
 
+  /**
+   * Attribute the number of rows a statement affected to the matching counter 
of the result. JDBC
+   * reports a single count per statement; for MERGE, UPSERT and REPLACE it 
covers the inserted,
+   * updated and deleted rows together and lands in the update counter.
+   */
+  private void countAffectedRows(Result result, String sql, int count) {
+    if (count <= 0) {
+      return;
+    }
+    String verb = SqlQueryClassifier.statementVerb(sql);
+    if (verb == null) {
+      return;
+    }
+    switch (verb) {
+      case "INSERT" -> result.setNrLinesOutput(count);
+      case "UPDATE", "MERGE", "UPSERT", "REPLACE" -> 
result.setNrLinesUpdated(count);
+      case "DELETE" -> result.setNrLinesDeleted(count);
+      default -> {
+        // Databases that update or delete through another statement, like 
ClickHouse with
+        // ALTER TABLE ... UPDATE / DELETE
+        String upperSql = sql.toUpperCase();
+        if (databaseMeta.isSupportsCustomUpdateStmt() && 
upperSql.contains("UPDATE")) {
+          result.setNrLinesUpdated(count);
+        } else if (databaseMeta.isSupportsCustomDeleteStmt() && 
upperSql.contains("DELETE")) {
+          result.setNrLinesDeleted(count);
+        }
+      }
+    }
+  }
+
   /**
    * Execute a series of SQL statements, separated by ;
    *
diff --git 
a/core/src/main/java/org/apache/hop/core/database/SqlQueryClassifier.java 
b/core/src/main/java/org/apache/hop/core/database/SqlQueryClassifier.java
index 30039f6e47..56d9c59d25 100644
--- a/core/src/main/java/org/apache/hop/core/database/SqlQueryClassifier.java
+++ b/core/src/main/java/org/apache/hop/core/database/SqlQueryClassifier.java
@@ -135,6 +135,24 @@ public final class SqlQueryClassifier {
     return true;
   }
 
+  /**
+   * @param sql one statement, comments allowed
+   * @return the upper-case verb of the main statement, past an optional 
{@code WITH} clause ({@code
+   *     UPDATE} for {@code WITH s AS (...) UPDATE t ...}), or {@code null} 
when {@code sql} does
+   *     not start with a keyword
+   */
+  public static String statementVerb(String sql) {
+    if (Utils.isEmpty(sql)) {
+      return null;
+    }
+    int i = skipTrivia(sql, 0);
+    String first = keywordAt(sql, i);
+    if ("WITH".equals(first)) {
+      first = keywordAt(sql, indexAfterCteList(sql, i));
+    }
+    return first;
+  }
+
   /**
    * @param sql one statement, comments allowed
    * @return {@code true} when {@code sql} starts with a SQL verb (query, DML 
or DDL), {@code false}
diff --git a/core/src/test/java/org/apache/hop/core/database/DatabaseTest.java 
b/core/src/test/java/org/apache/hop/core/database/DatabaseTest.java
index 9d7fab271f..774dd8a778 100644
--- a/core/src/test/java/org/apache/hop/core/database/DatabaseTest.java
+++ b/core/src/test/java/org/apache/hop/core/database/DatabaseTest.java
@@ -48,9 +48,11 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
+import java.sql.Statement;
 import java.sql.Types;
 import java.util.List;
 import org.apache.hop.core.HopClientEnvironment;
+import org.apache.hop.core.Result;
 import org.apache.hop.core.exception.HopDatabaseBatchException;
 import org.apache.hop.core.exception.HopDatabaseException;
 import org.apache.hop.core.logging.ILoggingObject;
@@ -822,4 +824,78 @@ class DatabaseTest {
     db.setConnection(conn);
     return db;
   }
+
+  /** A database whose driver reports {@code count} affected rows for every 
non-query statement. */
+  private Database databaseAffecting(int count) throws SQLException {
+    when(meta.getIDatabase()).thenReturn(new NoneDatabaseMeta());
+    when(meta.stripCR(anyString())).thenAnswer(invocation -> 
invocation.getArgument(0));
+    Statement statement = mock(Statement.class);
+    when(statement.execute(anyString())).thenReturn(false);
+    when(statement.getUpdateCount()).thenReturn(count);
+    when(conn.createStatement()).thenReturn(statement);
+    Database db = new Database(log, variables, meta);
+    db.setConnection(conn);
+    return db;
+  }
+
+  @Test
+  void execStatementCountsMergeAsUpdated() throws Exception {
+    Result result =
+        databaseAffecting(4)
+            .execStatement(
+                "MERGE INTO t USING s ON t.id = s.id WHEN MATCHED THEN UPDATE 
SET v = s.v "
+                    + "WHEN NOT MATCHED THEN INSERT (id, v) VALUES (s.id, 
s.v)");
+
+    assertEquals(4, result.getNrLinesUpdated());
+    assertEquals(0, result.getNrLinesOutput());
+    assertEquals(0, result.getNrLinesDeleted());
+  }
+
+  @Test
+  void execStatementCountsCtePrefixedDmlByItsVerb() throws Exception {
+    Result result =
+        databaseAffecting(2)
+            .execStatement(
+                "WITH s AS (SELECT id FROM src) UPDATE t SET v = 1 FROM s 
WHERE t.id = s.id");
+    assertEquals(2, result.getNrLinesUpdated());
+
+    result = databaseAffecting(3).execStatement("WITH s AS (SELECT 1) DELETE 
FROM t");
+    assertEquals(3, result.getNrLinesDeleted());
+  }
+
+  @Test
+  void execStatementKeepsInsertUpdateDeleteBuckets() throws Exception {
+    assertEquals(
+        5, databaseAffecting(5).execStatement("insert into t values 
(1)").getNrLinesOutput());
+    assertEquals(6, databaseAffecting(6).execStatement("UPDATE t SET v = 
1").getNrLinesUpdated());
+    assertEquals(
+        7, databaseAffecting(7).execStatement("-- all\nDELETE FROM 
t").getNrLinesDeleted());
+  }
+
+  @Test
+  void execStatementCountsCustomUpdateAndDeleteStatements() throws Exception {
+    when(meta.isSupportsCustomUpdateStmt()).thenReturn(true);
+    when(meta.isSupportsCustomDeleteStmt()).thenReturn(true);
+
+    assertEquals(
+        2,
+        databaseAffecting(2)
+            .execStatement("ALTER TABLE t UPDATE v = 1 WHERE id = 1")
+            .getNrLinesUpdated());
+    assertEquals(
+        3,
+        databaseAffecting(3)
+            .execStatement("ALTER TABLE t DELETE WHERE id = 1")
+            .getNrLinesDeleted());
+  }
+
+  @Test
+  void execStatementIgnoresStatementsWithoutAffectedRows() throws Exception {
+    Result result = databaseAffecting(0).execStatement("MERGE INTO t USING s 
ON t.id = s.id");
+    assertEquals(0, result.getNrLinesUpdated());
+
+    result = databaseAffecting(-1).execStatement("CREATE TABLE t (id INT)");
+    assertEquals(0, result.getNrLinesUpdated());
+    assertEquals(0, result.getNrLinesOutput());
+  }
 }
diff --git 
a/core/src/test/java/org/apache/hop/core/database/SqlQueryClassifierTest.java 
b/core/src/test/java/org/apache/hop/core/database/SqlQueryClassifierTest.java
index d6fe647bcb..88f7655c7d 100644
--- 
a/core/src/test/java/org/apache/hop/core/database/SqlQueryClassifierTest.java
+++ 
b/core/src/test/java/org/apache/hop/core/database/SqlQueryClassifierTest.java
@@ -16,7 +16,9 @@
  */
 package org.apache.hop.core.database;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import org.junit.jupiter.api.Test;
@@ -131,4 +133,35 @@ class SqlQueryClassifierTest {
     assertTrue(statements.get(0).isQuery());
     assertFalse(statements.get(1).isQuery());
   }
+
+  @Test
+  void statementVerbIsTheFirstKeyword() {
+    assertEquals("MERGE", SqlQueryClassifier.statementVerb("MERGE INTO t USING 
s ON t.id = s.id"));
+    assertEquals(
+        "insert".toUpperCase(), SqlQueryClassifier.statementVerb("insert into 
t values (1)"));
+    assertEquals("UPDATE", SqlQueryClassifier.statementVerb("  \n/* c */ 
UPDATE t SET a = 1"));
+    assertEquals("DELETE", SqlQueryClassifier.statementVerb("-- 
comment\nDELETE FROM t"));
+  }
+
+  @Test
+  void statementVerbSkipsTheCteList() {
+    assertEquals(
+        "UPDATE",
+        SqlQueryClassifier.statementVerb(
+            "WITH s AS (SELECT id FROM src WHERE id IN (2,3)) UPDATE t SET a = 
1 FROM s"));
+    assertEquals(
+        "MERGE",
+        SqlQueryClassifier.statementVerb(
+            "WITH RECURSIVE a AS (SELECT 1), b (x) AS NOT MATERIALIZED (SELECT 
2) "
+                + "MERGE INTO t USING b ON t.id = b.x WHEN MATCHED THEN 
DELETE"));
+    assertEquals(
+        "SELECT", SqlQueryClassifier.statementVerb("WITH s AS (SELECT 1) 
SELECT * FROM s"));
+  }
+
+  @Test
+  void statementVerbIsNullWithoutAKeyword() {
+    assertNull(SqlQueryClassifier.statementVerb(null));
+    assertNull(SqlQueryClassifier.statementVerb("   "));
+    assertNull(SqlQueryClassifier.statementVerb("(SELECT 1)"));
+  }
 }
diff --git 
a/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/execsql.adoc 
b/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/execsql.adoc
index a795a29fd5..de205b24cc 100644
--- a/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/execsql.adoc
+++ b/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/execsql.adoc
@@ -53,6 +53,10 @@ 
image:transforms/execute-sql-script-dialog-general-tab.png[Execute SQL script Ge
 |Field to contain read stats|Same as insert stats, but for read rows.
 |===
 
+The counts come from the number of affected rows the JDBC driver reports for 
each statement, attributed by the statement's verb (also behind a `WITH` 
clause). `MERGE`, `UPSERT` and `REPLACE` statements report a single count for 
the rows they inserted, updated and deleted together; that count is reported as 
updated rows. Rows returned by `SELECT` statements count as read rows, except 
when the SQL is sent as a single statement.
+
+The same counts show up in the transform's own metrics: read rows as input 
(I), inserted rows as output (O), updated and deleted rows as updated (U).
+
 == SQL
 
 The SQL tab is where you specify the script to run, either inline or from a 
file.
diff --git 
a/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/execsqlrow.adoc 
b/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/execsqlrow.adoc
index 1046b8e571..199eb8ddad 100644
--- 
a/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/execsqlrow.adoc
+++ 
b/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/execsqlrow.adoc
@@ -44,6 +44,10 @@ The SQL to execute can be passed as pipeline fields or read 
from a file.
 |Field to contain read stats|Same as insert stats, but for read rows.
 |===
 
+The counts come from the number of affected rows the JDBC driver reports for 
each statement, attributed by the statement's verb (also behind a `WITH` 
clause). `MERGE`, `UPSERT` and `REPLACE` statements report a single count for 
the rows they inserted, updated and deleted together; that count is reported as 
updated rows. Rows returned by `SELECT` statements count as read rows, except 
when the SQL is sent as a single statement.
+
+The same counts show up in the transform's own metrics: read rows as input 
(I), inserted rows as output (O), updated and deleted rows as updated (U).
+
 == Notes
 
 Because of the scripting/dynamic nature of the transform, it does not use 
prepared statements and thus is not intended to work fast or optimal.
diff --git a/integration-tests/database/0019-execute-sqlscript-merge.hpl 
b/integration-tests/database/0019-execute-sqlscript-merge.hpl
new file mode 100644
index 0000000000..fcf9d14c27
--- /dev/null
+++ b/integration-tests/database/0019-execute-sqlscript-merge.hpl
@@ -0,0 +1,228 @@
+<?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>0019-execute-sqlscript-merge</name>
+    <name_sync_with_filename>Y</name_sync_with_filename>
+    <description/>
+    <extended_description/>
+    <pipeline_version/>
+    <pipeline_type>Normal</pipeline_type>
+    <pipeline_status>0</pipeline_status>
+    <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/09/19 18:30:00.000</created_date>
+    <modified_user>-</modified_user>
+    <modified_date>2026/09/19 18:30:00.000</modified_date>
+    <key_for_session_key>H4sIAAAAAAAAAAMAAAAAAAAAAAA=</key_for_session_key>
+    <is_key_private>N</is_key_private>
+  </info>
+  <notepads>
+  </notepads>
+  <order>
+    <hop>
+      <from>validate count</from>
+      <to>success</to>
+      <enabled>Y</enabled>
+    </hop>
+    <hop>
+      <from>validate count</from>
+      <to>failed on count</to>
+      <enabled>Y</enabled>
+    </hop>
+    <hop>
+      <from>Execute SQL script</from>
+      <to>validate count</to>
+      <enabled>Y</enabled>
+    </hop>
+  </order>
+  <transform>
+    <name>Execute SQL script</name>
+    <type>ExecSql</type>
+    <description/>
+    <distribute>Y</distribute>
+    <custom_distribution/>
+    <copies>1</copies>
+    <partitioning>
+      <method>none</method>
+      <schema_name/>
+    </partitioning>
+    <connection>unit-test-db</connection>
+    <execute_each_row>N</execute_each_row>
+    <single_statement>N</single_statement>
+    <replace_variables>N</replace_variables>
+    <quoteString>N</quoteString>
+    <sql>
+-- MERGE reports one affected-row count for the 2 updated + 2 inserted rows 
(#8386)
+MERGE INTO public.merge_target t
+USING public.merge_source s ON t.id = s.id
+WHEN MATCHED THEN UPDATE SET value = s.value
+WHEN NOT MATCHED THEN INSERT (id, value) VALUES (s.id, s.value);
+
+-- a CTE-prefixed UPDATE is still an UPDATE: 2 rows
+WITH s AS (SELECT id FROM public.merge_source WHERE id IN (2, 3))
+UPDATE public.merge_target t SET value = t.value || '_cte' FROM s WHERE t.id = 
s.id;</sql>
+    <set_params>N</set_params>
+    <insert_field>inserted</insert_field>
+    <update_field>updated</update_field>
+    <delete_field>deleted</delete_field>
+    <read_field>read</read_field>
+    <arguments>
+    </arguments>
+    <attributes/>
+    <GUI>
+      <xloc>320</xloc>
+      <yloc>80</yloc>
+    </GUI>
+  </transform>
+  <transform>
+    <name>failed on count</name>
+    <type>Abort</type>
+    <description/>
+    <distribute>Y</distribute>
+    <custom_distribution/>
+    <copies>1</copies>
+    <partitioning>
+      <method>none</method>
+      <schema_name/>
+    </partitioning>
+    <abort_option>ABORT_WITH_ERROR</abort_option>
+    <always_log_rows>Y</always_log_rows>
+    <row_threshold>0</row_threshold>
+    <attributes/>
+    <GUI>
+      <xloc>640</xloc>
+      <yloc>176</yloc>
+    </GUI>
+  </transform>
+  <transform>
+    <name>success</name>
+    <type>Dummy</type>
+    <description/>
+    <distribute>Y</distribute>
+    <custom_distribution/>
+    <copies>1</copies>
+    <partitioning>
+      <method>none</method>
+      <schema_name/>
+    </partitioning>
+    <attributes/>
+    <GUI>
+      <xloc>784</xloc>
+      <yloc>80</yloc>
+    </GUI>
+  </transform>
+  <transform>
+    <name>validate count</name>
+    <type>FilterRows</type>
+    <description/>
+    <distribute>Y</distribute>
+    <custom_distribution/>
+    <copies>1</copies>
+    <partitioning>
+      <method>none</method>
+      <schema_name/>
+    </partitioning>
+    <send_true_to>success</send_true_to>
+    <send_false_to>failed on count</send_false_to>
+    <compare>
+      <condition>
+        <negated>N</negated>
+        <conditions>
+          <condition>
+            <negated>N</negated>
+            <leftvalue>updated</leftvalue>
+            <function>=</function>
+            <rightvalue/>
+            <value>
+              <name>constant</name>
+              <type>Integer</type>
+              <text>6</text>
+              <length>-1</length>
+              <precision>0</precision>
+              <isnull>N</isnull>
+              <mask>####0;-####0</mask>
+            </value>
+          </condition>
+          <condition>
+            <negated>N</negated>
+            <operator>AND</operator>
+            <leftvalue>deleted</leftvalue>
+            <function>=</function>
+            <rightvalue/>
+            <value>
+              <name>constant</name>
+              <type>Integer</type>
+              <text>0</text>
+              <length>-1</length>
+              <precision>0</precision>
+              <isnull>N</isnull>
+              <mask>####0;-####0</mask>
+            </value>
+          </condition>
+          <condition>
+            <negated>N</negated>
+            <operator>AND</operator>
+            <leftvalue>inserted</leftvalue>
+            <function>=</function>
+            <rightvalue/>
+            <value>
+              <name>constant</name>
+              <type>Integer</type>
+              <text>0</text>
+              <length>-1</length>
+              <precision>0</precision>
+              <isnull>N</isnull>
+              <mask>####0;-####0</mask>
+            </value>
+          </condition>
+          <condition>
+            <negated>N</negated>
+            <operator>AND</operator>
+            <leftvalue>read</leftvalue>
+            <function>=</function>
+            <rightvalue/>
+            <value>
+              <name>constant</name>
+              <type>Integer</type>
+              <text>0</text>
+              <length>-1</length>
+              <precision>0</precision>
+              <isnull>N</isnull>
+              <mask>####0;-####0</mask>
+            </value>
+          </condition>
+        </conditions>
+      </condition>
+    </compare>
+    <attributes/>
+    <GUI>
+      <xloc>640</xloc>
+      <yloc>80</yloc>
+    </GUI>
+  </transform>
+  <transform_error_handling>
+  </transform_error_handling>
+  <attributes/>
+</pipeline>
diff --git a/integration-tests/database/main-0019-execute-sqlscript.hwf 
b/integration-tests/database/main-0019-execute-sqlscript.hwf
index 937162be2f..31fea1393f 100644
--- a/integration-tests/database/main-0019-execute-sqlscript.hwf
+++ b/integration-tests/database/main-0019-execute-sqlscript.hwf
@@ -204,6 +204,59 @@ CREATE TABLE public.testtable
       <yloc>48</yloc>
       <attributes_hac/>
     </action>
+    <action>
+      <name>Prepare Test 4</name>
+      <description/>
+      <type>SQL</type>
+      <attributes/>
+      <sql>
+DROP TABLE IF EXISTS public.merge_target;
+DROP TABLE IF EXISTS public.merge_source;
+
+CREATE TABLE public.merge_target (id int PRIMARY KEY, value varchar NULL);
+CREATE TABLE public.merge_source (id int PRIMARY KEY, value varchar NULL);
+
+INSERT INTO public.merge_target VALUES (1, 'old1'), (2, 'old2'), (3, 'old3');
+INSERT INTO public.merge_source VALUES (2, 'new2'), (3, 'new3'), (4, 'new4'), 
(5, 'new5');
+</sql>
+      <useVariableSubstitution>F</useVariableSubstitution>
+      <sqlfromfile>F</sqlfromfile>
+      <sqlfilename/>
+      <sendOneStatement>F</sendOneStatement>
+      <connection>unit-test-db</connection>
+      <parallel>N</parallel>
+      <xloc>1296</xloc>
+      <yloc>48</yloc>
+      <attributes_hac/>
+    </action>
+    <action>
+      <name>0019-execute-sqlscript-merge</name>
+      <description/>
+      <type>PIPELINE</type>
+      <attributes/>
+      <filename>${PROJECT_HOME}/0019-execute-sqlscript-merge.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>
+      <set_logfile>N</set_logfile>
+      <logfile/>
+      <logext/>
+      <add_date>N</add_date>
+      <add_time>N</add_time>
+      <loglevel>Basic</loglevel>
+      <set_append_logfile>N</set_append_logfile>
+      <wait_until_finished>Y</wait_until_finished>
+      <create_parent_folder>N</create_parent_folder>
+      <run_configuration>local</run_configuration>
+      <parameters>
+        <pass_all_parameters>Y</pass_all_parameters>
+      </parameters>
+      <parallel>N</parallel>
+      <xloc>1456</xloc>
+      <yloc>48</yloc>
+      <attributes_hac/>
+    </action>
   </actions>
   <hops>
     <hop>
@@ -248,6 +301,20 @@ CREATE TABLE public.testtable
       <evaluation>Y</evaluation>
       <unconditional>Y</unconditional>
     </hop>
+    <hop>
+      <from>0019-execute-sqlscript-sql-file</from>
+      <to>Prepare Test 4</to>
+      <enabled>Y</enabled>
+      <evaluation>Y</evaluation>
+      <unconditional>Y</unconditional>
+    </hop>
+    <hop>
+      <from>Prepare Test 4</from>
+      <to>0019-execute-sqlscript-merge</to>
+      <enabled>Y</enabled>
+      <evaluation>Y</evaluation>
+      <unconditional>Y</unconditional>
+    </hop>
   </hops>
   <notepads>
   </notepads>
diff --git 
a/plugins/transforms/execsqlrow/src/main/java/org/apache/hop/pipeline/transforms/execsqlrow/ExecSqlRow.java
 
b/plugins/transforms/execsqlrow/src/main/java/org/apache/hop/pipeline/transforms/execsqlrow/ExecSqlRow.java
index afa0c874b3..319c8d21d3 100644
--- 
a/plugins/transforms/execsqlrow/src/main/java/org/apache/hop/pipeline/transforms/execsqlrow/ExecSqlRow.java
+++ 
b/plugins/transforms/execsqlrow/src/main/java/org/apache/hop/pipeline/transforms/execsqlrow/ExecSqlRow.java
@@ -80,6 +80,13 @@ public class ExecSqlRow extends 
BaseTransform<ExecSqlRowMeta, ExecSqlRowData> {
     return resultRow;
   }
 
+  /** Reflect the rows the statements read and affected in the transform's own 
counters. */
+  private void addResultToStats(Result result) {
+    setLinesInput(getLinesInput() + result.getNrLinesRead());
+    setLinesOutput(getLinesOutput() + result.getNrLinesOutput());
+    setLinesUpdated(getLinesUpdated() + result.getNrLinesUpdated() + 
result.getNrLinesDeleted());
+  }
+
   @Override
   public boolean processRow() throws HopException {
 
@@ -142,6 +149,7 @@ public class ExecSqlRow extends 
BaseTransform<ExecSqlRowMeta, ExecSqlRowData> {
           data.result = data.db.execStatements(sql);
         }
       }
+      addResultToStats(data.result);
 
       RowMetaAndData add =
           getResultRow(
diff --git 
a/plugins/transforms/sql/src/main/java/org/apache/hop/pipeline/transforms/sql/ExecSql.java
 
b/plugins/transforms/sql/src/main/java/org/apache/hop/pipeline/transforms/sql/ExecSql.java
index 7f58347f1a..51646cdae5 100644
--- 
a/plugins/transforms/sql/src/main/java/org/apache/hop/pipeline/transforms/sql/ExecSql.java
+++ 
b/plugins/transforms/sql/src/main/java/org/apache/hop/pipeline/transforms/sql/ExecSql.java
@@ -83,6 +83,13 @@ public class ExecSql extends BaseTransform<ExecSqlMeta, 
ExecSqlData> {
     return resultRow;
   }
 
+  /** Reflect the rows the statements read and affected in the transform's own 
counters. */
+  private void addResultToStats(Result result) {
+    setLinesInput(getLinesInput() + result.getNrLinesRead());
+    setLinesOutput(getLinesOutput() + result.getNrLinesOutput());
+    setLinesUpdated(getLinesUpdated() + result.getNrLinesUpdated() + 
result.getNrLinesDeleted());
+  }
+
   @Override
   public boolean processRow() throws HopException {
 
@@ -202,6 +209,7 @@ public class ExecSql extends BaseTransform<ExecSqlMeta, 
ExecSqlData> {
       } else {
         data.result = data.db.execStatements(sql, data.paramsMeta, paramsData);
       }
+      addResultToStats(data.result);
 
       RowMetaAndData add =
           getResultRow(
@@ -308,6 +316,7 @@ public class ExecSql extends BaseTransform<ExecSqlMeta, 
ExecSqlData> {
           } else {
             data.result = data.db.execStatements(data.sql);
           }
+          addResultToStats(data.result);
           if (!data.db.isAutoCommit()) {
             data.db.commit();
           }

Reply via email to