Skip to content

Commit

Permalink
feat(flux-dsl): supports empty logic operator (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar authored Apr 7, 2021
1 parent 3f5b8b8 commit 5be7b5f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ You have to replace your dependency from: `influxdb-client-scala` to:

### Features
1. [#211](https://github.com/influxdata/influxdb-client-java/pull/211): Add supports for Scala cross versioning [`2.12`, `2.13`]
1. [#213](https://github.com/influxdata/influxdb-client-java/pull/213): Supports empty logic operator [FluxDSL]

## 2.1.0 [2021-04-01]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
package com.influxdb.query.dsl.functions.restriction;

import java.util.stream.Collectors;
import java.util.StringJoiner;
import java.util.stream.Stream;
import javax.annotation.Nonnull;

Expand Down Expand Up @@ -141,7 +141,12 @@ public String toString() {

return Stream.of(restrictions)
.map(Object::toString)
.collect(Collectors.joining(" " + operator + " ", "(", ")"));
.filter(it -> it != null && !it.isEmpty())
.collect(() -> new StringJoiner(" " + operator + " ", "(", ")")
.setEmptyValue(""),
StringJoiner::add,
StringJoiner::merge)
.toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,21 @@ void exists() {

Assertions.assertThat(restrictions.toString()).isEqualTo("exists r[\"_value\"]");
}

@Test
void emptyLogical() {

Restrictions restrictions = Restrictions.and(
Restrictions.tag("tag").equal("production"),
Restrictions.or(),
Restrictions.measurement().equal("data")
);
Assertions.assertThat(restrictions.toString()).isEqualTo("(r[\"tag\"] == \"production\" and r[\"_measurement\"] == \"data\")");

restrictions = Restrictions.and(Restrictions.or());
Assertions.assertThat(restrictions.toString()).isEqualTo("");

restrictions = Restrictions.or(Restrictions.or());
Assertions.assertThat(restrictions.toString()).isEqualTo("");
}
}

0 comments on commit 5be7b5f

Please sign in to comment.