NIFI-11655 Fixed float and double handling in GenerateRecord

This closes #7356

Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
Matt Burgess 2023-06-07 17:13:16 -04:00 committed by exceptionfactory
parent 36da257e56
commit 5e6f3abdd2
No known key found for this signature in database
GPG Key ID: 29B6A52D2AAE8DBA
2 changed files with 13 additions and 2 deletions

View File

@ -59,6 +59,7 @@ import org.apache.nifi.serialization.record.type.MapDataType;
import org.apache.nifi.serialization.record.type.RecordDataType;
import org.apache.nifi.util.StringUtils;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.ZoneId;
@ -310,9 +311,13 @@ public class GenerateRecord extends AbstractProcessor {
return (char) faker.number().numberBetween(Character.MIN_VALUE, Character.MAX_VALUE);
case DATE:
return FakerUtils.getFakeData(DEFAULT_DATE_PROPERTY_NAME, faker);
case DECIMAL:
case DOUBLE:
return faker.number().randomDouble(6, Long.MIN_VALUE, Long.MAX_VALUE);
case FLOAT:
final double randomDouble = faker.number().randomDouble(6, Long.MIN_VALUE, Long.MAX_VALUE);
final BigDecimal asBigDecimal = new BigDecimal(randomDouble);
return asBigDecimal.floatValue();
case DECIMAL:
return faker.number().randomDouble(((DecimalDataType) recordField.getDataType()).getScale(), Long.MIN_VALUE, Long.MAX_VALUE);
case INT:
return faker.number().numberBetween(Integer.MIN_VALUE, Integer.MAX_VALUE);

View File

@ -18,7 +18,13 @@
}, {
"name": "Name",
"type": ["null", "string"]
}]
}, {
"name": "TestFloat",
"type": ["null", "float"]
}, {
"name": "TestDouble",
"type": ["null", "double"]
}]
}]
}, {
"name": "EventID",