on 06-02-2021 3:25 AM
In the documentation for Copy & Modify CDS QL Statements, we are shown how to modify a where clause as follows:
CqnSelect copy = CQL.copy(query, new Modifier() {
@Override
public Predicate where(Predicate where) {
return where.or(CQL.get("title").eq("CAP Java SDK"));
}
});
However, this only allows me to append segments to the where clause.
What if I wanted to remove the where-clause entirely?
Or, what if I wanted to filter out specific segments of the where clause?
In case you want to remove the where condition entirely you can simply return null in the modifier's where(Predicate) method:
CqnSelect copy = CQL.copy(query, new Modifier() {
@Override
public Predicate where(Predicate where) {
return null; // remove where clause
}
})
The modifier itself automatically traverses inside the structure of the where condition. You can therefore use the Modifiers methods to modify ElementRef, comparisons, connectives or negations to modify the existing where clause. For example this turns all < into <= and all > into >=. Of course you can also modify or exchange the values itself in these methods.
CqnSelect copy = CQL.copy(query, new Modifier() {
@Override
public Predicate comparison(Value<?> lhs, Operator op, Value<?> rhs) {
if(op == Operator.GT) {
return CQL.comparison(lhs, Operator.GE, rhs);
} else if (op == Operator.LT) {
return CQL.comparison(lhs, Operator.LE, rhs);
}
return CQL.comparison(lhs, op, rhs);
}
})
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I have a similar requirement. But I want to remove the clause from where if the "lhs" contains a certain substring. How can I do that?
My where caluse looks like this:
{"SELECT":{"from":{"ref":["ContractService.ContractItem"]},"columns":["*"],"where":[{"ref":["incoTerms_id"]},"is",{"val":"CIF"},"and",{"ref":["deliveryStartDate"]},"=",{"val":"2021-07-25","literal":"date"},"and",{"ref":["deliveryStartDate"]},"=",{"val":"2021-08-26","literal":"date"}],"orderBy":[{"ref":["itemNumber"]},{"ref":["contract_contractNumber"]}],"limit":{"rows":{"val":1000}}}}
I want to remove all the condition from where clause where the ref is "deliveryStartDate". Rest all will remain same. How can I do that?
I am not able to modify Value<?> lhs or rhs. How can I do that too?
Thanks,
Ruchika
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.