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 f52b45b0eb issue #7409 : When input data sets is set the transform is 
still doing field layout (#7411)
f52b45b0eb is described below

commit f52b45b0ebd8120145ecf6f3283287ec5226a2b9
Author: Matt Casters <[email protected]>
AuthorDate: Fri Jul 3 07:59:31 2026 +0200

    issue #7409 : When input data sets is set the transform is still doing 
field layout (#7411)
---
 .../java/org/apache/hop/pipeline/PipelineMeta.java | 132 ++++++++++++++++++++-
 .../apache/hop/testing/gui/TestingGuiPlugin.java   |   2 +-
 .../xp/PipelineGetFieldsExtensionPoint.java        |  92 ++++++++++++++
 3 files changed, 221 insertions(+), 5 deletions(-)

diff --git a/engine/src/main/java/org/apache/hop/pipeline/PipelineMeta.java 
b/engine/src/main/java/org/apache/hop/pipeline/PipelineMeta.java
index 331beca22c..b45e0aace9 100644
--- a/engine/src/main/java/org/apache/hop/pipeline/PipelineMeta.java
+++ b/engine/src/main/java/org/apache/hop/pipeline/PipelineMeta.java
@@ -1325,10 +1325,30 @@ public class PipelineMeta extends AbstractMeta
     IRowMeta before = row.clone();
     IRowMeta[] clonedInfo = cloneRowMetaInterfaces(infoRowMeta);
     if (!isSomethingDifferentInRow(before, row)) {
-      iTransformMeta.getFields(
-          this, before, name, clonedInfo, nextTransform, variables, 
metadataProvider);
-      // pass the clone object to prevent from spoiling data by other 
transforms
-      row = before;
+      GetFieldsExtension extension =
+          new GetFieldsExtension(
+              this,
+              transformMeta,
+              before,
+              name,
+              clonedInfo,
+              nextTransform,
+              variables,
+              metadataProvider);
+      try {
+        ExtensionPointHandler.callExtensionPoint(
+            LogChannel.GENERAL, variables, 
HopExtensionPoint.GetFieldsExtension.id, extension);
+      } catch (Exception e) {
+        LogChannel.GENERAL.logError("Error calling extension point 
'GetFieldsExtension'", e);
+      }
+      if (extension.isHandled()) {
+        row = before;
+      } else {
+        iTransformMeta.getFields(
+            this, before, name, clonedInfo, nextTransform, variables, 
metadataProvider);
+        // pass the clone object to prevent from spoiling data by other 
transforms
+        row = before;
+      }
     }
 
     return row;
@@ -3529,4 +3549,108 @@ public class PipelineMeta extends AbstractMeta
       }
     }
   }
+
+  public static class GetFieldsExtension {
+    private PipelineMeta pipelineMeta;
+    private TransformMeta transformMeta;
+    private IRowMeta row;
+    private String name;
+    private IRowMeta[] info;
+    private TransformMeta nextTransform;
+    private IVariables variables;
+    private IHopMetadataProvider metadataProvider;
+    private boolean handled;
+
+    public GetFieldsExtension(
+        PipelineMeta pipelineMeta,
+        TransformMeta transformMeta,
+        IRowMeta row,
+        String name,
+        IRowMeta[] info,
+        TransformMeta nextTransform,
+        IVariables variables,
+        IHopMetadataProvider metadataProvider) {
+      this.pipelineMeta = pipelineMeta;
+      this.transformMeta = transformMeta;
+      this.row = row;
+      this.name = name;
+      this.info = info;
+      this.nextTransform = nextTransform;
+      this.variables = variables;
+      this.metadataProvider = metadataProvider;
+      this.handled = false;
+    }
+
+    public PipelineMeta getPipelineMeta() {
+      return pipelineMeta;
+    }
+
+    public void setPipelineMeta(PipelineMeta pipelineMeta) {
+      this.pipelineMeta = pipelineMeta;
+    }
+
+    public TransformMeta getTransformMeta() {
+      return transformMeta;
+    }
+
+    public void setTransformMeta(TransformMeta transformMeta) {
+      this.transformMeta = transformMeta;
+    }
+
+    public IRowMeta getRow() {
+      return row;
+    }
+
+    public void setRow(IRowMeta row) {
+      this.row = row;
+    }
+
+    public String getName() {
+      return name;
+    }
+
+    public void setName(String name) {
+      this.name = name;
+    }
+
+    public IRowMeta[] getInfo() {
+      return info;
+    }
+
+    public void setInfo(IRowMeta[] info) {
+      this.info = info;
+    }
+
+    public TransformMeta getNextTransform() {
+      return nextTransform;
+    }
+
+    public void setNextTransform(TransformMeta nextTransform) {
+      this.nextTransform = nextTransform;
+    }
+
+    public IVariables getVariables() {
+      return variables;
+    }
+
+    public void setVariables(IVariables variables) {
+      this.variables = variables;
+    }
+
+    public IHopMetadataProvider getMetadataProvider() {
+      return metadataProvider;
+    }
+
+    public void setMetadataProvider(IHopMetadataProvider metadataProvider) {
+      this.metadataProvider = metadataProvider;
+    }
+
+    public boolean isHandled() {
+      return handled;
+    }
+
+    public void setHandled(boolean handled) {
+      this.handled = handled;
+    }
+  }
 }
