This is an automated email from the ASF dual-hosted git repository.

hansva pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hop.git


The following commit(s) were added to refs/heads/master by this push:
     new 9274eeb  HOP-2898 Refactor Coalesce Transform with @HopMetadataProperty
     new d913ca8  Merge pull request #815 from nadment/HOP-2898
9274eeb is described below

commit 9274eeb1dbe09b0093aa9c4b540d7240360a0a83
Author: nadment <[email protected]>
AuthorDate: Thu May 20 23:55:09 2021 +0200

    HOP-2898 Refactor Coalesce Transform with @HopMetadataProperty
---
 .../transforms/0016-coalesce-fields.hpl            |  14 +-
 .../transforms/coalesce/CoalesceDialog.java        |  33 ++---
 .../{CoalesceOperation.java => CoalesceField.java} |  96 +++++---------
 .../pipeline/transforms/coalesce/CoalesceMeta.java | 141 ++++-----------------
 .../transforms/coalesce/CoalesceTransform.java     |  34 +++--
 .../coalesce/messages/messages_en_US.properties    |   8 +-
 .../coalesce/CoalesceMetaInjectionTest.java        |   6 +-
 .../transforms/coalesce/CoalesceMetaTest.java      |   6 +-
 .../pipeline/transforms/coalesce/CoalesceTest.java |   4 +-
 9 files changed, 113 insertions(+), 229 deletions(-)

diff --git a/integration-tests/transforms/0016-coalesce-fields.hpl 
b/integration-tests/transforms/0016-coalesce-fields.hpl
index 2a98604..d4d2dc4 100644
--- a/integration-tests/transforms/0016-coalesce-fields.hpl
+++ b/integration-tests/transforms/0016-coalesce-fields.hpl
@@ -16,7 +16,7 @@
     <created_date>2021/05/18 11:17:47.076</created_date>
     <modified_user>-</modified_user>
     <modified_date>2021/05/18 11:17:47.076</modified_date>
-    <key_for_session_key/>
+    <key_for_session_key>H4sIAAAAAAAAAAMAAAAAAAAAAAA=</key_for_session_key>
     <is_key_private>N</is_key_private>
   </info>
   <notepads>
@@ -44,19 +44,15 @@
       <method>none</method>
       <schema_name/>
     </partitioning>
-    <empty_is_null>N</empty_is_null>
     <fields>
       <field>
+        <input>A, B, C</input>
         <name>result</name>
-        <value_type>String</value_type>
         <remove>N</remove>
-        <input>
-          <field>A</field>
-          <field>B</field>
-          <field>C</field>
-        </input>
+        <type>Boolean</type>
       </field>
     </fields>
+    <empty_is_null>Y</empty_is_null>
     <attributes/>
     <GUI>
       <xloc>288</xloc>
@@ -160,7 +156,7 @@
     </partitioning>
     <attributes/>
     <GUI>
-      <xloc>496</xloc>
+      <xloc>464</xloc>
       <yloc>96</yloc>
     </GUI>
   </transform>
diff --git 
a/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceDialog.java
 
