From eb57e11e2a2cab031e1fba888ccc12fada701621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ramos?= Date: Wed, 8 May 2024 15:24:30 +0100 Subject: [PATCH] [PDI-20085] - KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL produces opposite display for NULLS --- .../pentaho/di/core/row/value/ValueMetaBase.java | 13 ++++++++----- .../di/core/row/value/ValueMetaBaseTest.java | 12 +++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java b/core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java index 72681495c997..ff74837c2bb3 100644 --- a/core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java +++ b/core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java @@ -23,6 +23,7 @@ package org.pentaho.di.core.row.value; +import org.apache.commons.lang.StringUtils; import org.pentaho.di.compatibility.Value; import org.pentaho.di.core.Const; import org.pentaho.di.core.database.DatabaseInterface; @@ -4038,15 +4039,17 @@ public Object convertDataFromString( String pol, ValueMetaInterface convertMeta, boolean isStringValue = outValueType == Value.VALUE_TYPE_STRING; Object emptyValue = isStringValue ? Const.NULL_STRING : null; - Boolean isEmptyAndNullDiffer = convertStringToBoolean( + boolean isEmptyAndNullDiffer = convertStringToBoolean( Const.NVL( System.getProperty( Const.KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL, "N" ), "N" ) ); - Boolean normalizeNullStringToEmpty = !convertStringToBoolean( + boolean normalizeNullStringToEmpty = !convertStringToBoolean( Const.NVL( System.getProperty( Const.KETTLE_DO_NOT_NORMALIZE_NULL_STRING_TO_EMPTY, "N" ), "N" ) ); - if ( normalizeNullStringToEmpty ) { - if ( pol == null && isStringValue && isEmptyAndNullDiffer ) { - pol = Const.NULL_STRING; + //the property KETTLE_DO_NOT_NORMALIZE_NULL_STRING_TO_EMPTY is only valid when KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL = Y. + //the isEmptyAndNullDiffer means that null and empty string should be different. normalizeNullStringToEmpty stops pentaho from making this transaction. + if ( isEmptyAndNullDiffer && pol == null && isStringValue ) { + if ( normalizeNullStringToEmpty ) { + pol = StringUtils.EMPTY; } } diff --git a/core/src/test/java/org/pentaho/di/core/row/value/ValueMetaBaseTest.java b/core/src/test/java/org/pentaho/di/core/row/value/ValueMetaBaseTest.java index cdede74776f8..e4aa3006557c 100644 --- a/core/src/test/java/org/pentaho/di/core/row/value/ValueMetaBaseTest.java +++ b/core/src/test/java/org/pentaho/di/core/row/value/ValueMetaBaseTest.java @@ -389,15 +389,17 @@ public void testConvertDataFromStringToString() throws KettleValueException { + "Conversion from null string must return null", null, result ); System.setProperty( Const.KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL, "Y" ); + System.setProperty( Const.KETTLE_DO_NOT_NORMALIZE_NULL_STRING_TO_EMPTY, "N" ); result = - outValueMetaString.convertDataFromString( inputValueEmptyString, inValueMetaString, nullIf, ifNull, trim_type ); - assertEquals( "KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL = Y: " - + "Conversion from empty string to string must return empty string", StringUtils.EMPTY, result ); + outValueMetaString.convertDataFromString( inputValueNullString, inValueMetaString, nullIf, ifNull, trim_type ); + assertEquals( "KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL = Y and KETTLE_DO_NOT_NORMALIZE_NULL_STRING_TO_EMPTY = N: " + + "Conversion from null string must return empty string", StringUtils.EMPTY, result ); + System.setProperty( Const.KETTLE_DO_NOT_NORMALIZE_NULL_STRING_TO_EMPTY, "Y" ); result = outValueMetaString.convertDataFromString( inputValueNullString, inValueMetaString, nullIf, ifNull, trim_type ); - assertEquals( "KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL = Y: " - + "Conversion from null string must return empty string", StringUtils.EMPTY, result ); + assertEquals( "KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL = Y and KETTLE_DO_NOT_NORMALIZE_NULL_STRING_TO_EMPTY = Y: " + + "Conversion from null string must return null", null, result ); // test KETTLE_DO_NOT_NORMALIZE_SPACES_ONLY_STRING_TO_EMPTY System.setProperty( Const.KETTLE_DO_NOT_NORMALIZE_SPACES_ONLY_STRING_TO_EMPTY, "Y" );