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 @@ -710,13 +710,16 @@ void writeField(
}
break;
case IValueMeta.TYPE_BOOLEAN:
if (v != null) {
cell.setCellValue(vMeta.getBoolean(v));
// A lazily converted empty value is not null but converts to null: no cell value
Boolean bool = v != null ? vMeta.getBoolean(v) : null;
if (bool != null) {
cell.setCellValue(bool);
}
break;
case IValueMeta.TYPE_BIGNUMBER, IValueMeta.TYPE_NUMBER, IValueMeta.TYPE_INTEGER:
if (v != null) {
cell.setCellValue(vMeta.getNumber(v));
Double number = v != null ? vMeta.getNumber(v) : null;
if (number != null) {
cell.setCellValue(number);
}
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.apache.hop.core.row.IValueMeta;
import org.apache.hop.core.row.value.ValueMetaBigNumber;
import org.apache.hop.core.row.value.ValueMetaBinary;
import org.apache.hop.core.row.value.ValueMetaBoolean;
import org.apache.hop.core.row.value.ValueMetaDate;
import org.apache.hop.core.row.value.ValueMetaInteger;
import org.apache.hop.core.row.value.ValueMetaInternetAddress;
Expand All @@ -57,6 +58,8 @@
import org.apache.hop.utils.TestUtils;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
Expand Down Expand Up @@ -402,6 +405,34 @@ void testValueBoolean() throws Exception {
testBaseXlsx(vmi, vObj, false, false);
}

/**
* After a CSV file input with lazy conversion, an empty field is an empty byte array: not null,
* but it converts to null. The cell stays empty.
*/
@Test
void testValueNumberEmptyAndLazilyConverted() throws Exception {
testBaseXlsx(lazilyConverted(new ValueMetaNumber("value_number")), new byte[0], false, false);
assertBlankCell();
}

@Test
void testValueBooleanEmptyAndLazilyConverted() throws Exception {
testBaseXlsx(lazilyConverted(new ValueMetaBoolean("value_bool")), new byte[0], false, false);
assertBlankCell();
}

private static IValueMeta lazilyConverted(IValueMeta valueMeta) {
// As CSV file input reads it: the text of the file, converted when needed
valueMeta.setStorageType(IValueMeta.STORAGE_TYPE_BINARY_STRING);
valueMeta.setStorageMetadata(new ValueMetaString(valueMeta.getName()));
return valueMeta;
}

private void assertBlankCell() {
Cell cell = dataMock.currentWorkbookDefinition.getSheet().getRow(1).getCell(0);
assertTrue(cell == null || cell.getCellType() == CellType.BLANK, String.valueOf(cell));
}

@Test
void testValueDate() throws Exception {

Expand Down
Loading