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: Issue/644 #648

Merged
merged 5 commits into from
Nov 29, 2023
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ jobs:
- maven-cache_v3-<< parameters.maven-image >>-
- run:
name: "Check generate site"
command: mvn clean site site:stage -DskipTests
command: mvn clean install site site:stage -DskipTests

deploy-snapshot:
docker:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 6.11.0 [unreleased]

### Bug Fixes
1. [#648](https://github.com/influxdata/influxdb-client-java/pull/648): With csv parsing, return empty string when `stringValue` and `defaultValue` are both an empty string.

### Dependencies

Update dependencies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,18 +303,20 @@ private List<String> toList(final CSVRecord csvRecord) {
private Object toValue(@Nullable final String strValue, final @Nonnull FluxColumn column) {

Arguments.checkNotNull(column, "column");
String dataType = column.getDataType();

// Default value
if (strValue == null || strValue.isEmpty()) {
String defaultValue = column.getDefaultValue();
if (defaultValue == null || defaultValue.isEmpty()) {
if ("string".equals(dataType)) {
return defaultValue;
}
return null;
}

return toValue(defaultValue, column);
}

String dataType = column.getDataType();
switch (dataType) {
case "boolean":
return Boolean.valueOf(strValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,60 @@ public void parseDuplicateColumnNames() throws IOException {
Assertions.assertThat(tables.get(0).getRecords().get(0).getRow().get(7)).isEqualTo(25.3);
}


@Test
public void parseEmptyString() throws IOException {
String data = "#group,false,false,true,true,true,true,true,false,false\n"
+ "#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,string,string,string,double,string\n"
+ "#default,_result,,,,,,nana,,\n"
+ ",result,table,_start,_stop,_field,_measurement,owner,le,_value\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,wumpus,snipe,influxdata,0,\"foo\"\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,wumpus,snipe,,10,\"foo\"\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,wumpus,snipe,\"\",20,\"foo\"\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,wumpus,snipe,influxdata,30,\"foo\"\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,wumpus,snipe,influxdata,40,\"foo\"\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,wumpus,snipe,influxdata,50,\"foo\"\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,wumpus,snipe,influxdata,60,\"foo\"\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,wumpus,snipe,influxdata,70,\"foo\"\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,wumpus,snipe,influxdata,80,\"\"\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,wumpus,snipe,influxdata,90,\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,wumpus,snipe,influxdata,100,\"bar\"\n"
+ ",,0,2021-06-23T06:50:11.897825012Z,2021-06-25T06:50:11.897825012Z,wumpus,snipe,influxdata,-100,\"bar\"\n"
+ "\n";

List<FluxTable> tables = parseFluxResponse(data);

Assertions.assertThat(tables).hasSize(1);
Assertions.assertThat(tables.get(0).getRecords().get(7).getValue()).isEqualTo("foo");
Assertions.assertThat(tables.get(0).getRecords().get(8).getValue()).isEqualTo(""); // -- todo make sure default value is respected
Assertions.assertThat(tables.get(0).getRecords().get(9).getValue()).isNotNull();
Assertions.assertThat(tables.get(0).getRecords().get(10).getValue()).isEqualTo("bar");
Assertions.assertThat(tables.get(0).getRecords().get(0).getValueByKey("owner")).isEqualTo("influxdata");
Assertions.assertThat(tables.get(0).getRecords().get(1).getValueByKey("owner")).isEqualTo("nana");
Assertions.assertThat(tables.get(0).getRecords().get(2).getValueByKey("owner")).isEqualTo("nana");
}

@Test
public void parseEmptyStringWithoutTableDefinition() throws IOException {

String data = ",result,table,_start,_stop,_time,_value,_field,_measurement,host,value\n"
+ ",,0,1970-01-01T00:00:10Z,1970-01-01T00:00:20Z,1970-01-01T00:00:10Z,10,free,mem,A,12.25\n"
+ ",,1,1970-01-01T00:00:10Z,1970-01-01T00:00:20Z,1970-01-01T00:00:10Z,,free,mem,,15.55\n";

parser = new FluxCsvParser(FluxCsvParser.ResponseMetadataMode.ONLY_NAMES);
List<FluxTable> tables = parseFluxResponse(data);

Assertions.assertThat(tables).hasSize(2);
Assertions.assertThat(tables.get(0).getRecords()).hasSize(1);
Assertions.assertThat(tables.get(0).getRecords().get(0).getValues().get("value")).isEqualTo("12.25");
Assertions.assertThat(tables.get(0).getRecords().get(0).getValues().get("host")).isEqualTo("A");
Assertions.assertThat(tables.get(0).getRecords().get(0).getValue()).isEqualTo("10");
Assertions.assertThat(tables.get(1).getRecords()).hasSize(1);
Assertions.assertThat(tables.get(1).getRecords().get(0).getValues().get("value")).isEqualTo("15.55");
Assertions.assertThat(tables.get(1).getRecords().get(0).getValues().get("host")).isNull();
Assertions.assertThat(tables.get(1).getRecords().get(0).getValue()).isNull();
}

@Nonnull
private List<FluxTable> parseFluxResponse(@Nonnull final String data) throws IOException {

Expand Down Expand Up @@ -712,4 +766,5 @@ public boolean isCancelled() {
return cancelled;
}
}

}
Loading