Skip to content

Commit

Permalink
ConditionEvaluator - more string compare operators implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
patrykuszynski committed Nov 2, 2020
1 parent f0b594f commit 194c446
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/main/java/com/mapr/db/impl/ConditionEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.anicolaspp.ojai.DocumentProjector;
import com.mapr.db.rowcol.KeyValue;
import com.mapr.fs.proto.Dbfilters;
import org.ojai.Document;
import org.ojai.Value;
import org.ojai.store.Connection;
Expand Down Expand Up @@ -32,7 +33,7 @@ private boolean evalCondition(ConditionNode condition, Document document) {
return getAllLeafValues(projected, "")
.filter(pair -> pair._1.equals(leaf.getField().asPathString().replace("[]", "")))
.map(Tuple2::_2)
.anyMatch(value -> cmp(leaf.getValue(), value));
.anyMatch(value -> cmp(leaf.getValue(), value, leaf.getOp()));
} else {
ConditionBlock block = (ConditionBlock) condition;

Expand All @@ -46,15 +47,26 @@ private boolean evalCondition(ConditionNode condition, Document document) {
}
}

private boolean cmp(KeyValue keyValue, Value value) {
private boolean cmp(KeyValue keyValue, Value value, Dbfilters.CompareOpProto op) {
switch (value.getType()) {

case NULL:
return keyValue.getType().getCode() == Value.TYPE_CODE_NULL;
case BOOLEAN:
return keyValue.getBoolean() == value.getBoolean();
case STRING:
return keyValue.getString().equals(value.getString());
switch (op) {
case LESS:
return value.getString().compareTo(keyValue.getString()) < 0;
case LESS_OR_EQUAL:
return value.getString().compareTo(keyValue.getString()) <= 0;
case GREATER:
return value.getString().compareTo(keyValue.getString()) > 0;
case GREATER_OR_EQUAL:
return value.getString().compareTo(keyValue.getString()) >= 0;
default:
return keyValue.getString().equals(value.getString());
}
case BYTE:
return keyValue.getByte() == value.getByte();
case SHORT:
Expand Down

0 comments on commit 194c446

Please sign in to comment.