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 2e740e2543 Resolve variables in Excel input sheet names that are not 
regular expressions (#9182)
2e740e2543 is described below

commit 2e740e2543f026f0ff141075596675ce197193f4
Author: Ankit Garg <[email protected]>
AuthorDate: Sun Nov 1 11:00:22 2026 +0530

    Resolve variables in Excel input sheet names that are not regular 
expressions (#9182)
    
    * Resolve variables in Excel input sheet names that are not regular 
expressions
    
    Fixes #9116
    
    * Resolve variables in exact sheet names when another row uses a regex
    
    Once any row is a regex, every row goes through 
resolveSheetNamesFromRegex(), whose exact-name branch added the name 
unresolved. Adds a test for a regex row combined with a variable row.
---
 .../pipeline/transforms/excelinput/ExcelInput.java |  8 +++-
 .../excelinput/ExcelInputContentParsingTest.java   | 46 ++++++++++++++++++++++
 2 files changed, 52 insertions(+), 2 deletions(-)

diff --git 
a/plugins/transforms/excel/src/main/java/org/apache/hop/pipeline/transforms/excelinput/ExcelInput.java
 
b/plugins/transforms/excel/src/main/java/org/apache/hop/pipeline/transforms/excelinput/ExcelInput.java
index b68711f493..13685aeebe 100644
--- 
a/plugins/transforms/excel/src/main/java/org/apache/hop/pipeline/transforms/excelinput/ExcelInput.java
+++ 
b/plugins/transforms/excel/src/main/java/org/apache/hop/pipeline/transforms/excelinput/ExcelInput.java
@@ -528,8 +528,9 @@ public class ExcelInput extends 
BaseTransform<ExcelInputMeta, ExcelInputData> {
                   PKG, "ExcelInput.Error.InvalidSheetRegex", sheetNameRegex, 
e.getMessage()));
         }
       } else {
-        logBasic("Sheet exact name: [" + sheet.getName() + "]");
-        matchedNames.add(sheet.getName());
+        String exactName = resolve(sheet.getName());
+        logBasic("Sheet exact name: [" + exactName + "]");
+        matchedNames.add(exactName);
         matchedStartRow.add(sheet.getStartRow());
         matchedStartCol.add(sheet.getStartColumn());
       }
@@ -958,6 +959,9 @@ public class ExcelInput extends 
BaseTransform<ExcelInputMeta, ExcelInputData> {
         data.maxsheetlength = -1;
         if (!meta.readAllSheets() && !meta.hasRegexSheets()) {
           data.sheetNames = meta.getSheetsNames();
+          for (int i = 0; i < data.sheetNames.length; i++) {
+            data.sheetNames[i] = resolve(data.sheetNames[i]);
+          }
           data.startColumn = meta.getSheetsStartColumns();
           data.startRow = meta.getSheetsStartRows();
         } else {
diff --git 
a/plugins/transforms/excel/src/test/java/org/apache/hop/pipeline/transforms/excelinput/ExcelInputContentParsingTest.java
 
b/plugins/transforms/excel/src/test/java/org/apache/hop/pipeline/transforms/excelinput/ExcelInputContentParsingTest.java
index b912a1c573..68000b6453 100644
--- 
a/plugins/transforms/excel/src/test/java/org/apache/hop/pipeline/transforms/excelinput/ExcelInputContentParsingTest.java
+++ 
b/plugins/transforms/excel/src/test/java/org/apache/hop/pipeline/transforms/excelinput/ExcelInputContentParsingTest.java
@@ -359,4 +359,50 @@ class ExcelInputContentParsingTest extends 
BaseExcelParsingTest {
     assertEquals("1.0", rows.get(0)[0], "Wrong first result");
     assertEquals("101.0", rows.get(rows.size() - 1)[0], "Wrong last result");
   }
+
+  @Test
+  void testSheetNameResolvedFromVariable() throws Exception {
+    meta.setSpreadSheetType(SpreadSheetType.SAX_POI);
+    meta.setStartsWithHeader(true);
+    setFields(new ExcelInputField("COL", -1, -1));
+
+    ExcelInputMeta.EISheet sheet = new ExcelInputMeta.EISheet();
+    sheet.setName("${SHEET_NAME}");
+    sheet.setRegex(false);
+    meta.getSheets().add(sheet);
+
+    pipeline.setVariable("SHEET_NAME", "Sheet1");
+    init("pdi-17765.xlsx");
+    process();
+
+    checkErrors();
+    assertEquals(30, rows.size(), "Wrong row count");
+    assertEquals("1.0", rows.get(0)[0], "Wrong first result");
+  }
+
+  @Test
+  void testSheetNameResolvedFromVariableAlongsideRegexRow() throws Exception {
+    meta.setSpreadSheetType(SpreadSheetType.SAX_POI);
+    meta.setStartsWithHeader(true);
+    setFields(new ExcelInputField("COL", -1, -1));
+
+    // A regex row that matches nothing forces every row through the regex 
resolution path
+    ExcelInputMeta.EISheet regexSheet = new ExcelInputMeta.EISheet();
+    regexSheet.setName("NoSuchSheet.*");
+    regexSheet.setRegex(true);
+    meta.getSheets().add(regexSheet);
+
+    ExcelInputMeta.EISheet exactSheet = new ExcelInputMeta.EISheet();
+    exactSheet.setName("${SHEET_NAME}");
+    exactSheet.setRegex(false);
+    meta.getSheets().add(exactSheet);
+
+    pipeline.setVariable("SHEET_NAME", "Sheet1");
+    init("pdi-17765.xlsx");
+    process();
+
+    checkErrors();
+    assertEquals(30, rows.size(), "Wrong row count");
+    assertEquals("1.0", rows.get(0)[0], "Wrong first result");
+  }
 }

Reply via email to