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 6f3ede7d36 issue #7441 : Add Enter Field Mapping button to Update
transform (#7484)
6f3ede7d36 is described below
commit 6f3ede7d369beee733aa1415f4730c1c03253001
Author: Matt Casters <[email protected]>
AuthorDate: Wed Jul 15 12:47:23 2026 +0200
issue #7441 : Add Enter Field Mapping button to Update transform (#7484)
---
.../pipeline/transforms/update/UpdateDialog.java | 168 ++++++++++++++++++++-
.../hop/pipeline/transforms/update/UpdateMeta.java | 34 +++++
.../update/messages/messages_en_US.properties | 13 ++
3 files changed, 214 insertions(+), 1 deletion(-)
diff --git
a/plugins/transforms/update/src/main/java/org/apache/hop/pipeline/transforms/update/UpdateDialog.java
b/plugins/transforms/update/src/main/java/org/apache/hop/pipeline/transforms/update/UpdateDialog.java
index e336835817..79e398bb21 100644
---
a/plugins/transforms/update/src/main/java/org/apache/hop/pipeline/transforms/update/UpdateDialog.java
+++
b/plugins/transforms/update/src/main/java/org/apache/hop/pipeline/transforms/update/UpdateDialog.java
@@ -23,6 +23,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.hop.core.Const;
import org.apache.hop.core.DbCache;
import org.apache.hop.core.Props;
+import org.apache.hop.core.SourceToTargetMapping;
import org.apache.hop.core.SqlStatement;
import org.apache.hop.core.database.Database;
import org.apache.hop.core.database.DatabaseMeta;
@@ -39,6 +40,7 @@ import org.apache.hop.ui.core.PropsUi;
import org.apache.hop.ui.core.database.dialog.DatabaseExplorerDialog;
import org.apache.hop.ui.core.database.dialog.SqlEditor;
import org.apache.hop.ui.core.dialog.BaseDialog;
+import org.apache.hop.ui.core.dialog.EnterMappingDialog;
import org.apache.hop.ui.core.dialog.EnterSelectionDialog;
import org.apache.hop.ui.core.dialog.ErrorDialog;
import org.apache.hop.ui.core.dialog.MessageBox;
@@ -487,7 +489,14 @@ public class UpdateDialog extends BaseTransformDialog {
Button wGetUpdateFields = new Button(composite, SWT.PUSH);
wGetUpdateFields.setText(BaseMessages.getString(PKG,
"UpdateDialog.GetAndUpdateFields"));
wGetUpdateFields.addListener(SWT.Selection, e -> getUpdateFields());
- setButtonPositions(new Button[] {wGetUpdateFields}, margin, null);
+ PropsUi.setLook(wGetUpdateFields);
+
+ Button wDoMapping = new Button(composite, SWT.PUSH);
+ wDoMapping.setText(BaseMessages.getString(PKG,
"UpdateDialog.DoMapping.Button"));
+ wDoMapping.addListener(SWT.Selection, e -> generateMappings());
+ PropsUi.setLook(wDoMapping);
+
+ setButtonPositions(new Button[] {wGetUpdateFields, wDoMapping}, margin,
null);
wReturn.setLayoutData(
FormDataBuilder.builder()
@@ -497,6 +506,163 @@ public class UpdateDialog extends BaseTransformDialog {
.result());
}
+ /**
+ * Reads in the fields from the previous transforms and from the target
table and opens an
+ * EnterMappingDialog with this information. After the user did the mapping,
that information is
+ * put into the update fields table.
+ */
+ private void generateMappings() {
+
+ // Determine the source and target fields...
+ //
+ IRowMeta sourceFields;
+ IRowMeta targetFields;
+
+ try {
+ sourceFields = pipelineMeta.getPrevTransformFields(variables,
transformMeta);
+ } catch (HopException e) {
+ new ErrorDialog(
+ shell,
+ BaseMessages.getString(PKG,
"UpdateDialog.DoMapping.UnableToFindSourceFields.Title"),
+ BaseMessages.getString(PKG,
"UpdateDialog.DoMapping.UnableToFindSourceFields.Message"),
+ e);
+ return;
+ }
+
+ // Load target table fields from the currently selected
connection/schema/table
+ // without mutating the transform meta (so Cancel still discards dialog
edits).
+ DatabaseMeta databaseMeta =
pipelineMeta.findDatabase(wConnection.getText(), variables);
+ if (databaseMeta == null) {
+ new ErrorDialog(
+ shell,
+ BaseMessages.getString(PKG,
"UpdateDialog.DoMapping.UnableToFindTargetFields.Title"),
+ BaseMessages.getString(PKG,
"UpdateDialog.DoMapping.UnableToFindTargetFields.Message"),
+ new HopException(
+ BaseMessages.getString(PKG,
"UpdateMeta.Exception.ConnectionNotDefined")));
+ return;
+ }
+ try (Database db = new Database(loggingObject, variables, databaseMeta)) {
+ db.connect();
+ String realSchemaName = variables.resolve(wSchema.getText());
+ String realTableName = variables.resolve(wTable.getText());
+ if (Utils.isEmpty(realTableName)) {
+ throw new HopException(
+ BaseMessages.getString(PKG,
"UpdateMeta.Exception.TableNotSpecified"));
+ }
+ targetFields = db.getTableFieldsMeta(realSchemaName, realTableName);
+ if (targetFields == null) {
+ throw new HopException(BaseMessages.getString(PKG,
"UpdateMeta.Exception.TableNotFound"));
+ }
+ } catch (Exception e) {
+ new ErrorDialog(
+ shell,
+ BaseMessages.getString(PKG,
"UpdateDialog.DoMapping.UnableToFindTargetFields.Title"),
+ BaseMessages.getString(PKG,
"UpdateDialog.DoMapping.UnableToFindTargetFields.Message"),
+ e);
+ return;
+ }
+
+ // Create the existing mapping list...
+ //
+ List<SourceToTargetMapping> mappings = new ArrayList<>();
+ StringBuilder missingSourceFields = new StringBuilder();
+ StringBuilder missingTargetFields = new StringBuilder();
+
+ int nrFields = wReturn.nrNonEmpty();
+ for (int i = 0; i < nrFields; i++) {
+ TableItem item = wReturn.getNonEmpty(i);
+ String source = item.getText(2);
+ String target = item.getText(1);
+
+ int sourceIndex = sourceFields.indexOfValue(source);
+ if (sourceIndex < 0) {
+ missingSourceFields
+ .append(Const.CR)
+ .append(" ")
+ .append(source)
+ .append(" --> ")
+ .append(target);
+ }
+ int targetIndex = targetFields.indexOfValue(target);
+ if (targetIndex < 0) {
+ missingTargetFields
+ .append(Const.CR)
+ .append(" ")
+ .append(source)
+ .append(" --> ")
+ .append(target);
+ }
+ if (sourceIndex < 0 || targetIndex < 0) {
+ continue;
+ }
+
+ SourceToTargetMapping mapping = new SourceToTargetMapping(sourceIndex,
targetIndex);
+ mappings.add(mapping);
+ }
+
+ // show a confirm dialog if some missing field was found
+ //
+ if (!missingSourceFields.isEmpty() || !missingTargetFields.isEmpty()) {
+
+ String message = "";
+ if (!missingSourceFields.isEmpty()) {
+ message +=
+ BaseMessages.getString(
+ PKG,
+ "UpdateDialog.DoMapping.SomeSourceFieldsNotFound",
+ missingSourceFields.toString())
+ + Const.CR;
+ }
+ if (!missingTargetFields.isEmpty()) {
+ message +=
+ BaseMessages.getString(
+ PKG,
+ "UpdateDialog.DoMapping.SomeTargetFieldsNotFound",
+ missingTargetFields.toString())
+ + Const.CR;
+ }
+ message += Const.CR;
+ message +=
+ BaseMessages.getString(PKG,
"UpdateDialog.DoMapping.SomeFieldsNotFoundContinue")
+ + Const.CR;
+ int answer =
+ BaseDialog.openMessageBox(
+ shell,
+ BaseMessages.getString(PKG,
"UpdateDialog.DoMapping.SomeFieldsNotFoundTitle"),
+ message,
+ SWT.ICON_QUESTION | SWT.YES | SWT.NO);
+ boolean goOn = (answer & SWT.YES) != 0;
+ if (!goOn) {
+ return;
+ }
+ }
+ EnterMappingDialog d =
+ new EnterMappingDialog(
+ UpdateDialog.this.shell,
+ sourceFields.getFieldNames(),
+ targetFields.getFieldNames(),
+ mappings);
+ mappings = d.open();
+
+ // mappings == null if the user pressed cancel
+ //
+ if (mappings != null) {
+ // Clear and re-populate!
+ //
+ wReturn.table.removeAll();
+ wReturn.table.setItemCount(mappings.size());
+ for (int i = 0; i < mappings.size(); i++) {
+ SourceToTargetMapping mapping = mappings.get(i);
+ TableItem item = wReturn.table.getItem(i);
+ item.setText(2,
sourceFields.getValueMeta(mapping.getSourcePosition()).getName());
+ item.setText(1,
targetFields.getValueMeta(mapping.getTargetPosition()).getName());
+ }
+ wReturn.setRowNums();
+ wReturn.optWidth(true);
+ input.setChanged();
+ }
+ }
+
public void setActiveIgnoreLookup() {
if (wSkipLookup.getSelection()) {
wErrorIgnored.setSelection(false);
diff --git
a/plugins/transforms/update/src/main/java/org/apache/hop/pipeline/transforms/update/UpdateMeta.java
b/plugins/transforms/update/src/main/java/org/apache/hop/pipeline/transforms/update/UpdateMeta.java
index df3d3994a3..1a40147fa1 100644
---
a/plugins/transforms/update/src/main/java/org/apache/hop/pipeline/transforms/update/UpdateMeta.java
+++
b/plugins/transforms/update/src/main/java/org/apache/hop/pipeline/transforms/update/UpdateMeta.java
@@ -621,6 +621,40 @@ public class UpdateMeta extends BaseTransformMeta<Update,
UpdateData> {
}
}
+ @Override
+ public IRowMeta getRequiredFields(IVariables variables) throws HopException {
+
+ String realSchemaName = variables.resolve(lookupField.getSchemaName());
+ String realTableName = variables.resolve(lookupField.getTableName());
+ DatabaseMeta databaseMeta =
+
getParentTransformMeta().getParentPipelineMeta().findDatabase(connection,
variables);
+
+ if (databaseMeta != null) {
+ try (Database db = new Database(loggingObject, variables, databaseMeta))
{
+ db.connect();
+
+ if (!Utils.isEmpty(realTableName)) {
+ // Check if this table exists...
+ if (db.checkTableExists(realSchemaName, realTableName)) {
+ return db.getTableFieldsMeta(realSchemaName, realTableName);
+ } else {
+ throw new HopException(
+ BaseMessages.getString(PKG,
"UpdateMeta.Exception.TableNotFound"));
+ }
+ } else {
+ throw new HopException(
+ BaseMessages.getString(PKG,
"UpdateMeta.Exception.TableNotSpecified"));
+ }
+ } catch (Exception e) {
+ throw new HopException(
+ BaseMessages.getString(PKG,
"UpdateMeta.Exception.ErrorGettingFields"), e);
+ }
+ } else {
+ throw new HopException(
+ BaseMessages.getString(PKG,
"UpdateMeta.Exception.ConnectionNotDefined"));
+ }
+ }
+
@Override
public boolean supportsErrorHandling() {
return true;
diff --git
a/plugins/transforms/update/src/main/resources/org/apache/hop/pipeline/transforms/update/messages/messages_en_US.properties
b/plugins/transforms/update/src/main/resources/org/apache/hop/pipeline/transforms/update/messages/messages_en_US.properties
index 3b49e6d976..c27b64a57a 100644
---
a/plugins/transforms/update/src/main/resources/org/apache/hop/pipeline/transforms/update/messages/messages_en_US.properties
+++
b/plugins/transforms/update/src/main/resources/org/apache/hop/pipeline/transforms/update/messages/messages_en_US.properties
@@ -45,6 +45,15 @@ UpdateDialog.ColumnInfo.StreamField2=Stream field2
UpdateDialog.ColumnInfo.TableField=Table field
UpdateDialog.CouldNotBuildSQL.DialogMessage=Unable to build the SQL statement
because of an error
UpdateDialog.CouldNotBuildSQL.DialogTitle=Couldn''t build SQL
+UpdateDialog.DoMapping.Button=Enter field mapping
+UpdateDialog.DoMapping.SomeFieldsNotFoundContinue=Certain fields could not be
found in the existing mapping, do you want continue?
+UpdateDialog.DoMapping.SomeFieldsNotFoundTitle=Certain referenced fields were
not found\!
+UpdateDialog.DoMapping.SomeSourceFieldsNotFound=These source fields were not
found\: {0}
+UpdateDialog.DoMapping.SomeTargetFieldsNotFound=These target fields were not
found\: {0}
+UpdateDialog.DoMapping.UnableToFindSourceFields.Message=It was not possible to
retrieve the source fields for this transform because of an error\:
+UpdateDialog.DoMapping.UnableToFindSourceFields.Title=Error getting source
fields
+UpdateDialog.DoMapping.UnableToFindTargetFields.Message=It was not possible to
retrieve the target fields for this transform because of an error\:
+UpdateDialog.DoMapping.UnableToFindTargetFields.Title=Error getting target
fields
UpdateDialog.ErrorGettingSchemas=Please select a schema name
UpdateDialog.ErrorIgnored.Label=Ignore lookup failure
UpdateDialog.ErrorIgnored.ToolTip=Check this to add a flag field (boolean) to
see if the key was found.
@@ -93,6 +102,10 @@ UpdateMeta.CheckResult.TableNameOK=Table name is filled in.
UpdateMeta.CheckResult.TransformReceivingDatas=Transform is connected to
previous one, receiving {0} fields
UpdateMeta.CheckResult.TransformReceivingInfoFromOtherTransforms=Transform is
receiving info from other transforms.
UpdateMeta.DefaultTableName=lookup table
+UpdateMeta.Exception.ConnectionNotDefined=Unable to determine the required
fields because the database connection wasn''t defined.
+UpdateMeta.Exception.ErrorGettingFields=Unable to determine the required
fields.
+UpdateMeta.Exception.TableNotFound=Unable to determine the required fields
because the specified database table couldn''t be found.
+UpdateMeta.Exception.TableNotSpecified=Unable to determine the required fields
because the database table name wasn''t specified.
UpdateMeta.Injection.CommitSize=The number of rows to commit at a time.
UpdateMeta.Injection.Connection=The name of the database connection.
UpdateMeta.Injection.IgnoreFlagField=The optional field to use to output
successful key lookups.