Skip to content
Open
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 @@ -120,6 +120,16 @@ public void getFields(
IValueMeta v = new ValueMetaString(variables.resolve(this.getValueXmlField()));
v.setOrigin(name);

IRowMeta knownTarget = info == null || info.length == 0 ? null : info[0];
if (knownTarget != null) {
// The target's row with the joined XML, as processRow() builds it, whatever rows the
// previous transforms give here
IRowMeta target = knownTarget.clone();
row.clear();
row.addRowMeta(target);
row.addValueMeta(v);
return;
}
try {
/*
Row should only include fields from the target and not the source. During the preview table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;

import java.util.List;
import org.apache.hop.core.HopClientEnvironment;
import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.core.row.IValueMeta;
import org.apache.hop.core.row.RowMeta;
import org.apache.hop.core.row.value.ValueMetaInteger;
import org.apache.hop.core.row.value.ValueMetaString;
import org.apache.hop.core.variables.Variables;
import org.apache.hop.pipeline.PipelineMeta;
Expand Down Expand Up @@ -150,4 +153,28 @@ void testGetFieldsReturnTargetTransformFieldsWithDuplicates() throws Exception {
assertEquals("c", strings[1]);
assertEquals("result xml field name", strings[2]);
}

/**
* The previous fields are merged in the order of the hops: with the source's hop first, a field
* both streams have keeps the source's type, and the fields come in the source's order. The
* transform writes the target's row, so that is what it declares.
*/
@Test
void testGetFieldsGiveTheTargetRowWhateverTheOrderOfThePreviousFields() throws Exception {
RowMeta source = new RowMeta();
source.addValueMeta(new ValueMetaInteger("c"));
source.addValueMeta(new ValueMetaString("a"));
RowMeta target = new RowMeta();
target.addValueMeta(new ValueMetaString("a"));
target.addValueMeta(new ValueMetaString("c"));
// As PipelineMeta merges the fields of the previous transforms, the source's first
RowMeta rowMeta = source.clone();
xmlJoinMeta.setValueXmlField("xml");

xmlJoinMeta.getFields(
rowMeta, "join", new IRowMeta[] {target, source}, null, new Variables(), null);

assertEquals(List.of("a", "c", "xml"), List.of(rowMeta.getFieldNames()));
assertEquals(IValueMeta.TYPE_STRING, rowMeta.getValueMeta(1).getType());
}
}
Loading