refactor: refactor ExpressionAdaptor

This commit is contained in:
Michael Yang 2024-05-09 20:29:27 +08:00
parent 8a39182a6f
commit e0189217af
2 changed files with 6 additions and 9 deletions

View File

@ -24,7 +24,7 @@ public interface ExpressionAdaptor {
default String toCondition(Condition condition) {
return toLeft(condition.left)
+ toSymbol(condition.type)
+ toOperationSymbol(condition.type)
+ toRight(condition.right);
}
@ -32,7 +32,7 @@ public interface ExpressionAdaptor {
return operand.toExpression(this);
}
default String toSymbol(ConditionType type) {
default String toOperationSymbol(ConditionType type) {
return type.getDefaultSymbol();
}
@ -67,7 +67,6 @@ public interface ExpressionAdaptor {
return connector.getValue();
}
default String toGroupStart(Group group) {
return "(";
}

View File

@ -27,24 +27,22 @@ public class MilvusExpressionAdaptor implements ExpressionAdaptor {
public static final MilvusExpressionAdaptor DEFAULT = new MilvusExpressionAdaptor();
@Override
public String toSymbol(ConditionType type) {
public String toOperationSymbol(ConditionType type) {
if (type == ConditionType.EQ) {
return " == ";
}
return ExpressionAdaptor.super.toSymbol(type);
return type.getDefaultSymbol();
}
@Override
public String toCondition(Condition condition) {
if (condition.getType() == ConditionType.BETWEEN) {
Object[] values = (Object[]) ((Value) condition.getRight()).getValue();
return "(" + toLeft(condition.getLeft())
+ toSymbol(ConditionType.GE)
+ toOperationSymbol(ConditionType.GE)
+ values[0] + " && "
+ toLeft(condition.getLeft())
+ toSymbol(ConditionType.LE)
+ toOperationSymbol(ConditionType.LE)
+ values[1] + ")";
}