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 4e57c9a353 [#5748] Improve MetaInject plugin to allow empty stream 
(#5791)
4e57c9a353 is described below

commit 4e57c9a3534baf7006ed4ab48f848999cc541886
Author: François Papon <[email protected]>
AuthorDate: Thu Oct 16 09:25:41 2025 +0200

    [#5748] Improve MetaInject plugin to allow empty stream (#5791)
---
 .../pipeline/transforms/metainject/MetaInject.java | 15 ++++++++-----
 .../transforms/metainject/MetaInjectDialog.java    | 16 +++++++++++++
 .../transforms/metainject/MetaInjectMeta.java      | 26 ++++++++++++++++++++++
 .../metainject/messages/messages_en_US.properties  |  3 ++-
 .../metainject/messages/messages_fr_FR.properties  |  1 +
 .../metainject/MetaInjectMetaInjectionTest.java    |  1 +
 .../metainject/MetaInjectMetaLoadSaveTest.java     |  1 +
 7 files changed, 56 insertions(+), 7 deletions(-)

diff --git 
a/plugins/transforms/metainject/src/main/java/org/apache/hop/pipeline/transforms/metainject/MetaInject.java
 
b/plugins/transforms/metainject/src/main/java/org/apache/hop/pipeline/transforms/metainject/MetaInject.java
index cbc54e505e..d520785215 100644
--- 
a/plugins/transforms/metainject/src/main/java/org/apache/hop/pipeline/transforms/metainject/MetaInject.java
+++ 
b/plugins/transforms/metainject/src/main/java/org/apache/hop/pipeline/transforms/metainject/MetaInject.java
@@ -82,7 +82,9 @@ public class MetaInject extends BaseTransform<MetaInjectMeta, 
MetaInjectData> {
     // Skip the transform from which we stream data. Keep that available for 
runtime action.
     //
     data.rowMap = new HashMap<>();
-    boolean receivedRows = true;
+    boolean receivedRows = false;
+    boolean hasEmptyList = false;
+
     for (String prevTransformName : 
getPipelineMeta().getPrevTransformNames(getTransformMeta())) {
       // Don't read from the streaming source transform
       //
@@ -99,14 +101,15 @@ public class MetaInject extends 
BaseTransform<MetaInjectMeta, MetaInjectData> {
 
           row = getRowFrom(rowSet);
         }
-        if (list.isEmpty()) {
-          receivedRows = false;
-          break;
+        if (!list.isEmpty()) {
+          receivedRows = true;
+          data.rowMap.put(prevTransformName, list);
+        } else {
+          hasEmptyList = true;
         }
-        data.rowMap.put(prevTransformName, list);
       }
     }
-    if (!receivedRows) {
+    if (!receivedRows || (hasEmptyList && 
!meta.isAllowEmptyStreamOnExecution())) {
       setOutputDone();
       return false;
     }
diff --git 
a/plugins/transforms/metainject/src/main/java/org/apache/hop/pipeline/transforms/metainject/MetaInjectDialog.java
 
b/plugins/transforms/metainject/src/main/java/org/apache/hop/pipeline/transforms/metainject/MetaInjectDialog.java
index 1d5b44af90..8f241c5ed8 100644
--- 
a/plugins/transforms/metainject/src/main/java/org/apache/hop/pipeline/transforms/metainject/MetaInjectDialog.java
+++ 
b/plugins/transforms/metainject/src/main/java/org/apache/hop/pipeline/transforms/metainject/MetaInjectDialog.java
@@ -135,6 +135,10 @@ public class MetaInjectDialog extends BaseTransformDialog {
   //
   private Button wNoExecution;
 
+  // allow to run execution if previous stream data are empty
+  //
+  private Button wAllowEmptyStreamOnExecution;
+
   private CCombo wStreamingSourceTransform;
 
   // the streaming target transform
@@ -573,6 +577,16 @@ public class MetaInjectDialog extends BaseTransformDialog {
     fdNoExecution.top = new FormAttachment(wStreamingTargetTransform, 10);
     wNoExecution.setLayoutData(fdNoExecution);
 
+    wAllowEmptyStreamOnExecution = new Button(wOptionsComp, SWT.CHECK);
+    wAllowEmptyStreamOnExecution.setText(
+        BaseMessages.getString(PKG, 
"MetaInjectDialog.AllowEmptyStreamOnExecution.Label"));
+    PropsUi.setLook(wAllowEmptyStreamOnExecution);
+    FormData fdAllowEmptyStreamOnExecution = new FormData();
+    fdAllowEmptyStreamOnExecution.width = 350;
+    fdAllowEmptyStreamOnExecution.left = new FormAttachment(0, 0);
+    fdAllowEmptyStreamOnExecution.top = new FormAttachment(wNoExecution, 10);
+    wAllowEmptyStreamOnExecution.setLayoutData(fdAllowEmptyStreamOnExecution);
+
     FormData fdOptionsComp = new FormData();
     fdOptionsComp.left = new FormAttachment(0, 0);
     fdOptionsComp.top = new FormAttachment(0, 0);
@@ -912,6 +926,7 @@ public class MetaInjectDialog extends BaseTransformDialog {
     wTargetFile.setText(Const.NVL(metaInjectMeta.getTargetFile(), ""));
     wCreateParentFolder.setSelection(metaInjectMeta.isCreateParentFolder());
     wNoExecution.setSelection(!metaInjectMeta.isNoExecution());
+    
wAllowEmptyStreamOnExecution.setSelection(metaInjectMeta.isAllowEmptyStreamOnExecution());
 
     wStreamingSourceTransform.setText(
         Const.NVL(
@@ -1130,6 +1145,7 @@ public class MetaInjectDialog extends BaseTransformDialog 
{
     meta.setTargetFile(wTargetFile.getText());
     meta.setCreateParentFolder(wCreateParentFolder.getSelection());
     meta.setNoExecution(!wNoExecution.getSelection());
+    
meta.setAllowEmptyStreamOnExecution(wAllowEmptyStreamOnExecution.getSelection());
 
     final TransformMeta streamSourceTransform =
         pipelineMeta.findTransform(wStreamingSourceTransform.getText());
diff --git 
a/plugins/transforms/metainject/src/main/java/org/apache/hop/pipeline/transforms/metainject/MetaInjectMeta.java
 
b/plugins/transforms/metainject/src/main/java/org/apache/hop/pipeline/transforms/metainject/MetaInjectMeta.java
index 4b3a006999..4461ce7a97 100644
--- 
a/plugins/transforms/metainject/src/main/java/org/apache/hop/pipeline/transforms/metainject/MetaInjectMeta.java
+++ 
b/plugins/transforms/metainject/src/main/java/org/apache/hop/pipeline/transforms/metainject/MetaInjectMeta.java
@@ -79,6 +79,7 @@ public class MetaInjectMeta extends 
BaseTransformMeta<MetaInject, MetaInjectData
   private static final String TARGET_FILE = "target_file";
   private static final String CREATE_PARENT_FOLDER = "create_parent_folder";
   private static final String NO_EXECUTION = "no_execution";
+  private static final String ALLOW_EMPTY_STREAM_ON_EXECUTION = 
"allow_empty_stream_on_execution";
   private static final String SOURCE_TRANSFORM = "source_transform";
 
   private static final String STREAM_SOURCE_TRANSFORM = 
"stream_source_transform";
@@ -118,6 +119,9 @@ public class MetaInjectMeta extends 
BaseTransformMeta<MetaInject, MetaInjectData
   @Injection(name = "NO_EXECUTION")
   private boolean noExecution;
 
+  @Injection(name = "ALLOW_EMPTY_STREAM_ON_EXECUTION")
+  private boolean allowEmptyStreamOnExecution;
+
   @Injection(name = "STREAMING_SOURCE_TRANSFORM")
   private String streamSourceTransformName;
 
@@ -173,6 +177,10 @@ public class MetaInjectMeta extends 
BaseTransformMeta<MetaInject, MetaInjectData
     retval.append("    ").append(XmlHandler.addTagValue(TARGET_FILE, 
targetFile));
     retval.append("    ").append(XmlHandler.addTagValue(CREATE_PARENT_FOLDER, 
createParentFolder));
     retval.append("    ").append(XmlHandler.addTagValue(NO_EXECUTION, 
noExecution));
+    retval
+        .append("    ")
+        .append(
+            XmlHandler.addTagValue(ALLOW_EMPTY_STREAM_ON_EXECUTION, 
allowEmptyStreamOnExecution));
 
     if ((streamSourceTransformName == null) && (streamSourceTransform != 
null)) {
       streamSourceTransformName = streamSourceTransform.getName();
@@ -236,6 +244,10 @@ public class MetaInjectMeta extends 
BaseTransformMeta<MetaInject, MetaInjectData
       createParentFolder =
           "Y".equalsIgnoreCase(XmlHandler.getTagValue(transformNode, 
CREATE_PARENT_FOLDER));
       noExecution = "Y".equalsIgnoreCase(XmlHandler.getTagValue(transformNode, 
NO_EXECUTION));
+      allowEmptyStreamOnExecution =
+          "Y"
+              .equalsIgnoreCase(
+                  XmlHandler.getTagValue(transformNode, 
ALLOW_EMPTY_STREAM_ON_EXECUTION));
 
       streamSourceTransformName = XmlHandler.getTagValue(transformNode, 
STREAM_SOURCE_TRANSFORM);
       streamTargetTransformName = XmlHandler.getTagValue(transformNode, 
STREAM_TARGET_TRANSFORM);
@@ -468,6 +480,20 @@ public class MetaInjectMeta extends 
BaseTransformMeta<MetaInject, MetaInjectData
     this.noExecution = noExecution;
   }
 
+  /**
+   * @return the allowEmptyStreamOnExecution
+   */
+  public boolean isAllowEmptyStreamOnExecution() {
+    return allowEmptyStreamOnExecution;
+  }
+
+  /**
+   * @param allowEmptyStreamOnExecution the allowEmptyStreamOnExecution to set
+   */
+  public void setAllowEmptyStreamOnExecution(boolean 
allowEmptyStreamOnExecution) {
+    this.allowEmptyStreamOnExecution = allowEmptyStreamOnExecution;
+  }
+
   public String getRunConfigurationName() {
     return runConfigurationName;
   }
diff --git 
a/plugins/transforms/metainject/src/main/resources/org/apache/hop/pipeline/transforms/metainject/messages/messages_en_US.properties
 
b/plugins/transforms/metainject/src/main/resources/org/apache/hop/pipeline/transforms/metainject/messages/messages_en_US.properties
index dcbfe4c733..016580c57c 100644
--- 
a/plugins/transforms/metainject/src/main/resources/org/apache/hop/pipeline/transforms/metainject/messages/messages_en_US.properties
+++ 
b/plugins/transforms/metainject/src/main/resources/org/apache/hop/pipeline/transforms/metainject/messages/messages_en_US.properties
@@ -73,6 +73,7 @@ MetaInjectDialog.InjectTab.TabTitle=Inject Metadata
 MetaInjectDialog.InvalidMapping.Question=There are missing metadata injection 
mappings. Do you want to remove them ?
 MetaInjectDialog.InvalidMapping.Title=Invalid mapping
 MetaInjectDialog.NoExecution.Label=Run resulting pipeline
+MetaInjectDialog.AllowEmptyStreamOnExecution.Label=Allow empty stream to run 
the resulting pipeline
 MetaInjectDialog.OptionsTab.TabTitle=Options
 MetaInjectDialog.Pipeline.Label=Pipeline:
 MetaInjectDialog.RunConfiguration.Label=Run configuration (optional)
@@ -92,4 +93,4 @@ 
MetaInjectMeta.ReferencedObjectAfterInjection.Description=Pipeline template afte
 MetaInjectDialog.FilenameMissing.Header=Warning
 MetaInjectDialog.FilenameMissing.Message=The template pipeline filename is 
missing
 MetaInjectDialog.SelfReference.Header=Warning
-MetaInjectDialog.SelfReference.Message=This pipeline can''t inject into 
itself. Please select another template pipeline.
\ No newline at end of file
+MetaInjectDialog.SelfReference.Message=This pipeline can''t inject into 
itself. Please select another template pipeline.
diff --git 
a/plugins/transforms/metainject/src/main/resources/org/apache/hop/pipeline/transforms/metainject/messages/messages_fr_FR.properties
 
b/plugins/transforms/metainject/src/main/resources/org/apache/hop/pipeline/transforms/metainject/messages/messages_fr_FR.properties
index 4b359dfe5f..1aafda5fba 100644
--- 
a/plugins/transforms/metainject/src/main/resources/org/apache/hop/pipeline/transforms/metainject/messages/messages_fr_FR.properties
+++ 
b/plugins/transforms/metainject/src/main/resources/org/apache/hop/pipeline/transforms/metainject/messages/messages_fr_FR.properties
@@ -29,6 +29,7 @@ MetaInjectDialog.ErrorLoadingPipeline.DialogTitle=Erreur lors 
du chargement du p
 MetaInjectDialog.ErrorLoadingSpecifiedPipeline.Message=Erreur lors du 
chargement et de la v\u00E9rification du pipeline s\u00E9lectionn\u00E9e.
 MetaInjectDialog.ErrorLoadingSpecifiedPipeline.Title=Erreur
 MetaInjectDialog.NoExecution.Label=Ne pas ex\u00E9cuter la pipeline 
r\u00E9sultante
+MetaInjectDialog.AllowEmptyStreamOnExecution.Label=Autoriser les streams vides 
pour lancer l'ex\u00E9cution de la pipeline r\u00E9sultante
 MetaInjectDialog.Pipeline.Label=Pipeline
 MetaInjectDialog.Shell.Title=Injection de m\u00E9tadonn\u00E9es
 MetaInjectDialog.SourceFieldDialog.Title=Champ source
diff --git 
a/plugins/transforms/metainject/src/test/java/org/apache/hop/pipeline/transforms/metainject/MetaInjectMetaInjectionTest.java
 
b/plugins/transforms/metainject/src/test/java/org/apache/hop/pipeline/transforms/metainject/MetaInjectMetaInjectionTest.java
index 47dda0d6a4..1cfefb2f74 100644
--- 
a/plugins/transforms/metainject/src/test/java/org/apache/hop/pipeline/transforms/metainject/MetaInjectMetaInjectionTest.java
+++ 
b/plugins/transforms/metainject/src/test/java/org/apache/hop/pipeline/transforms/metainject/MetaInjectMetaInjectionTest.java
@@ -41,6 +41,7 @@ class MetaInjectMetaInjectionTest extends 
BaseMetadataInjectionTestJunit5<MetaIn
     check("SOURCE_TRANSFORM_NAME", () -> meta.getSourceTransformName());
     check("TARGET_FILE", () -> meta.getTargetFile());
     check("NO_EXECUTION", () -> meta.isNoExecution());
+    check("ALLOW_EMPTY_STREAM_ON_EXECUTION", () -> 
meta.isAllowEmptyStreamOnExecution());
     check("STREAMING_SOURCE_TRANSFORM", () -> 
meta.getStreamSourceTransformName());
     check("STREAMING_TARGET_TRANSFORM", () -> 
meta.getStreamTargetTransformName());
     check("SOURCE_OUTPUT_NAME", () -> 
meta.getSourceOutputFields().get(0).getName());
diff --git 
a/plugins/transforms/metainject/src/test/java/org/apache/hop/pipeline/transforms/metainject/MetaInjectMetaLoadSaveTest.java
 
b/plugins/transforms/metainject/src/test/java/org/apache/hop/pipeline/transforms/metainject/MetaInjectMetaLoadSaveTest.java
index 2f8d969c87..1bf0ff0c01 100644
--- 
a/plugins/transforms/metainject/src/test/java/org/apache/hop/pipeline/transforms/metainject/MetaInjectMetaLoadSaveTest.java
+++ 
b/plugins/transforms/metainject/src/test/java/org/apache/hop/pipeline/transforms/metainject/MetaInjectMetaLoadSaveTest.java
@@ -48,6 +48,7 @@ class MetaInjectMetaLoadSaveTest {
             "sourceTransformName",
             "targetFile",
             "noExecution",
+            "allowEmptyStreamOnExecution",
             "streamSourceTransformName",
             "streamTargetTransformName",
             "sourceOutputFields");

Reply via email to