b/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceDialog.java
index 9755641..32bb86d 100644
--- 
a/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceDialog.java
+++ 
b/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceDialog.java
@@ -160,22 +160,22 @@ public class CoalesceDialog extends BaseTransformDialog 
implements ITransformDia
 
     columns[1] =
         new ColumnInfo(
-            BaseMessages.getString(PKG, 
"CoalesceDialog.ColumnInfo.ValueType.Label"),
+            BaseMessages.getString(PKG, 
"CoalesceDialog.ColumnInfo.Type.Label"),
             ColumnInfo.COLUMN_TYPE_CCOMBO,
             ValueMetaBase.getTypes());
     columns[1].setToolTip(
-        BaseMessages.getString(PKG, 
"CoalesceDialog.ColumnInfo.ValueType.Tooltip"));
+        BaseMessages.getString(PKG, "CoalesceDialog.ColumnInfo.Type.Tooltip"));
 
     columns[2] =
         new ColumnInfo(
-            BaseMessages.getString(PKG, 
"CoalesceDialog.ColumnInfo.RemoveInputColumns.Label"),
+            BaseMessages.getString(PKG, 
"CoalesceDialog.ColumnInfo.RemoveInputFields.Label"),
             ColumnInfo.COLUMN_TYPE_CCOMBO,
             new String[] {
               BaseMessages.getString(PKG, "System.Combo.No"),
               BaseMessages.getString(PKG, "System.Combo.Yes")
             });
     columns[2].setToolTip(
-        BaseMessages.getString(PKG, 
"CoalesceDialog.ColumnInfo.RemoveInputColumns.Tooltip"));
+        BaseMessages.getString(PKG, 
"CoalesceDialog.ColumnInfo.RemoveInputFields.Tooltip"));
 
     columns[3] =
         new ColumnInfo(
@@ -193,7 +193,7 @@ public class CoalesceDialog extends BaseTransformDialog 
implements ITransformDia
             shell,
             SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE,
             columns,
-            input.getOperations().size(),
+            input.getFields().size(),
             e -> input.setChanged(),
             props);
     this.wFields.setLayoutData(
@@ -249,15 +249,15 @@ public class CoalesceDialog extends BaseTransformDialog 
implements ITransformDia
 
     wEmptyStrings.setSelection(input.isTreatEmptyStringsAsNulls());
 
-    List<CoalesceOperation> coalesces = input.getOperations();
+    List<CoalesceField> coalesces = input.getFields();
     for (int i = 0; i < coalesces.size(); i++) {
 
-      CoalesceOperation coalesce = coalesces.get(i);
+      CoalesceField coalesce = coalesces.get(i);
       TableItem item = wFields.getTable().getItem(i);
       item.setText(1, StringUtils.stripToEmpty(coalesce.getName()));
-      item.setText(2, ValueMetaBase.getTypeDesc(coalesce.getType()));
+      item.setText(2, StringUtils.stripToEmpty(coalesce.getType()));
       item.setText(3, getStringFromBoolean(coalesce.isRemoveFields()));
-      item.setText(4, String.join(", ", coalesce.getInputFields()));
+      item.setText(4, StringUtils.stripToEmpty(coalesce.getInputFields()));
     }
 
     wFields.setRowNums();
@@ -284,25 +284,20 @@ public class CoalesceDialog extends BaseTransformDialog 
implements ITransformDia
 
     int count = wFields.nrNonEmpty();
 
-    List<CoalesceOperation> coalesces = new ArrayList<>(count);
+    List<CoalesceField> coalesces = new ArrayList<>(count);
 
     for (int i = 0; i < count; i++) {
       TableItem item = wFields.getNonEmpty(i);
 
-      CoalesceOperation coalesce = new CoalesceOperation();
+      CoalesceField coalesce = new CoalesceField();
       coalesce.setName(item.getText(1));
-
-      String typeValueText = item.getText(2);
-      coalesce.setType(
-          Utils.isEmpty(typeValueText)
-              ? IValueMeta.TYPE_NONE
-              : ValueMetaBase.getType(typeValueText));
+      coalesce.setType(item.getText(2));
       coalesce.setRemoveFields(getBooleanFromString(item.getText(3)));
-      coalesce.setInputFields(item.getText(4));
+      coalesce.setInputFields(StringUtils.stripToNull(item.getText(4)));
       coalesces.add(coalesce);
     }
 
-    input.setOperations(coalesces);
+    input.setFields(coalesces);
 
     dispose();
   }
diff --git 
a/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceOperation.java
 
b/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceField.java
similarity index 53%
rename from 
plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceOperation.java
rename to 
plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceField.java
index 299709f..c601f2f 100644
--- 
a/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceOperation.java
+++ 
b/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceField.java
@@ -18,69 +18,50 @@
 package org.apache.hop.pipeline.transforms.coalesce;
 
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.commons.lang.StringUtils;
-import org.apache.hop.core.injection.Injection;
 import org.apache.hop.core.row.IValueMeta;
 import org.apache.hop.core.row.value.ValueMetaFactory;
-import org.apache.hop.core.util.Utils;
+import org.apache.hop.metadata.api.HopMetadataProperty;
 
 /**
  * Contains the properties of the inputs fields, target field name, target 
value type and options.
  *
  * @author Nicolas ADMENT
  */