diff --git 
a/plugins/misc/testing/src/main/java/org/apache/hop/testing/gui/TestingGuiPlugin.java
 
b/plugins/misc/testing/src/main/java/org/apache/hop/testing/gui/TestingGuiPlugin.java
index b6c65bd7d0..28ee451809 100644
--- 
a/plugins/misc/testing/src/main/java/org/apache/hop/testing/gui/TestingGuiPlugin.java
+++ 
b/plugins/misc/testing/src/main/java/org/apache/hop/testing/gui/TestingGuiPlugin.java
@@ -237,7 +237,7 @@ public class TestingGuiPlugin {
     IRowMeta transformFields;
     try {
       transformFields = pipelineMeta.getTransformFields(variables, 
transformMeta);
-    } catch (HopTransformException e) {
+    } catch (Exception e) {
       // Driver or input problems...
       //
       transformFields = new RowMeta();
diff --git 
a/plugins/misc/testing/src/main/java/org/apache/hop/testing/xp/PipelineGetFieldsExtensionPoint.java
 
b/plugins/misc/testing/src/main/java/org/apache/hop/testing/xp/PipelineGetFieldsExtensionPoint.java
new file mode 100644
index 0000000000..0a95df5bce
--- /dev/null
+++ 
b/plugins/misc/testing/src/main/java/org/apache/hop/testing/xp/PipelineGetFieldsExtensionPoint.java
@@ -0,0 +1,92 @@
+/*
+ * 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.
+ */
+
+package org.apache.hop.testing.xp;
+
+import org.apache.hop.core.exception.HopException;
+import org.apache.hop.core.extension.ExtensionPoint;
+import org.apache.hop.core.extension.IExtensionPoint;
+import org.apache.hop.core.logging.ILogChannel;
+import org.apache.hop.core.row.IRowMeta;
+import org.apache.hop.core.row.IValueMeta;
+import org.apache.hop.core.variables.IVariables;
+import org.apache.hop.pipeline.PipelineMeta;
+import org.apache.hop.pipeline.transform.TransformMeta;
+import org.apache.hop.testing.DataSet;
+import org.apache.hop.testing.PipelineUnitTest;
+import org.apache.hop.testing.PipelineUnitTestSetLocation;
+import org.apache.hop.testing.gui.TestingGuiPlugin;
+import org.apache.hop.testing.util.DataSetConst;
+
+@ExtensionPoint(
+    extensionPointId = "GetFieldsExtension",
+    id = "PipelineGetFieldsExtensionPoint",
+    description =
+        "Intercept field determination for transforms that have a unit test 
input dataset mapped to them")
+public class PipelineGetFieldsExtensionPoint
+    implements IExtensionPoint<PipelineMeta.GetFieldsExtension> {
+
+  @Override
+  public void callExtensionPoint(
+      ILogChannel log, IVariables variables, PipelineMeta.GetFieldsExtension 
extension)
+      throws HopException {
+    PipelineMeta pipelineMeta = extension.getPipelineMeta();
+    TransformMeta transformMeta = extension.getTransformMeta();
+
+    if (pipelineMeta == null || transformMeta == null) {
+      return;
+    }
+
+    // Check if a unit test is active in Hop GUI
+    PipelineUnitTest unitTest = 
TestingGuiPlugin.getCurrentUnitTest(pipelineMeta);
+    if (unitTest == null) {
+      return;
+    }
+
+    // Check if this transform has an input location mapping
+    PipelineUnitTestSetLocation inputLocation = 
unitTest.findInputLocation(transformMeta.getName());
+    if (inputLocation == null) {
+      return;
+    }
+
+    String dataSetName = inputLocation.getDataSetName();
+    if (dataSetName == null) {
+      return;
+    }
+
+    // Load dataset and get its fields
+    DataSet dataSet;
+    try {
+      dataSet = 
extension.getMetadataProvider().getSerializer(DataSet.class).load(dataSetName);
+    } catch (HopException e) {
+      throw new HopException("Unable to load data set '" + dataSetName + "'");
+    }
+
+    if (dataSet != null) {
+      IRowMeta outputRowMeta = DataSetConst.getTransformOutputFields(dataSet, 
inputLocation);
+      if (outputRowMeta != null) {
+        IRowMeta row = extension.getRow();
+        for (int i = 0; i < outputRowMeta.size(); i++) {
+          IValueMeta v = outputRowMeta.getValueMeta(i);
+          v.setOrigin(extension.getName());
+        }
+        row.addRowMeta(outputRowMeta);
+        extension.setHandled(true);
+      }
+    }
+  }
+}

Reply via email to