Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #4818 #4823

Merged
merged 2 commits into from
Jan 30, 2025
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 @@ -24,6 +24,7 @@
import org.apache.hop.core.exception.HopValueException;
import org.apache.hop.core.row.IValueMeta;
import org.apache.hop.core.row.RowDataUtil;
import org.apache.hop.core.row.value.ValueMetaBase;
import org.apache.hop.core.util.StringUtil;
import org.apache.hop.i18n.BaseMessages;
import org.apache.hop.pipeline.Pipeline;
Expand Down Expand Up @@ -157,7 +158,8 @@ private Object[] concatFields(Object[] inputRowData) throws HopException {
nullString = Const.NVL(field.getNullString(), "");
}

concatField(targetString, valueMeta, valueData, nullString);
String trimType = data.trimType[i];
concatField(targetString, valueMeta, valueData, nullString, trimType);
}

outputRowData[data.outputRowMeta.size() - 1] = targetString.toString();
Expand All @@ -166,13 +168,21 @@ private Object[] concatFields(Object[] inputRowData) throws HopException {
}

private void concatField(
StringBuilder targetField, IValueMeta valueMeta, Object valueData, String nullString)
StringBuilder targetField,
IValueMeta valueMeta,
Object valueData,
String nullString,
String trimType)
throws HopValueException {

if (valueMeta.isNull(valueData)) {
targetField.append(nullString);
} else {
targetField.append(valueMeta.getString(valueData));
if (trimType != null) {
targetField.append(
Const.trimToType(
valueMeta.getString(valueData), ValueMetaBase.getTrimTypeByCode(trimType)));
}
}
}

Expand Down Expand Up @@ -220,12 +230,18 @@ private void initStringDataFields() {
}

data.stringNullValue = new String[meta.getOutputFields().size()];
data.trimType = new String[meta.getOutputFields().size()];

for (int i = 0; i < meta.getOutputFields().size(); i++) {
data.stringNullValue[i] = "";
String nullString = meta.getOutputFields().get(i).getNullString();
if (!StringUtil.isEmpty(nullString)) {
data.stringNullValue[i] = nullString;
}
String trimType = meta.getOutputFields().get(i).getTrimType();
if (!StringUtil.isEmpty(trimType)) {
data.trimType[i] = trimType;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class ConcatFieldsData extends BaseTransformData implements ITransformDat
public String stringSeparator;
public String stringEnclosure;
public String[] stringNullValue;

public String[] trimType;

public int targetFieldLength; // for fast data dump (StringBuilder size)

public ConcatFieldsData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
public class ConcatFieldsMeta extends BaseTransformMeta<ConcatFields, ConcatFieldsData> {
private static final Class<?> PKG = ConcatFieldsMeta.class;

public static final String TRIM_TYPE_LEFT = "left";
public static final String TRIM_TYPE_RIGHT = "right";
public static final String TRIM_TYPE_BOTH = "both";

/** The separator to choose for the CSV file */
@HopMetadataProperty(key = "separator", injectionKey = "SEPARATOR")
private String separator;
Expand Down
Loading