Skip to content

Commit 5be7b5f

Browse files
authored
feat(flux-dsl): supports empty logic operator (#213)
1 parent 3f5b8b8 commit 5be7b5f

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ You have to replace your dependency from: `influxdb-client-scala` to:
99

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

1314
## 2.1.0 [2021-04-01]
1415

flux-dsl/src/main/java/com/influxdb/query/dsl/functions/restriction/Restrictions.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
package com.influxdb.query.dsl.functions.restriction;
2323

24-
import java.util.stream.Collectors;
24+
import java.util.StringJoiner;
2525
import java.util.stream.Stream;
2626
import javax.annotation.Nonnull;
2727

@@ -141,7 +141,12 @@ public String toString() {
141141

142142
return Stream.of(restrictions)
143143
.map(Object::toString)
144-
.collect(Collectors.joining(" " + operator + " ", "(", ")"));
144+
.filter(it -> it != null && !it.isEmpty())
145+
.collect(() -> new StringJoiner(" " + operator + " ", "(", ")")
146+
.setEmptyValue(""),
147+
StringJoiner::add,
148+
StringJoiner::merge)
149+
.toString();
145150
}
146151
}
147152
}

flux-dsl/src/test/java/com/influxdb/query/dsl/functions/restriction/RestrictionsTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,21 @@ void exists() {
6363

6464
Assertions.assertThat(restrictions.toString()).isEqualTo("exists r[\"_value\"]");
6565
}
66+
67+
@Test
68+
void emptyLogical() {
69+
70+
Restrictions restrictions = Restrictions.and(
71+
Restrictions.tag("tag").equal("production"),
72+
Restrictions.or(),
73+
Restrictions.measurement().equal("data")
74+
);
75+
Assertions.assertThat(restrictions.toString()).isEqualTo("(r[\"tag\"] == \"production\" and r[\"_measurement\"] == \"data\")");
76+
77+
restrictions = Restrictions.and(Restrictions.or());
78+
Assertions.assertThat(restrictions.toString()).isEqualTo("");
79+
80+
restrictions = Restrictions.or(Restrictions.or());
81+
Assertions.assertThat(restrictions.toString()).isEqualTo("");
82+
}
6683
}

0 commit comments

Comments
 (0)