-public class CoalesceOperation implements Cloneable {
-
-  private List<String> fields = new ArrayList<>();
-
-  private int type = IValueMeta.TYPE_NONE;
+public class CoalesceField implements Cloneable {
 
   /** The target field name */
-  @Injection(name = "NAME", group = "FIELDS")
+  @HopMetadataProperty(key = "name", injectionKey="NAME", 
injectionKeyDescription = "CoalesceMeta.Injection.Field.Name")
   private String name;
 
-  @Injection(name = "TYPE", group = "FIELDS")
-  public void setType(final String name) {
-    this.type = ValueMetaFactory.getIdForValueMeta(name);
-  }
-
-  @Injection(name = "INPUT_FIELDS", group = "FIELDS")
-  public void setInputFields(final String fields) {
-
-    this.fields = new ArrayList<>();
+  @HopMetadataProperty(key = "type",  injectionKey="TYPE", 
injectionKeyDescription = "CoalesceMeta.Injection.Field.Type")
+  private String type = 
ValueMetaFactory.getValueMetaName(IValueMeta.TRIM_TYPE_NONE);
 
-    if (fields != null) {
-      for (String field : fields.split("\\s*,\\s*")) {
-        this.addInputField(field);
-      }
-    }
-  }
-
-  @Injection(name = "REMOVE_INPUT_FIELDS", group = "FIELDS")
+  @HopMetadataProperty(key = "remove", injectionKey="REMOVE_INPUT_FIELDS", 
injectionKeyDescription = "CoalesceMeta.Injection.Field.Remove")
   private boolean removeFields;
+     
+  @HopMetadataProperty(key = "input", injectionKey="INPUT_FIELDS",  
injectionKeyDescription = "CoalesceMeta.Injection.Field.InputFields")
+  private String inputFields;
 
-  public CoalesceOperation() {
+  private List<String> cache = new ArrayList<>();
+
+  public CoalesceField() {
     super();
   }
 
-  public CoalesceOperation(CoalesceOperation cloned) {
+  public CoalesceField(CoalesceField cloned) {
     super();
     this.name = cloned.name;
     this.type = cloned.type;
     this.removeFields = cloned.removeFields;
-
-    Iterator<String> iterator = cloned.fields.iterator();
-    while (iterator.hasNext()) {
-      fields.add(iterator.next());
-    }
+    this.setInputFields(cloned.inputFields);
   }
 
   @Override
   public Object clone() {
-    return new CoalesceOperation(this);
+    return new CoalesceField(this);
   }
 
   public String getName() {
@@ -91,43 +72,34 @@ public class CoalesceOperation implements Cloneable {
     this.name = StringUtils.stripToNull(name);
   }
 
-  public List<String> getInputFields() {
-    return this.fields;
+  public String getInputFields() {
+    return this.inputFields;
   }
 
-  public String getInputField(int index) {
-    return this.fields.get(index);
-  }
-
-  public void addInputField(final String field) {
-    // Ignore empty field
-    if (Utils.isEmpty(field)) return;
-
-    this.fields.add(field);
+  public void setInputFields(final String fields) {
+    this.inputFields = fields;
+        
+    // Rebuild cache
+    cache = new ArrayList<>();
+    if (inputFields != null) {
+      for (String field : inputFields.split("\\s*,\\s*")) {
+          this.cache.add(field);
+      }
+    }    
   }
-
-  public void removeInputField(final String field) {
-    this.fields.remove(field);
+  
+  public List<String> getInputFieldNames() {
+      return cache;
   }
-
-  public void setInputFields(final List<String> fields) {
-
-    if (fields == null) this.fields = new ArrayList<>();
-    else this.fields = fields;
-  }
-
-  public int getType() {
+    
+  public String getType() {
     return this.type;
   }
 
-  public void setType(final int type) {
+  public void setType(final String type) {
     this.type = type;
   }
 
-  private String getTypeDesc() {
-    return ValueMetaFactory.getValueMetaName(this.type);
-  }
-
   /**
    * Remove input fields
    *
@@ -143,6 +115,6 @@ public class CoalesceOperation implements Cloneable {
 
   @Override
   public String toString() {
-    return name + ":" + getTypeDesc();
+    return name + ":" + type;
   }
 }
diff --git 
a/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceMeta.java
 
b/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceMeta.java
index 2208b28..0051426 100644
--- 
a/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceMeta.java
+++ 
b/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceMeta.java
@@ -19,33 +19,25 @@ package org.apache.hop.pipeline.transforms.coalesce;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.hop.core.CheckResult;
-import org.apache.hop.core.Const;
 import org.apache.hop.core.ICheckResult;
 import org.apache.hop.core.annotations.Transform;
 import org.apache.hop.core.exception.HopTransformException;
-import org.apache.hop.core.exception.HopValueException;
-import org.apache.hop.core.exception.HopXmlException;
-import org.apache.hop.core.injection.Injection;
-import org.apache.hop.core.injection.InjectionDeep;
-import org.apache.hop.core.injection.InjectionSupported;
 import org.apache.hop.core.row.IRowMeta;
 import org.apache.hop.core.row.IValueMeta;
 import org.apache.hop.core.row.value.ValueMetaFactory;
 import org.apache.hop.core.variables.IVariables;
-import org.apache.hop.core.xml.XmlHandler;
 import org.apache.hop.i18n.BaseMessages;
+import org.apache.hop.metadata.api.HopMetadataProperty;
 import org.apache.hop.metadata.api.IHopMetadataProvider;
 import org.apache.hop.pipeline.Pipeline;
 import org.apache.hop.pipeline.PipelineMeta;
 import org.apache.hop.pipeline.transform.BaseTransformMeta;
 import org.apache.hop.pipeline.transform.ITransformMeta;
 import org.apache.hop.pipeline.transform.TransformMeta;
-import org.w3c.dom.Node;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
@@ -57,39 +49,28 @@ import java.util.Set;
     image = "coalesce.svg",
     categoryDescription = 
"i18n:org.apache.hop.pipeline.transform:BaseTransform.Category.Transform",
     documentationUrl = 
"https://hop.apache.org/manual/latest/pipeline/transforms/coalesce.html";)
-@InjectionSupported(
-    localizationPrefix = "CoalesceMeta.Injection.",
-    groups = {"FIELDS"})
 public class CoalesceMeta extends BaseTransformMeta
     implements ITransformMeta<CoalesceTransform, CoalesceData> {
 
   private static final Class<?> PKG = CoalesceMeta.class; // for i18n purposes
 
-  private static final String TAG_NAME = "name";
-  private static final String TAG_FIELD = "field";
-  private static final String TAG_FIELDS = "fields";
-  private static final String TAG_INPUT = "input";
-  private static final String TAG_VALUE_TYPE = "value_type";
-  private static final String TAG_EMPTY_IS_NULL = "empty_is_null";
-  private static final String TAG_REMOVE = "remove";
-
   /** The fields to coalesce */
-  @InjectionDeep private List<CoalesceOperation> operations;
-
-  /** additional options */
-  @Injection(name = "EMPTY_STRING_AS_NULLS")
-  private boolean emptyStringsAsNulls;
+  @HopMetadataProperty(key = "field", groupKey = "fields", 
injectionGroupDescription = "CoalesceMeta.Injection.Fields", 
injectionKeyDescription = "CoalesceMeta.Injection.Field")
+  private List<CoalesceField> fields = new ArrayList<>();
 
+  /** additional options */  
+  @HopMetadataProperty(key = "empty_is_null", 
injectionKey="EMPTY_STRING_AS_NULLS", injectionKeyDescription = 
"CoalesceMeta.Injection.EmptyStringAsNulls") 
+  private boolean treatEmptyStringsAsNulls;
+  
   public CoalesceMeta() {
-    operations = new ArrayList<>();
+    fields = new ArrayList<>();
   }
 
   public CoalesceMeta(CoalesceMeta c) {
     super();
-    this.emptyStringsAsNulls = c.emptyStringsAsNulls;
-    Iterator<CoalesceOperation> iterator = c.operations.iterator();
-    while (iterator.hasNext()) {
-      operations.add(new CoalesceOperation(iterator.next()));
+    this.treatEmptyStringsAsNulls = c.treatEmptyStringsAsNulls;
+    for (CoalesceField field: c.getFields())  {
+      fields.add(new CoalesceField(field));
     }
   }
 
@@ -110,16 +91,16 @@ public class CoalesceMeta extends BaseTransformMeta
 
   @Override
   public void setDefault() {
-    this.operations = new ArrayList<>();
-    this.emptyStringsAsNulls = false;
+    this.fields = new ArrayList<>();
+    this.treatEmptyStringsAsNulls = false;
   }
 
   public boolean isTreatEmptyStringsAsNulls() {
-    return this.emptyStringsAsNulls;
+    return this.treatEmptyStringsAsNulls;
   }
 
   public void setTreatEmptyStringsAsNulls(boolean value) {
-    this.emptyStringsAsNulls = value;
+    this.treatEmptyStringsAsNulls = value;
   }
 
   @Override
@@ -128,72 +109,6 @@ public class CoalesceMeta extends BaseTransformMeta
   }
 
   @Override
-  public String getXml() throws HopValueException {
-
-    StringBuilder xml = new StringBuilder(500);
-
-    xml.append(XmlHandler.addTagValue(TAG_EMPTY_IS_NULL, emptyStringsAsNulls));
-
-    xml.append(XmlHandler.openTag(TAG_FIELDS));
-    for (CoalesceOperation coalesce : operations) {
-      xml.append(XmlHandler.openTag(TAG_FIELD));
-
-      xml.append(XmlHandler.addTagValue(TAG_NAME, coalesce.getName()));
-      xml.append(
-          XmlHandler.addTagValue(
-              TAG_VALUE_TYPE, 
ValueMetaFactory.getValueMetaName(coalesce.getType())));
-      xml.append(XmlHandler.addTagValue(TAG_REMOVE, 
coalesce.isRemoveFields()));
-
-      xml.append(XmlHandler.openTag(TAG_INPUT));
-      for (String field : coalesce.getInputFields()) {
-        xml.append(XmlHandler.addTagValue(TAG_FIELD, field));
-      }
-      xml.append(XmlHandler.closeTag(TAG_INPUT));
-
-      xml.append(XmlHandler.closeTag(TAG_FIELD));
-    }
-    xml.append(XmlHandler.closeTag(TAG_FIELDS));
-
-    return xml.toString();
-  }
-
-  @Override
-  public void loadXml(Node transformNode, IHopMetadataProvider 
metadataProvider)
-      throws HopXmlException {
-
-    try {
-      this.emptyStringsAsNulls =
-          "Y".equalsIgnoreCase(XmlHandler.getTagValue(transformNode, 
TAG_EMPTY_IS_NULL));
-
-      Node fields = XmlHandler.getSubNode(transformNode, TAG_FIELDS);
-      int count = XmlHandler.countNodes(fields, TAG_FIELD);
-      operations = new ArrayList<>(count);
-      for (int i = 0; i < count; i++) {
-        Node line = XmlHandler.getSubNodeByNr(fields, TAG_FIELD, i);
-
-        CoalesceOperation coalesce = new CoalesceOperation();
-        coalesce.setName(Const.NVL(XmlHandler.getTagValue(line, TAG_NAME), 
""));
-        coalesce.setType(XmlHandler.getTagValue(line, TAG_VALUE_TYPE));
-        
coalesce.setRemoveFields("Y".equalsIgnoreCase(XmlHandler.getTagValue(line, 
TAG_REMOVE)));
-
-        Node input = XmlHandler.getSubNode(line, TAG_INPUT);
-        if (input != null) {
-          Node field = input.getFirstChild();
-          while (field != null) {
-            coalesce.addInputField(XmlHandler.getNodeValue(field));
-            field = field.getNextSibling();
-          }
-        }
-
-        operations.add(coalesce);
-      }
-    } catch (Exception e) {
-      throw new HopXmlException(
-          BaseMessages.getString(PKG, 
"CoalesceMeta.Exception.UnableToReadXML"), e);
-    }
-  }
-
-  @Override
   public void getFields(
       IRowMeta rowMeta,
       String transformName,
@@ -207,14 +122,14 @@ public class CoalesceMeta extends BaseTransformMeta
       IRowMeta unalteredInputRowMeta = rowMeta.clone();
 
       // first remove all unwanted input fields from the stream
-      for (CoalesceOperation coalesce : this.getOperations()) {
+      for (CoalesceField coalesce : this.getFields()) {
 
         if (coalesce.isRemoveFields()) {
 
           // Resolve variable name
           String name = variables.resolve(coalesce.getName());
 
-          for (String fieldName : coalesce.getInputFields()) {
+          for (String fieldName : coalesce.getInputFieldNames()) {
 
             // If input field name is recycled for output, don't
             // remove
@@ -228,8 +143,8 @@ public class CoalesceMeta extends BaseTransformMeta
       }
 
       // then add the output fields
-      for (CoalesceOperation coalesce : this.getOperations()) {
-        int type = coalesce.getType();
+      for (CoalesceField coalesce : this.getFields()) {
+        int type = ValueMetaFactory.getIdForValueMeta(coalesce.getType());
         if (type == IValueMeta.TYPE_NONE) {
           type = findDefaultValueType(unalteredInputRowMeta, coalesce);
         }
@@ -299,13 +214,13 @@ public class CoalesceMeta extends BaseTransformMeta
 
     // See if there are missing, duplicate or not enough input streams
     boolean missing = false;
-    for (CoalesceOperation coalesce : this.getOperations()) {
+    for (CoalesceField coalesce : this.getFields()) {
 
       Set<String> fields = new HashSet<>();
       List<String> missingFields = new ArrayList<>();
       List<String> duplicateFields = new ArrayList<>();
 
-      for (String fieldName : coalesce.getInputFields()) {
+      for (String fieldName : coalesce.getInputFieldNames()) {
 
         if (fields.contains(fieldName)) duplicateFields.add(fieldName);
         else fields.add(fieldName);
@@ -349,7 +264,7 @@ public class CoalesceMeta extends BaseTransformMeta
     }
 
     // See if there something to coalesce
-    if (this.getOperations().isEmpty()) {
+    if (this.getFields().isEmpty()) {
       remarks.add(
           new CheckResult(
               ICheckResult.TYPE_RESULT_WARNING,
@@ -368,12 +283,12 @@ public class CoalesceMeta extends BaseTransformMeta
    * If all fields are of the same data type then the output field should 
mirror this otherwise
    * return a more generic String type
    */
-  private int findDefaultValueType(final IRowMeta inputRowMeta, final 
CoalesceOperation coalesce) {
+  private int findDefaultValueType(final IRowMeta inputRowMeta, final 
CoalesceField coalesce) {
 
     int type = IValueMeta.TYPE_NONE;
     boolean first = true;
 
-    for (String field : coalesce.getInputFields()) {
+    for (String field : coalesce.getInputFieldNames()) {
 
       if (first) {
         type = getInputFieldValueType(inputRowMeta, field);
@@ -459,11 +374,11 @@ public class CoalesceMeta extends BaseTransformMeta
     return IValueMeta.TYPE_NONE;
   }
 
-  public List<CoalesceOperation> getOperations() {
-    return operations;
+  public List<CoalesceField> getFields() {
+    return fields;
   }
 
-  public void setOperations(List<CoalesceOperation> operations) {
-    this.operations = (operations == null) ? Collections.emptyList() : 
operations;
+  public void setFields(List<CoalesceField> fields) {
+    this.fields = (fields == null) ? Collections.emptyList() : fields;
   }
 }
diff --git 
a/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceTransform.java
 
b/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceTransform.java
index ddc3cc1..5caf656 100644
--- 
a/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceTransform.java
+++ 
b/plugins/transforms/coalesce/src/main/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceTransform.java
@@ -80,11 +80,20 @@ public class CoalesceTransform extends 
BaseTransform<CoalesceMeta, CoalesceData>
 
       first = false;
       // clone the input row structure and place it in our data object
-      data.outputRowMeta = getInputRowMeta().clone();
+      data.outputRowMeta = getInputRowMeta().clone();    
+      
       // use meta.getFields() to change it, so it reflects the output row
       // structure
       meta.getFields(data.outputRowMeta, getTransformName(), null, null, this, 
metadataProvider);
 
+      // Check output name
+      for (CoalesceField coalesce : meta.getFields()) {
+        String name = this.resolve(coalesce.getName());
+        if ( Utils.isEmpty(name) ) {
+          throw new 
HopException(BaseMessages.getString(PKG,"CoalesceTransform.Log.MissingFieldName"));
+        }        
+      }
+            
       checkInputFieldsExist(meta);
     }
 
@@ -107,14 +116,14 @@ public class CoalesceTransform extends 
BaseTransform<CoalesceMeta, CoalesceData>
     // Calculates the coalesce value for each extra output field and also
     // converts its value to reflect the Value Type option,
     // or in case it was None to reflect on the default data type logic.
-    for (CoalesceOperation coalesce : meta.getOperations()) {
+    for (CoalesceField coalesce : meta.getFields()) {
 
-      int inputIndex = getFirstNonNullValueIndex(meta, inputRowMeta, row, 
coalesce);
+      int inputIndex = getFirstNonNullValueIndex(inputRowMeta, row, 
coalesce.getInputFieldNames(), meta.isTreatEmptyStringsAsNulls());
 
       // Resolve variable name
       String name = this.resolve(coalesce.getName());
       outputIndex = data.outputRowMeta.indexOfValue(name);
-
+      
       IValueMeta vm = data.outputRowMeta.getValueMeta(outputIndex);
       try {
         Object result = null;
@@ -155,10 +164,10 @@ public class CoalesceTransform extends 
BaseTransform<CoalesceMeta, CoalesceData>
   private void checkInputFieldsExist(final CoalesceMeta meta) throws 
HopException {
     IRowMeta prev = getInputRowMeta();
 
-    for (CoalesceOperation coalesce : meta.getOperations()) {
+    for (CoalesceField coalesce : meta.getFields()) {
       List<String> missingFields = new ArrayList<>();
 
-      for (String field : coalesce.getInputFields()) {
+      for (String field : coalesce.getInputFieldNames()) {
 
         if (!Utils.isEmpty(field)) {
           IValueMeta vmi = prev.searchValueMeta(field);
@@ -179,19 +188,18 @@ public class CoalesceTransform extends 
BaseTransform<CoalesceMeta, CoalesceData>
   }
 
   /** The actual coalesce logic, returns the index of the first non null value 
*/
-  private int getFirstNonNullValueIndex(
-      final CoalesceMeta meta,
+  private int getFirstNonNullValueIndex(      
       final IRowMeta inputRowMeta,
       Object[] row,
-      CoalesceOperation coalesce) {
+      List<String> fields, boolean isTreatEmptyStringsAsNulls) {
 
-    for (String field : coalesce.getInputFields()) {
+    for (String fieldName : fields) {
 
-      int index = inputRowMeta.indexOfValue(field);
+      int index = inputRowMeta.indexOfValue(fieldName);
       if (index >= 0) {
-        if (!meta.isTreatEmptyStringsAsNulls() && row[index] != null) {
+        if (!isTreatEmptyStringsAsNulls && row[index] != null) {
           return index;
-        } else if (meta.isTreatEmptyStringsAsNulls()
+        } else if (isTreatEmptyStringsAsNulls
             && row[index] != null
             && !Utils.isEmpty(row[index].toString())) return index;
       }
diff --git 
a/plugins/transforms/coalesce/src/main/resources/org/apache/hop/pipeline/transforms/coalesce/messages/messages_en_US.properties
 
b/plugins/transforms/coalesce/src/main/resources/org/apache/hop/pipeline/transforms/coalesce/messages/messages_en_US.properties
index ae80447..bdb6e93 100644
--- 
a/plugins/transforms/coalesce/src/main/resources/org/apache/hop/pipeline/transforms/coalesce/messages/messages_en_US.properties
+++ 
b/plugins/transforms/coalesce/src/main/resources/org/apache/hop/pipeline/transforms/coalesce/messages/messages_en_US.properties
@@ -25,15 +25,14 @@ CoalesceDialog.ColumnInfo.Type.Label=Type
 CoalesceDialog.ColumnInfo.Type.Tooltip=The output value type
 CoalesceDialog.ColumnInfo.InputFields.Label=Input fields
 CoalesceDialog.ColumnInfo.InputFields.Tooltip=The input fields name. The order 
of the input fields listed in the columns determines the order in which they 
are evaluated
-CoalesceDialog.ColumnInfo.Remove.Label=Remove fields
-CoalesceDialog.ColumnInfo.Remove.Tooltip=Remove input fields from stream
+CoalesceDialog.ColumnInfo.RemoveInputFields.Label=Remove fields
+CoalesceDialog.ColumnInfo.RemoveInputFields.Tooltip=Remove input fields from 
stream
 CoalesceDialog.Log.UnableToFindInput=Sorry, couldn''t find previous transform 
fields...
 CoalesceDialog.Log.FoundFields=Found {0} fields
 CoalesceDialog.Validations.DialogTitle=Warning\!
 CoalesceDialog.Validations.DialogMessage=The Coalesce transform needs to have 
at least 2 non empty inputs\!
 CoalesceDialog.Validations.Option.1=I understand
 CoalesceDialog.Validations.Option.2=Please, don''t show this warning anymore.
-CoalesceMeta.Exception.UnableToReadXML=Unable to read transform information 
from XML 
 CoalesceMeta.Exception.SourceFieldNotFound=Unable to find field [{0}] in the 
input row.{1}This is the input row\: {2} 
 CoalesceMeta.CheckResult.ReceivingFieldsFromPreviousTransforms=Transform is 
connected to previous one, receiving {0} fields.
 CoalesceMeta.CheckResult.NotReceivingFieldsFromPreviousTransforms=Not 
receiving any fields from previous transforms\!
@@ -55,6 +54,5 @@ CoalesceMeta.Injection.Field.Remove=Remove inputs fields
 CoalesceTransform.Log.WroteRowToNextTransform=Wrote row to next transform: {0}
 CoalesceTransform.Log.StartedProcessing=Started transform processing
 CoalesceTransform.Log.DataIncompatibleError=Cannot convert [{0}] of [{1}] to 
[{2}]
+CoalesceTransform.Log.MissingFieldName=Missing field name
 CoalesceTransform.Log.MissingInputFields=Missing input fields: {0}
-CoalesceDialog.ColumnInfo.ValueType.Label=Value type
-CoalesceDialog.ColumnInfo.RemoveInputColumns.Label=Remove?
diff --git 
a/plugins/transforms/coalesce/src/test/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceMetaInjectionTest.java
 
b/plugins/transforms/coalesce/src/test/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceMetaInjectionTest.java
index 6c55dd8..3569f5b 100644
--- 
a/plugins/transforms/coalesce/src/test/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceMetaInjectionTest.java
+++ 
b/plugins/transforms/coalesce/src/test/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceMetaInjectionTest.java
@@ -30,10 +30,10 @@ public class CoalesceMetaInjectionTest extends 
BaseMetadataInjectionTest<Coalesc
   @Test
   public void test() throws Exception {
     check("EMPTY_STRING_AS_NULLS", () -> meta.isTreatEmptyStringsAsNulls());
-    check("NAME", () -> meta.getOperations().get(0).getName());
+    check("NAME", () -> meta.getFields().get(0).getName());
     // check( "TYPE", () -> meta.getOperations().get(0).getType() );
     skipPropertyTest("TYPE");
-    check("INPUT_FIELDS", () -> meta.getOperations().get(0).getInputField(0));
-    check("REMOVE_INPUT_FIELDS", () -> 
meta.getOperations().get(0).isRemoveFields());
+    check("INPUT_FIELDS", () -> meta.getFields().get(0).getInputFields());
+    check("REMOVE_INPUT_FIELDS", () -> 
meta.getFields().get(0).isRemoveFields());
   }
 }
diff --git 
a/plugins/transforms/coalesce/src/test/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceMetaTest.java
 
b/plugins/transforms/coalesce/src/test/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceMetaTest.java
index 357d31c..8e39cb1 100644
--- 
a/plugins/transforms/coalesce/src/test/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceMetaTest.java
+++ 
b/plugins/transforms/coalesce/src/test/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceMetaTest.java
@@ -44,7 +44,7 @@ public class CoalesceMetaTest {
     assertEquals(3, prop.getPath().size());
     BeanLevelInfo info = prop.getPath().get(1);
     assertEquals(BeanLevelInfo.DIMENSION.LIST, info.dim);
-    assertEquals(CoalesceOperation.class, info.leafClass);
+    assertEquals(CoalesceField.class, info.leafClass);
 
     info = prop.getPath().get(2);
     assertEquals(String.class, info.leafClass);
@@ -74,7 +74,7 @@ public class CoalesceMetaTest {
     injector.setProperty(meta, "INPUT_FIELDS", resultRows, "inputs");
     injector.setProperty(meta, "REMOVE_INPUT_FIELDS", resultRows, "remove?");
 
-    assertEquals(3, meta.getOperations().size());
-    assertEquals("result1", meta.getOperations().get(0).getName());
+    assertEquals(3, meta.getFields().size());
+    assertEquals("result1", meta.getFields().get(0).getName());
   }
 }
diff --git 
a/plugins/transforms/coalesce/src/test/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceTest.java
 
b/plugins/transforms/coalesce/src/test/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceTest.java
index f0581ca..42a2a54 100644
--- 
a/plugins/transforms/coalesce/src/test/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceTest.java
+++ 
b/plugins/transforms/coalesce/src/test/java/org/apache/hop/pipeline/transforms/coalesce/CoalesceTest.java
@@ -37,11 +37,11 @@ public class CoalesceTest {
 
   @Test
   public void testLoadSave() throws HopException {
-    List<String> attributes = Arrays.asList( "TreatEmptyStringsAsNulls" );
+    List<String> attributes = Arrays.asList( "treatEmptyStringsAsNulls" );
 
     LoadSaveTester<CoalesceMeta> loadSaveTester =
       new LoadSaveTester<CoalesceMeta>( CoalesceMeta.class, attributes );
 
     loadSaveTester.testSerialization();
-}
+  }
 }

Reply via email to