Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,30 @@ under the License.
The Table Compare transform compares the data from two tables (provided they have the same lay-out), finds differences between the data in the two tables and logs it.

== Options

=== Reference/Comparison data tab
[width="90%",options="header"]
|===
|Option|Description
|Transform name|Name of the transform; This name has to be unique in a single pipeline
|Reference connection / Compare connection|Database connections from which the reference/compare table data will come.
|Reference schema field / Compare schema field|contain the schema names for the reference/compare table.
|Reference table field / Compare table field|contain the actual table names.
This means that you could compare two tables with a different name, as long as they have the same column names.
|===

=== Other fields tab
[width="90%",options="header"]
|===
|Option|Description
|Key fields field|should contain a comma separated list of they fields that make up the 'primary' key of the table(s) you are comparing.
The primary key is needed because without this information the two tables cannot be correctly joined.
|Exclude fields field|contains a comma separated list of columns that you want to exclude from the comparison.
E.g. because they exist in the first table, but not in the second.
|===

=== Additional fields tab
[width="90%",options="header"]
|===
|Option|Description
|Number of errors field|allows you to specify the name of the output column that will contain the total number of errors found for the comparison of your tables.
|Number of reference/compare table records field|allows you to specify the name of the field that will contain the actual number of records found in each table.
|Number of left/inner/right join errors field|allows you to specify the name of the field(s) that will contain the number of errors found for each join type.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.hop.core.Const;
import org.apache.hop.core.database.Database;
import org.apache.hop.core.database.DatabaseMeta;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.core.row.IValueMeta;
Expand Down Expand Up @@ -231,6 +232,7 @@ private Object[] compareTables(

Object[] result = new Object[6];


if (Utils.isEmpty(referenceTable)) {
Object[] errorRowData = constructErrorRow(rowMeta, r, null, null, null);
putError(
Expand All @@ -255,12 +257,12 @@ private Object[] compareTables(
nrErrors++;
}

DatabaseMeta refConnectionDatabaseMeta = getPipelineMeta().findDatabase(meta.getReferenceConnection(), variables);
String refSchemaTable =
meta.getReferenceConnection()
.getQuotedSchemaTableCombination(this, referenceSchema, referenceTable);
refConnectionDatabaseMeta.getQuotedSchemaTableCombination(this, referenceSchema, referenceTable);
DatabaseMeta compConnectionDatabaseMeta = getPipelineMeta().findDatabase(meta.getReferenceConnection(), variables);
String cmpSchemaTable =
meta.getCompareConnection()
.getQuotedSchemaTableCombination(this, compareSchema, compareTable);
compConnectionDatabaseMeta.getQuotedSchemaTableCombination(this, compareSchema, compareTable);

if (Utils.isEmpty(keyFields)) {
Object[] errorRowData = constructErrorRow(rowMeta, r, null, null, null);
Expand All @@ -284,11 +286,11 @@ private Object[] compareTables(

String[] keys = keyFields.split(",");
for (int i = 0; i < keys.length; i++) {
keys[i] = Kjube.trim(keys[i]);
keys[i] = keys[i].trim();
}
String[] excluded = Utils.isEmpty(excludeFields) ? new String[0] : excludeFields.split(",");
for (int i = 0; i < excluded.length; i++) {
excluded[i] = Kjube.trim(excluded[i]);
excluded[i] = excluded[i].trim();
}

try {
Expand Down Expand Up @@ -389,24 +391,24 @@ private Object[] compareTables(
cmpSql += ", ";
}
keyNrs[i] = i;
refSql += meta.getReferenceConnection().quoteField(keys[i]);
cmpSql += meta.getReferenceConnection().quoteField(keys[i]);
refSql += refConnectionDatabaseMeta.quoteField(keys[i]);
cmpSql += refConnectionDatabaseMeta.quoteField(keys[i]);
}
int[] valueNrs = new int[refFields.size() - keys.length];
int valueNr = keys.length;
int valueIndex = 0;
for (int i = 0; i < refFields.getFieldNames().length; i++) {
String field = refFields.getFieldNames()[i];
if (Const.indexOfString(field, keys) < 0) {
refSql += ", " + meta.getReferenceConnection().quoteField(field);
refSql += ", " + refConnectionDatabaseMeta.quoteField(field);
valueRowMeta.addValueMeta(refFields.searchValueMeta(field));
valueNrs[valueIndex++] = valueNr++;
}
}

for (String field : cmpFields.getFieldNames()) {
if (Const.indexOfString(field, keys) < 0) {
cmpSql += ", " + meta.getCompareConnection().quoteField(field);
cmpSql += ", " + compConnectionDatabaseMeta.quoteField(field);
}
}
refSql += " FROM " + refSchemaTable + " ORDER BY ";
Expand All @@ -416,8 +418,8 @@ private Object[] compareTables(
refSql += ", ";
cmpSql += ", ";
}
refSql += meta.getReferenceConnection().quoteField(keys[i]);
cmpSql += meta.getReferenceConnection().quoteField(keys[i]);
refSql += refConnectionDatabaseMeta.quoteField(keys[i]);
cmpSql += refConnectionDatabaseMeta.quoteField(keys[i]);
}

// Now we execute the SQL...
Expand Down Expand Up @@ -685,29 +687,47 @@ public boolean init() {
if (super.init()) {

try {
data.referenceDb = new Database(this, this, meta.getReferenceConnection());
DatabaseMeta refConnectionDatabaseMeta = getPipelineMeta().findDatabase(meta.getReferenceConnection(), variables);
if (refConnectionDatabaseMeta == null) {
logError(
BaseMessages.getString(
PKG, "TableCompare.RefConnection.ConnectionMissing", getTransformName()));
return false;
}


data.referenceDb = new Database(this, this, refConnectionDatabaseMeta);
data.referenceDb.connect();

} catch (Exception e) {
logError(
BaseMessages.getString(
PKG,
"TableCompare.Exception.UnexpectedErrorConnectingToReferenceDatabase",
meta.getReferenceConnection().getName()),
meta.getReferenceConnection()),
e);
return false;
}

try {
data.compareDb = new Database(this, this, meta.getCompareConnection());
DatabaseMeta compConnectionDatabaseMeta = getPipelineMeta().findDatabase(meta.getCompareConnection(), variables);
if (compConnectionDatabaseMeta == null) {
logError(
BaseMessages.getString(
PKG, "TableCompare.CompConnection.ConnectionMissing", getTransformName()));
return false;
}


data.compareDb = new Database(this, this, compConnectionDatabaseMeta);
data.compareDb.connect();

} catch (Exception e) {
logError(
BaseMessages.getString(
PKG,
"TableCompare.Exception.UnexpectedErrorConnectingToCompareDatabase",
meta.getCompareConnection().getName()),
meta.getCompareConnection()),
e);
return false;
}
Expand Down
Loading