|
21 | 21 | import java.math.BigDecimal;
|
22 | 22 | import java.math.BigInteger;
|
23 | 23 | import java.util.ArrayList;
|
| 24 | +import java.util.Collections; |
24 | 25 | import java.util.List;
|
25 | 26 |
|
26 | 27 | /**
|
@@ -173,7 +174,8 @@ private boolean isCond(SQLBinaryOpExpr expr) {
|
173 | 174 | }
|
174 | 175 | return leftSide instanceof SQLIdentifierExpr ||
|
175 | 176 | leftSide instanceof SQLPropertyExpr ||
|
176 |
| - leftSide instanceof SQLVariantRefExpr; |
| 177 | + leftSide instanceof SQLVariantRefExpr || |
| 178 | + leftSide instanceof SQLCastExpr; |
177 | 179 | }
|
178 | 180 |
|
179 | 181 | private boolean isAllowedMethodOnConditionLeft(SQLMethodInvokeExpr method, SQLBinaryOperator operator) {
|
@@ -480,48 +482,63 @@ private MethodField parseSQLMethodInvokeExprWithFunctionInWhere(SQLMethodInvokeE
|
480 | 482 | return methodField;
|
481 | 483 | }
|
482 | 484 |
|
| 485 | + private MethodField parseSQLCastExprInWhere(SQLCastExpr soExpr) throws SqlParseException { |
| 486 | + MethodField methodField = FieldMaker.makeMethodField("cast", |
| 487 | + Collections.singletonList(soExpr), |
| 488 | + null, |
| 489 | + null, |
| 490 | + query != null ? query.getFrom().getAlias() : null, |
| 491 | + true); |
| 492 | + List<KVValue> params = methodField.getParams(); |
| 493 | + KVValue param = params.get(0); |
| 494 | + params.clear(); |
| 495 | + params.add(new KVValue(param.key)); |
| 496 | + params.add(new KVValue(param.value)); |
| 497 | + return methodField; |
| 498 | + } |
| 499 | + |
483 | 500 | private SQLMethodInvokeExpr parseSQLBinaryOpExprWhoIsConditionInWhere(SQLBinaryOpExpr soExpr) throws SqlParseException {
|
484 | 501 |
|
485 |
| - if (!(soExpr.getLeft() instanceof SQLMethodInvokeExpr || |
| 502 | + if (!(soExpr.getLeft() instanceof SQLCastExpr || soExpr.getRight() instanceof SQLCastExpr)) { |
| 503 | + if (!(soExpr.getLeft() instanceof SQLMethodInvokeExpr || |
486 | 504 | soExpr.getRight() instanceof SQLMethodInvokeExpr)) {
|
487 |
| - return null; |
488 |
| - } |
489 |
| - |
490 |
| - if (soExpr.getLeft() instanceof SQLMethodInvokeExpr) { |
491 |
| - if (!SQLFunctions.buildInFunctions.contains(((SQLMethodInvokeExpr) soExpr.getLeft()).getMethodName())) { |
492 | 505 | return null;
|
493 | 506 | }
|
494 |
| - } |
495 | 507 |
|
496 |
| - if (soExpr.getRight() instanceof SQLMethodInvokeExpr) { |
497 |
| - if (!SQLFunctions.buildInFunctions.contains(((SQLMethodInvokeExpr) soExpr.getRight()).getMethodName())) { |
498 |
| - return null; |
| 508 | + if (soExpr.getLeft() instanceof SQLMethodInvokeExpr) { |
| 509 | + if (!SQLFunctions.buildInFunctions.contains(((SQLMethodInvokeExpr) soExpr.getLeft()).getMethodName())) { |
| 510 | + return null; |
| 511 | + } |
499 | 512 | }
|
500 |
| - } |
501 | 513 |
|
| 514 | + if (soExpr.getRight() instanceof SQLMethodInvokeExpr) { |
| 515 | + if (!SQLFunctions.buildInFunctions.contains(((SQLMethodInvokeExpr) soExpr.getRight()).getMethodName())) { |
| 516 | + return null; |
| 517 | + } |
| 518 | + } |
| 519 | + } |
502 | 520 |
|
503 | 521 | MethodField leftMethod = new MethodField(null, Lists.newArrayList(new KVValue("", Util.expr2Object(soExpr.getLeft(), "'"))), null, null);
|
504 |
| - MethodField rightMethod = new MethodField(null, Lists.newArrayList(new KVValue("", Util.expr2Object(soExpr.getRight(), "'"))), null, null); |
505 |
| - |
506 | 522 | if (soExpr.getLeft() instanceof SQLIdentifierExpr || soExpr.getLeft() instanceof SQLPropertyExpr) {
|
507 | 523 | leftMethod = new MethodField(null, Lists.newArrayList(new KVValue("", "doc['" + Util.expr2Object(soExpr.getLeft(), "'") + "'].value")), null, null);
|
| 524 | + } else if (soExpr.getLeft() instanceof SQLMethodInvokeExpr) { |
| 525 | + leftMethod = parseSQLMethodInvokeExprWithFunctionInWhere((SQLMethodInvokeExpr) soExpr.getLeft()); |
| 526 | + } else if (soExpr.getLeft() instanceof SQLCastExpr) { |
| 527 | + leftMethod = parseSQLCastExprInWhere((SQLCastExpr) soExpr.getLeft()); |
508 | 528 | }
|
509 | 529 |
|
| 530 | + MethodField rightMethod = new MethodField(null, Lists.newArrayList(new KVValue("", Util.expr2Object(soExpr.getRight(), "'"))), null, null); |
510 | 531 | if (soExpr.getRight() instanceof SQLIdentifierExpr || soExpr.getRight() instanceof SQLPropertyExpr) {
|
511 | 532 | rightMethod = new MethodField(null, Lists.newArrayList(new KVValue("", "doc['" + Util.expr2Object(soExpr.getRight(), "'") + "'].value")), null, null);
|
512 |
| - } |
513 |
| - |
514 |
| - if (soExpr.getLeft() instanceof SQLMethodInvokeExpr) { |
515 |
| - leftMethod = parseSQLMethodInvokeExprWithFunctionInWhere((SQLMethodInvokeExpr) soExpr.getLeft()); |
516 |
| - } |
517 |
| - if (soExpr.getRight() instanceof SQLMethodInvokeExpr) { |
| 533 | + } else if (soExpr.getRight() instanceof SQLMethodInvokeExpr) { |
518 | 534 | rightMethod = parseSQLMethodInvokeExprWithFunctionInWhere((SQLMethodInvokeExpr) soExpr.getRight());
|
| 535 | + } else if (soExpr.getRight() instanceof SQLCastExpr) { |
| 536 | + rightMethod = parseSQLCastExprInWhere((SQLCastExpr) soExpr.getRight()); |
519 | 537 | }
|
520 | 538 |
|
521 | 539 | String v1 = leftMethod.getParams().get(0).value.toString();
|
522 | 540 | String v1Dec = leftMethod.getParams().size() == 2 ? leftMethod.getParams().get(1).value.toString() + ";" : "";
|
523 | 541 |
|
524 |
| - |
525 | 542 | String v2 = rightMethod.getParams().get(0).value.toString();
|
526 | 543 | String v2Dec = rightMethod.getParams().size() == 2 ? rightMethod.getParams().get(1).value.toString() + ";" : "";
|
527 | 544 |
|
|
0 commit comments