1
1
package org .nlpcn .es4sql .parse ;
2
2
3
- import com .alibaba .druid .sql .ast .expr .*;
4
- import com .alibaba .druid .sql .ast .statement .*;
5
- import com .alibaba .druid .sql .ast .*;
6
- import com .alibaba .druid .sql .dialect .mysql .ast .statement .MySqlSelectQueryBlock ;
7
-
8
3
import com .google .common .collect .Lists ;
9
4
import com .google .common .collect .Sets ;
5
+
6
+ import com .alibaba .druid .sql .ast .SQLExpr ;
7
+ import com .alibaba .druid .sql .ast .expr .SQLBetweenExpr ;
8
+ import com .alibaba .druid .sql .ast .expr .SQLBinaryOpExpr ;
9
+ import com .alibaba .druid .sql .ast .expr .SQLBinaryOperator ;
10
+ import com .alibaba .druid .sql .ast .expr .SQLCharExpr ;
11
+ import com .alibaba .druid .sql .ast .expr .SQLIdentifierExpr ;
12
+ import com .alibaba .druid .sql .ast .expr .SQLInListExpr ;
13
+ import com .alibaba .druid .sql .ast .expr .SQLInSubQueryExpr ;
14
+ import com .alibaba .druid .sql .ast .expr .SQLMethodInvokeExpr ;
15
+ import com .alibaba .druid .sql .ast .expr .SQLNotExpr ;
16
+ import com .alibaba .druid .sql .ast .expr .SQLNullExpr ;
17
+ import com .alibaba .druid .sql .ast .expr .SQLNumericLiteralExpr ;
18
+ import com .alibaba .druid .sql .ast .expr .SQLPropertyExpr ;
19
+ import com .alibaba .druid .sql .ast .expr .SQLQueryExpr ;
20
+ import com .alibaba .druid .sql .ast .expr .SQLTextLiteralExpr ;
21
+ import com .alibaba .druid .sql .ast .expr .SQLVariantRefExpr ;
22
+ import com .alibaba .druid .sql .ast .statement .SQLDeleteStatement ;
23
+ import com .alibaba .druid .sql .dialect .mysql .ast .statement .MySqlSelectQueryBlock ;
24
+
10
25
import org .nlpcn .es4sql .SQLFunctions ;
11
26
import org .nlpcn .es4sql .Util ;
12
- import org .nlpcn .es4sql .domain .*;
27
+ import org .nlpcn .es4sql .domain .Condition ;
28
+ import org .nlpcn .es4sql .domain .KVValue ;
29
+ import org .nlpcn .es4sql .domain .MethodField ;
30
+ import org .nlpcn .es4sql .domain .Select ;
31
+ import org .nlpcn .es4sql .domain .Where ;
13
32
import org .nlpcn .es4sql .exception .SqlParseException ;
14
33
import org .nlpcn .es4sql .spatial .SpatialParamsFactory ;
15
34
35
+ import java .math .BigDecimal ;
36
+ import java .math .BigInteger ;
16
37
import java .util .ArrayList ;
17
38
import java .util .List ;
18
39
@@ -351,11 +372,11 @@ else if (isChildren)
351
372
Condition condition = null ;
352
373
353
374
if (isNested )
354
- condition = new Condition (Where .CONN .valueOf (opear ), fieldName ,null , methodName , spatialParamsObject , null ,nestedType );
375
+ condition = new Condition (Where .CONN .valueOf (opear ), fieldName , null , methodName , spatialParamsObject , null , nestedType );
355
376
else if (isChildren )
356
- condition = new Condition (Where .CONN .valueOf (opear ), fieldName ,null , methodName , spatialParamsObject , null ,childrenType );
377
+ condition = new Condition (Where .CONN .valueOf (opear ), fieldName , null , methodName , spatialParamsObject , null , childrenType );
357
378
else
358
- condition = new Condition (Where .CONN .valueOf (opear ), fieldName ,null , methodName , spatialParamsObject ,null , null );
379
+ condition = new Condition (Where .CONN .valueOf (opear ), fieldName , null , methodName , spatialParamsObject , null , null );
359
380
360
381
where .addWhere (condition );
361
382
} else if (methodName .toLowerCase ().equals ("nested" )) {
@@ -365,7 +386,7 @@ else if (isChildren)
365
386
throw new SqlParseException ("could not fill nested from expr:" + expr );
366
387
}
367
388
368
- Condition condition = new Condition (Where .CONN .valueOf (opear ), nestedType .path ,null , methodName .toUpperCase (), nestedType .where ,null );
389
+ Condition condition = new Condition (Where .CONN .valueOf (opear ), nestedType .path , null , methodName .toUpperCase (), nestedType .where , null );
369
390
370
391
where .addWhere (condition );
371
392
} else if (methodName .toLowerCase ().equals ("children" )) {
@@ -375,15 +396,15 @@ else if (isChildren)
375
396
throw new SqlParseException ("could not fill children from expr:" + expr );
376
397
}
377
398
378
- Condition condition = new Condition (Where .CONN .valueOf (opear ), childrenType .childType ,null , methodName .toUpperCase (), childrenType .where ,null );
399
+ Condition condition = new Condition (Where .CONN .valueOf (opear ), childrenType .childType , null , methodName .toUpperCase (), childrenType .where , null );
379
400
380
401
where .addWhere (condition );
381
402
} else if (methodName .toLowerCase ().equals ("script" )) {
382
403
ScriptFilter scriptFilter = new ScriptFilter ();
383
404
if (!scriptFilter .tryParseFromMethodExpr (methodExpr )) {
384
405
throw new SqlParseException ("could not parse script filter" );
385
406
}
386
- Condition condition = new Condition (Where .CONN .valueOf (opear ), null , null ,"SCRIPT" , scriptFilter ,null );
407
+ Condition condition = new Condition (Where .CONN .valueOf (opear ), null , null , "SCRIPT" , scriptFilter , null );
387
408
where .addWhere (condition );
388
409
} else {
389
410
throw new SqlParseException ("unsupported method: " + methodName );
@@ -420,11 +441,11 @@ else if (isChildren)
420
441
Condition condition = null ;
421
442
422
443
if (isNested )
423
- condition = new Condition (Where .CONN .valueOf (opear ), leftSide ,null , sqlIn .isNot () ? "NOT IN" : "IN" , subQueryExpression , null ,nestedType );
444
+ condition = new Condition (Where .CONN .valueOf (opear ), leftSide , null , sqlIn .isNot () ? "NOT IN" : "IN" , subQueryExpression , null , nestedType );
424
445
else if (isChildren )
425
- condition = new Condition (Where .CONN .valueOf (opear ), leftSide ,null , sqlIn .isNot () ? "NOT IN" : "IN" , subQueryExpression , null , childrenType );
446
+ condition = new Condition (Where .CONN .valueOf (opear ), leftSide , null , sqlIn .isNot () ? "NOT IN" : "IN" , subQueryExpression , null , childrenType );
426
447
else
427
- condition = new Condition (Where .CONN .valueOf (opear ), leftSide ,null , sqlIn .isNot () ? "NOT IN" : "IN" , subQueryExpression , null , null );
448
+ condition = new Condition (Where .CONN .valueOf (opear ), leftSide , null , sqlIn .isNot () ? "NOT IN" : "IN" , subQueryExpression , null , null );
428
449
429
450
where .addWhere (condition );
430
451
} else {
@@ -528,6 +549,13 @@ private Object[] parseValue(List<SQLExpr> targetList) throws SqlParseException {
528
549
529
550
private Object parseValue (SQLExpr expr ) throws SqlParseException {
530
551
if (expr instanceof SQLNumericLiteralExpr ) {
552
+ Number number = ((SQLNumericLiteralExpr ) expr ).getNumber ();
553
+ if (number instanceof BigDecimal ){
554
+ return number .doubleValue ();
555
+ }
556
+ if (number instanceof BigInteger ){
557
+ return number .longValue ();
558
+ }
531
559
return ((SQLNumericLiteralExpr ) expr ).getNumber ();
532
560
} else if (expr instanceof SQLCharExpr ) {
533
561
return ((SQLCharExpr ) expr ).getText ();
0 commit comments