Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9b139bb

Browse files
committed
fix bug
当查询条件里面是double 数字是,druid 默认解析完的是BigDecimal 类型的,导致 es StreamOut writer 报错
1 parent 0ea8ff9 commit 9b139bb

File tree

1 file changed

+43
-15
lines changed

1 file changed

+43
-15
lines changed

src/main/java/org/nlpcn/es4sql/parse/WhereParser.java

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,39 @@
11
package org.nlpcn.es4sql.parse;
22

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-
83
import com.google.common.collect.Lists;
94
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+
1025
import org.nlpcn.es4sql.SQLFunctions;
1126
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;
1332
import org.nlpcn.es4sql.exception.SqlParseException;
1433
import org.nlpcn.es4sql.spatial.SpatialParamsFactory;
1534

35+
import java.math.BigDecimal;
36+
import java.math.BigInteger;
1637
import java.util.ArrayList;
1738
import java.util.List;
1839

@@ -351,11 +372,11 @@ else if (isChildren)
351372
Condition condition = null;
352373

353374
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);
355376
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);
357378
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);
359380

360381
where.addWhere(condition);
361382
} else if (methodName.toLowerCase().equals("nested")) {
@@ -365,7 +386,7 @@ else if (isChildren)
365386
throw new SqlParseException("could not fill nested from expr:" + expr);
366387
}
367388

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);
369390

370391
where.addWhere(condition);
371392
} else if (methodName.toLowerCase().equals("children")) {
@@ -375,15 +396,15 @@ else if (isChildren)
375396
throw new SqlParseException("could not fill children from expr:" + expr);
376397
}
377398

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);
379400

380401
where.addWhere(condition);
381402
} else if (methodName.toLowerCase().equals("script")) {
382403
ScriptFilter scriptFilter = new ScriptFilter();
383404
if (!scriptFilter.tryParseFromMethodExpr(methodExpr)) {
384405
throw new SqlParseException("could not parse script filter");
385406
}
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);
387408
where.addWhere(condition);
388409
} else {
389410
throw new SqlParseException("unsupported method: " + methodName);
@@ -420,11 +441,11 @@ else if (isChildren)
420441
Condition condition = null;
421442

422443
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);
424445
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);
426447
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);
428449

429450
where.addWhere(condition);
430451
} else {
@@ -528,6 +549,13 @@ private Object[] parseValue(List<SQLExpr> targetList) throws SqlParseException {
528549

529550
private Object parseValue(SQLExpr expr) throws SqlParseException {
530551
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+
}
531559
return ((SQLNumericLiteralExpr) expr).getNumber();
532560
} else if (expr instanceof SQLCharExpr) {
533561
return ((SQLCharExpr) expr).getText();

0 commit comments

Comments
 (0)