in core/src/main/java/com/alibaba/druid/support/calcite/CalciteMySqlNodeVisitor.java [1008:1184]
public boolean visit(SQLBinaryOpExpr x) {
SqlOperator operator = null;
SqlQuantifyOperator someOrAllOperator = null;
SqlNode left = convertToSqlNode(x.getLeft());
SQLExpr rightExpr = x.getRight();
SqlNode right = convertToSqlNode(rightExpr);
switch (x.getOperator()) {
case Equality:
if (isSqlAllExpr(rightExpr)) {
someOrAllOperator = SqlStdOperatorTable.ALL_EQ;
} else if (isAnyOrSomeExpr(rightExpr)) {
someOrAllOperator = SqlStdOperatorTable.SOME_EQ;
} else {
operator = SqlStdOperatorTable.EQUALS;
}
break;
case GreaterThan:
if (isSqlAllExpr(rightExpr)) {
someOrAllOperator = SqlStdOperatorTable.ALL_GT;
} else if (isAnyOrSomeExpr(rightExpr)) {
someOrAllOperator = SqlStdOperatorTable.SOME_GT;
} else {
operator = SqlStdOperatorTable.GREATER_THAN;
}
break;
case GreaterThanOrEqual:
if (isSqlAllExpr(rightExpr)) {
someOrAllOperator = SqlStdOperatorTable.ALL_GE;
} else if (isAnyOrSomeExpr(rightExpr)) {
someOrAllOperator = SqlStdOperatorTable.SOME_GE;
} else {
operator = SqlStdOperatorTable.GREATER_THAN_OR_EQUAL;
}
break;
case LessThan:
if (isSqlAllExpr(rightExpr)) {
someOrAllOperator = SqlStdOperatorTable.ALL_LT;
} else if (isAnyOrSomeExpr(rightExpr)) {
someOrAllOperator = SqlStdOperatorTable.SOME_LT;
} else {
operator = SqlStdOperatorTable.LESS_THAN;
}
break;
case LessThanOrEqual:
if (isSqlAllExpr(rightExpr)) {
someOrAllOperator = SqlStdOperatorTable.ALL_LE;
} else if (isAnyOrSomeExpr(rightExpr)) {
someOrAllOperator = SqlStdOperatorTable.SOME_LE;
} else {
operator = SqlStdOperatorTable.LESS_THAN_OR_EQUAL;
}
break;
case NotEqual:
case LessThanOrGreater:
if (isSqlAllExpr(rightExpr)) {
someOrAllOperator = SqlStdOperatorTable.ALL_NE;
} else if (isAnyOrSomeExpr(rightExpr)) {
someOrAllOperator = SqlStdOperatorTable.SOME_NE;
} else {
operator = SqlStdOperatorTable.NOT_EQUALS;
}
break;
case Add:
operator = SqlStdOperatorTable.PLUS;
break;
case Subtract:
operator = SqlStdOperatorTable.MINUS;
break;
case Multiply:
operator = SqlStdOperatorTable.MULTIPLY;
break;
case Divide:
operator = SqlStdOperatorTable.DIVIDE;
break;
case Modulus:
operator = SqlStdOperatorTable.MOD;
break;
case Like:
operator = SqlStdOperatorTable.LIKE;
break;
case NotLike:
operator = SqlStdOperatorTable.NOT_LIKE;
break;
case BooleanAnd:
operator = SqlStdOperatorTable.AND;
break;
case BooleanOr:
operator = SqlStdOperatorTable.OR;
break;
case Concat:
operator = SqlStdOperatorTable.CONCAT;
break;
case Is: {
if (rightExpr instanceof SQLNullExpr) {
operator = SqlStdOperatorTable.IS_NULL;
} else if (rightExpr instanceof SQLIdentifierExpr) {
long hashCode64 = ((SQLIdentifierExpr) rightExpr).nameHashCode64();
if (hashCode64 == FnvHash.Constants.JSON
|| hashCode64 == JSON_VALUE) {
operator = SqlStdOperatorTable.IS_JSON_VALUE;
} else if (hashCode64 == JSON_OBJECT) {
operator = SqlStdOperatorTable.IS_JSON_OBJECT;
} else if (hashCode64 == JSON_ARRAY) {
operator = SqlStdOperatorTable.IS_JSON_ARRAY;
} else if (hashCode64 == JSON_SCALAR) {
operator = SqlStdOperatorTable.IS_JSON_SCALAR;
} else if (hashCode64 == FnvHash.Constants.UNKNOWN) {
operator = SqlStdOperatorTable.IS_UNKNOWN;
}
} else if (rightExpr instanceof SQLBooleanExpr) {
if (((SQLBooleanExpr) rightExpr).getValue()) {
operator = SqlStdOperatorTable.IS_TRUE;
} else {
operator = SqlStdOperatorTable.IS_FALSE;
}
}
}
break;
case IsNot:
if (rightExpr instanceof SQLNullExpr) {
operator = SqlStdOperatorTable.IS_NOT_NULL;
} else if (rightExpr instanceof SQLIdentifierExpr) {
long hashCode64 = ((SQLIdentifierExpr) rightExpr).nameHashCode64();
if (hashCode64 == FnvHash.Constants.JSON
|| hashCode64 == JSON_VALUE) {
operator = SqlStdOperatorTable.IS_NOT_JSON_VALUE;
} else if (hashCode64 == JSON_OBJECT) {
operator = SqlStdOperatorTable.IS_NOT_JSON_OBJECT;
} else if (hashCode64 == JSON_ARRAY) {
operator = SqlStdOperatorTable.IS_NOT_JSON_ARRAY;
} else if (hashCode64 == JSON_SCALAR) {
operator = SqlStdOperatorTable.IS_NOT_JSON_SCALAR;
} else if (hashCode64 == FnvHash.Constants.UNKNOWN) {
operator = SqlStdOperatorTable.IS_NOT_UNKNOWN;
}
} else if (rightExpr instanceof SQLBooleanExpr) {
if (((SQLBooleanExpr) rightExpr).getValue()) {
operator = SqlStdOperatorTable.IS_NOT_TRUE;
} else {
operator = SqlStdOperatorTable.IS_NOT_FALSE;
}
}
break;
case Escape: {
SqlBasicCall like = (SqlBasicCall) left;
sqlNode = new SqlBasicCall(like.getOperator(), new SqlNode[]{like.operands[0], like.operands[1], right},
SqlParserPos.ZERO);
return false;
}
default:
throw new FastsqlException("not support " + x.getOperator());
}
if (someOrAllOperator != null) {
this.sqlNode = new SqlBasicCall(someOrAllOperator, new SqlNode[]{left, right},
SqlParserPos.ZERO);
} else {
if (operator == SqlStdOperatorTable.IS_NULL
|| operator == SqlStdOperatorTable.IS_NOT_NULL
|| operator == SqlStdOperatorTable.IS_TRUE
|| operator == SqlStdOperatorTable.IS_NOT_TRUE) {
this.sqlNode = new SqlBasicCall(operator,
new SqlNode[]{left},
SqlParserPos.ZERO);
} else {
this.sqlNode = new SqlBasicCall(operator,
new SqlNode[]{left, right},
SqlParserPos.ZERO);
}
}
return false;
}