File tree Expand file tree Collapse file tree
main/java/com/influxdb/query/dsl/functions/restriction
test/java/com/influxdb/query/dsl/functions/restriction Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ You have to replace your dependency from: `influxdb-client-scala` to:
99
1010### Features
11111 . [ #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
Original file line number Diff line number Diff line change 2121 */
2222package com .influxdb .query .dsl .functions .restriction ;
2323
24- import java .util .stream . Collectors ;
24+ import java .util .StringJoiner ;
2525import java .util .stream .Stream ;
2626import 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}
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments