diff --git a/CHANGELOG.md b/CHANGELOG.md index d7b104a..c70f32f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ #### Build: - influxdb-java to 2.23 - commons-io to 2.11 + - commons-lang3 to 3.12.0 - gson to 2.9.0 #### Test: diff --git a/nifi-influx-database-serialization/src/main/java/org/influxdata/nifi/serialization/InfluxLineProtocolParser.java b/nifi-influx-database-serialization/src/main/java/org/influxdata/nifi/serialization/InfluxLineProtocolParser.java index e913c0a..fe312fc 100644 --- a/nifi-influx-database-serialization/src/main/java/org/influxdata/nifi/serialization/InfluxLineProtocolParser.java +++ b/nifi-influx-database-serialization/src/main/java/org/influxdata/nifi/serialization/InfluxLineProtocolParser.java @@ -17,6 +17,7 @@ package org.influxdata.nifi.serialization; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -38,6 +39,11 @@ public final class InfluxLineProtocolParser { private static final Logger LOG = LoggerFactory.getLogger(InfluxLineProtocolParser.class); + /** + * Boolean accepted values + */ + private static final List BOOLEAN_ACCEPTED = Arrays.asList("t", "true", "f", "false"); + // Internal private String lineProtocol; private String[] tokens; @@ -394,9 +400,13 @@ Object transformValue(@NonNull final String value) { return Long.parseLong(value.substring(0, value.length() - 1)); } - Boolean bool = BooleanUtils.toBooleanObject(value); - if (bool != null) { - return bool; + // We don't want parse the '0', '1' ... as a boolean. Accepted values: + // https://docs.influxdata.com/influxdb/latest/reference/syntax/line-protocol/#boolean + if (BOOLEAN_ACCEPTED.contains(value.toLowerCase())) { + Boolean bool = BooleanUtils.toBooleanObject(value); + if (bool != null) { + return bool; + } } // diff --git a/nifi-influx-database-serialization/src/test/java/org/influxdata/nifi/serialization/TestInfluxLineProtocolParser.java b/nifi-influx-database-serialization/src/test/java/org/influxdata/nifi/serialization/TestInfluxLineProtocolParser.java index 24e764b..fad2fb6 100644 --- a/nifi-influx-database-serialization/src/test/java/org/influxdata/nifi/serialization/TestInfluxLineProtocolParser.java +++ b/nifi-influx-database-serialization/src/test/java/org/influxdata/nifi/serialization/TestInfluxLineProtocolParser.java @@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory; /** - * The tests comes from https://github.com/influxdata/influxdb/blob/1.6/models/points_test.go. + * The tests comes from points_test.go. */ public class TestInfluxLineProtocolParser { @@ -1035,6 +1035,17 @@ public void tagsAreNotNull() throws NotParsableInlineProtocolData Assert.assertTrue(parser.getTags().isEmpty()); } + @Test + public void onlyValidBooleans() { + + ExpectedResult.success() + .measurement("b") + .field("float1", 1F) + .field("float2", 0F) + .field("float3", 1.0F) + .validate("b float1=1,float2=0,float3=1.0"); + } + private static final class ExpectedResult { private static final Logger LOG = LoggerFactory.getLogger(ExpectedResult.class); diff --git a/pom.xml b/pom.xml index 7eaa08e..75d83ad 100644 --- a/pom.xml +++ b/pom.xml @@ -212,7 +212,7 @@ org.apache.commons commons-lang3 - 3.8.1 + 3.12.0