Skip to content

Commit 376f4e3

Browse files
committed
noticket: Add explicit ScalarExpr operators for not(STARTS_WITH) and not(ENDS_WITH)
1 parent 1cc0c6b commit 376f4e3

File tree

6 files changed

+142
-67
lines changed

6 files changed

+142
-67
lines changed

databind/src/main/java/tech/ydb/yoj/databind/expression/FilterBuilder.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
import static tech.ydb.yoj.databind.expression.ScalarExpr.Operator.LTE;
3232
import static tech.ydb.yoj.databind.expression.ScalarExpr.Operator.NEQ;
3333
import static tech.ydb.yoj.databind.expression.ScalarExpr.Operator.NOT_CONTAINS;
34+
import static tech.ydb.yoj.databind.expression.ScalarExpr.Operator.NOT_ENDS_WITH;
3435
import static tech.ydb.yoj.databind.expression.ScalarExpr.Operator.NOT_ICONTAINS;
36+
import static tech.ydb.yoj.databind.expression.ScalarExpr.Operator.NOT_STARTS_WITH;
3537
import static tech.ydb.yoj.databind.expression.ScalarExpr.Operator.STARTS_WITH;
3638

3739
@RequiredArgsConstructor(access = PRIVATE)
@@ -281,12 +283,24 @@ public FilterBuilder<T> startsWith(@NonNull String value) {
281283
return FilterBuilder.this;
282284
}
283285

286+
@NonNull
287+
public FilterBuilder<T> doesNotStartWith(@NonNull String value) {
288+
current = finisher.apply(new ScalarExpr<>(schema, generated, field, NOT_STARTS_WITH, fieldValue(value)));
289+
return FilterBuilder.this;
290+
}
291+
284292
@NonNull
285293
public FilterBuilder<T> endsWith(@NonNull String value) {
286294
current = finisher.apply(new ScalarExpr<>(schema, generated, field, ENDS_WITH, fieldValue(value)));
287295
return FilterBuilder.this;
288296
}
289297

298+
@NonNull
299+
public FilterBuilder<T> doesNotEndWith(@NonNull String value) {
300+
current = finisher.apply(new ScalarExpr<>(schema, generated, field, NOT_ENDS_WITH, fieldValue(value)));
301+
return FilterBuilder.this;
302+
}
303+
290304
@NonNull
291305
public FilterBuilder<T> isNull() {
292306
current = finisher.apply(new NullExpr<>(schema, generated, field, IS_NULL));

databind/src/main/java/tech/ydb/yoj/databind/expression/ScalarExpr.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,29 +197,59 @@ public String toString() {
197197
STARTS_WITH {
198198
@Override
199199
public Operator negate() {
200-
return null;
200+
return NOT_STARTS_WITH;
201201
}
202202

203203
@Override
204204
public String toString() {
205205
return "startswith";
206206
}
207207
},
208+
/**
209+
* "NOT Starts with" is case-sensitive match to check if a string does not start with the specified substring.
210+
* E.g., {@code name not startswith "Ni"}
211+
*/
212+
NOT_STARTS_WITH {
213+
@Override
214+
public Operator negate() {
215+
return STARTS_WITH;
216+
}
217+
218+
@Override
219+
public String toString() {
220+
return "not startswith";
221+
}
222+
},
208223
/**
209224
* "Ends with" is case-sensitive match to check if a string ends with the specified substring.
210225
* E.g., {@code name endswith "exey"}
211226
*/
212227
ENDS_WITH {
213228
@Override
214229
public Operator negate() {
215-
return null;
230+
return NOT_ENDS_WITH;
216231
}
217232

218233
@Override
219234
public String toString() {
220235
return "endswith";
221236
}
222237
},
238+
/**
239+
* "NOT Ends with" is case-sensitive match to check if a string does not end with the specified substring.
240+
* E.g., {@code name not endswith "kolai"}
241+
*/
242+
NOT_ENDS_WITH {
243+
@Override
244+
public Operator negate() {
245+
return ENDS_WITH;
246+
}
247+
248+
@Override
249+
public String toString() {
250+
return "not endswith";
251+
}
252+
},
223253
/**
224254
* "Contains" case-sensitive match for a substring in a string
225255
* E.g., {@code name contains "abc"}

0 commit comments

Comments
 (0)