Skip to content

Commit 19713b4

Browse files
committed
fix #1187 upgrade druid to 1.2.15
1 parent ab17f62 commit 19713b4

File tree

12 files changed

+9571
-56
lines changed

12 files changed

+9571
-56
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.nlpcn</groupId>
55
<artifactId>elasticsearch-sql</artifactId>
6-
<version>7.17.7.0</version>
6+
<version>7.17.7.1</version>
77
<packaging>jar</packaging>
88
<description>Query elasticsearch using SQL</description>
99
<name>elasticsearch-sql</name>
@@ -46,7 +46,7 @@
4646
<elasticsearch.plugin.name>sql</elasticsearch.plugin.name>
4747
<elasticsearch.version>7.17.7</elasticsearch.version>
4848
<elasticsearch.plugin.classname>org.elasticsearch.plugin.nlpcn.SqlPlug</elasticsearch.plugin.classname>
49-
<druid.version>1.1.16</druid.version>
49+
<druid.version>1.2.15</druid.version>
5050
<guava.version>30.1.1-jre</guava.version>
5151
</properties>
5252

src/main/java/com/alibaba/druid/pool/ElasticSearchDruidDataSource.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.alibaba.druid.pool;
22

33
import com.alibaba.druid.Constants;
4+
import com.alibaba.druid.DbType;
45
import com.alibaba.druid.TransactionTimeoutException;
56
import com.alibaba.druid.VERSION;
67
import com.alibaba.druid.filter.AutoLoad;
@@ -795,13 +796,12 @@ public void init() throws SQLException {
795796
filter.init(this);
796797
}
797798

798-
if (this.dbType == null || this.dbType.length() == 0) {
799-
this.dbType = JdbcUtils.getDbType(jdbcUrl, null);
799+
if (this.dbTypeName == null || this.dbTypeName.length() == 0) {
800+
this.dbTypeName = JdbcUtils.getDbType(jdbcUrl, null);
800801
}
801802

802-
if (JdbcConstants.MYSQL.equals(this.dbType)
803-
|| JdbcConstants.MARIADB.equals(this.dbType)
804-
|| JdbcConstants.ALIYUN_ADS.equals(this.dbType)) {
803+
DbType dbType = DbType.of(this.dbTypeName);
804+
if (JdbcUtils.isMysqlDbType(dbType)) {
805805
boolean cacheServerConfigurationSet = false;
806806
if (this.connectProperties.containsKey("cacheServerConfiguration")) {
807807
cacheServerConfigurationSet = true;
@@ -848,14 +848,14 @@ public void init() throws SQLException {
848848
if (isUseGlobalDataSourceStat()) {
849849
dataSourceStat = JdbcDataSourceStat.getGlobal();
850850
if (dataSourceStat == null) {
851-
dataSourceStat = new JdbcDataSourceStat("Global", "Global", this.dbType);
851+
dataSourceStat = new JdbcDataSourceStat("Global", "Global", this.dbTypeName);
852852
JdbcDataSourceStat.setGlobal(dataSourceStat);
853853
}
854854
if (dataSourceStat.getDbType() == null) {
855-
dataSourceStat.setDbType(this.dbType);
855+
dataSourceStat.setDbType(this.dbTypeName);
856856
}
857857
} else {
858-
dataSourceStat = new JdbcDataSourceStat(this.name, this.jdbcUrl, this.dbType, this.connectProperties);
858+
dataSourceStat = new JdbcDataSourceStat(this.name, this.jdbcUrl, this.dbTypeName, this.connectProperties);
859859
}
860860
dataSourceStat.setResetStatEnable(this.resetStatEnable);
861861

@@ -1187,7 +1187,9 @@ private void validationQueryCheck() {
11871187
}
11881188

11891189
protected void initCheck() throws SQLException {
1190-
if (JdbcUtils.ORACLE.equals(this.dbType)) {
1190+
DbType dbType = DbType.of(this.dbTypeName);
1191+
1192+
if (dbType == DbType.oracle) {
11911193
isOracle = true;
11921194

11931195
if (driver.getMajorVersion() < 10) {
@@ -1200,15 +1202,17 @@ protected void initCheck() throws SQLException {
12001202
}
12011203

12021204
oracleValidationQueryCheck();
1203-
} else if (JdbcUtils.DB2.equals(dbType)) {
1205+
} else if (dbType == DbType.db2) {
12041206
db2ValidationQueryCheck();
1205-
} else if (JdbcUtils.MYSQL.equals(this.dbType)
1206-
|| JdbcUtils.MYSQL_DRIVER_6.equals(this.dbType)) {
1207+
} else if (dbType == DbType.mysql
1208+
|| JdbcUtils.MYSQL_DRIVER.equals(this.driverClass)
1209+
|| JdbcUtils.MYSQL_DRIVER_6.equals(this.driverClass)
1210+
) {
12071211
isMySql = true;
12081212
}
12091213

12101214
if (removeAbandoned) {
1211-
LOG.warn("removeAbandoned is true, not use in productiion.");
1215+
LOG.warn("removeAbandoned is true, not use in production.");
12121216
}
12131217
}
12141218

@@ -1220,7 +1224,7 @@ private void oracleValidationQueryCheck() {
12201224
return;
12211225
}
12221226

1223-
SQLStatementParser sqlStmtParser = SQLParserUtils.createSQLStatementParser(validationQuery, this.dbType);
1227+
SQLStatementParser sqlStmtParser = SQLParserUtils.createSQLStatementParser(validationQuery, DbType.of(this.dbTypeName));
12241228
List<SQLStatement> stmtList = sqlStmtParser.parseStatementList();
12251229

12261230
if (stmtList.size() != 1) {
@@ -1249,7 +1253,7 @@ private void db2ValidationQueryCheck() {
12491253
return;
12501254
}
12511255

1252-
SQLStatementParser sqlStmtParser = SQLParserUtils.createSQLStatementParser(validationQuery, this.dbType);
1256+
SQLStatementParser sqlStmtParser = SQLParserUtils.createSQLStatementParser(validationQuery, DbType.of(this.dbTypeName));
12531257
List<SQLStatement> stmtList = sqlStmtParser.parseStatementList();
12541258

12551259
if (stmtList.size() != 1) {
@@ -2127,7 +2131,7 @@ public DruidDataSourceStatValue getStatValueAndReset() {
21272131
}
21282132

21292133
value.setName(this.getName());
2130-
value.setDbType(this.dbType);
2134+
value.setDbType(this.dbTypeName);
21312135
value.setDriverClassName(this.getDriverClassName());
21322136

21332137
value.setUrl(this.getUrl());
@@ -3103,7 +3107,7 @@ public JdbcDataSourceStat getDataSourceStat() {
31033107
return dataSourceStat;
31043108
}
31053109

3106-
public Object clone() throws CloneNotSupportedException {
3110+
public Object clone() {
31073111
return cloneDruidDataSource();
31083112
}
31093113

@@ -3145,7 +3149,7 @@ public Map<String, Object> getStatDataForMBean() {
31453149
map.put("MinEvictableIdleTimeMillis", this.minEvictableIdleTimeMillis);
31463150
map.put("ConnectErrorCount", this.getConnectErrorCount());
31473151
map.put("CreateTimespanMillis", this.getCreateTimespanMillis());
3148-
map.put("DbType", this.dbType);
3152+
map.put("DbType", this.dbTypeName);
31493153

31503154
// 20 - 24
31513155
map.put("ValidationQuery", this.getValidationQuery());
@@ -3221,7 +3225,7 @@ public Map<String, Object> getStatData() {
32213225

32223226
dataMap.put("Identity", System.identityHashCode(this));
32233227
dataMap.put("Name", this.getName());
3224-
dataMap.put("DbType", this.dbType);
3228+
dataMap.put("DbType", this.dbTypeName);
32253229
dataMap.put("DriverClassName", this.getDriverClassName());
32263230

32273231
dataMap.put("URL", this.getUrl());

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public ElasticLexer(char[] input, int inputLength, boolean skipComment) {
2323
}
2424

2525
public void scanIdentifier() {
26-
hash_lower = 0;
26+
hashLCase = 0;
2727
hash = 0;
2828

2929
final char first = ch;
@@ -62,14 +62,14 @@ && charAt(pos + 1) == '\'') {
6262
throw new ParserException("illegal identifier. " + info());
6363
}
6464

65-
hash_lower = 0xcbf29ce484222325L;
65+
hashLCase = 0xcbf29ce484222325L;
6666
hash = 0xcbf29ce484222325L;
6767

6868
for (int i = startPos; i < quoteIndex; ++i) {
6969
ch = text.charAt(i);
7070

71-
hash_lower ^= ((ch >= 'A' && ch <= 'Z') ? (ch + 32) : ch);
72-
hash_lower *= 0x100000001b3L;
71+
hashLCase ^= ((ch >= 'A' && ch <= 'Z') ? (ch + 32) : ch);
72+
hashLCase *= 0x100000001b3L;
7373

7474
hash ^= ch;
7575
hash *= 0x100000001b3L;
@@ -86,11 +86,11 @@ && charAt(pos + 1) == '\'') {
8686
throw new ParserException("illegal identifier. " + info());
8787
}
8888

89-
hash_lower = 0xcbf29ce484222325L;
89+
hashLCase = 0xcbf29ce484222325L;
9090
hash = 0xcbf29ce484222325L;
9191

92-
hash_lower ^= ((ch >= 'A' && ch <= 'Z') ? (ch + 32) : ch);
93-
hash_lower *= 0x100000001b3L;
92+
hashLCase ^= ((ch >= 'A' && ch <= 'Z') ? (ch + 32) : ch);
93+
hashLCase *= 0x100000001b3L;
9494

9595
hash ^= ch;
9696
hash *= 0x100000001b3L;
@@ -107,8 +107,8 @@ && charAt(pos + 1) == '\'') {
107107

108108
bufPos++;
109109

110-
hash_lower ^= ((ch >= 'A' && ch <= 'Z') ? (ch + 32) : ch);
111-
hash_lower *= 0x100000001b3L;
110+
hashLCase ^= ((ch >= 'A' && ch <= 'Z') ? (ch + 32) : ch);
111+
hashLCase *= 0x100000001b3L;
112112

113113
hash ^= ch;
114114
hash *= 0x100000001b3L;
@@ -127,7 +127,7 @@ && charAt(pos + 1) == '\'') {
127127
return;
128128
}
129129

130-
Token tok = keywods.getKeyword(hash_lower);
130+
Token tok = keywords.getKeyword(hashLCase);
131131
if (tok != null) {
132132
token = tok;
133133
if (token == Token.IDENTIFIER) {

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
1616
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
1717
import com.alibaba.druid.sql.ast.expr.SQLExistsExpr;
18+
import com.alibaba.druid.sql.ast.expr.SQLExtractExpr;
1819
import com.alibaba.druid.sql.ast.expr.SQLHexExpr;
1920
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
2021
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
2122
import com.alibaba.druid.sql.ast.expr.SQLIntervalExpr;
2223
import com.alibaba.druid.sql.ast.expr.SQLIntervalUnit;
24+
import com.alibaba.druid.sql.ast.expr.SQLMatchAgainstExpr;
2325
import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
2426
import com.alibaba.druid.sql.ast.expr.SQLNotExpr;
2527
import com.alibaba.druid.sql.ast.expr.SQLUnaryExpr;
@@ -32,8 +34,6 @@
3234
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlUnique;
3335
import com.alibaba.druid.sql.dialect.mysql.ast.MysqlForeignKey;
3436
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlCharExpr;
35-
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlExtractExpr;
36-
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlMatchAgainstExpr;
3737
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOrderingExpr;
3838
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOutFileExpr;
3939
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlUserName;
@@ -369,7 +369,7 @@ protected SQLExpr bracketRest(SQLExpr expr) {
369369

370370
if (expr instanceof SQLMethodInvokeExpr) {
371371
SQLMethodInvokeExpr methodInvokeExpr = (SQLMethodInvokeExpr) expr;
372-
methodInvokeExpr.getParameters().add(new SQLIntegerExpr(index));
372+
methodInvokeExpr.getArguments().add(new SQLIntegerExpr(index));
373373
}
374374
lexer.nextToken();
375375
expr = primaryRest(expr);
@@ -443,8 +443,8 @@ protected SQLExpr parsePosition() {
443443
accept(Token.RPAREN);
444444

445445
SQLMethodInvokeExpr locate = new SQLMethodInvokeExpr("LOCATE");
446-
locate.addParameter(subStr);
447-
locate.addParameter(str);
446+
locate.addArgument(subStr);
447+
locate.addArgument(str);
448448

449449
return primaryRest(locate);
450450
}
@@ -463,7 +463,7 @@ protected SQLExpr parseExtract() {
463463

464464
SQLExpr value = expr();
465465

466-
MySqlExtractExpr extract = new MySqlExtractExpr();
466+
SQLExtractExpr extract = new SQLExtractExpr();
467467
extract.setValue(value);
468468
extract.setUnit(unit);
469469
accept(Token.RPAREN);
@@ -475,7 +475,7 @@ protected SQLExpr parseExtract() {
475475

476476
protected SQLExpr parseMatch() {
477477

478-
MySqlMatchAgainstExpr matchAgainstExpr = new MySqlMatchAgainstExpr();
478+
SQLMatchAgainstExpr matchAgainstExpr = new SQLMatchAgainstExpr();
479479

480480
if (lexer.token() == Token.RPAREN) {
481481
lexer.nextToken();
@@ -500,14 +500,14 @@ protected SQLExpr parseMatch() {
500500
lexer.nextToken();
501501
acceptIdentifier("QUERY");
502502
acceptIdentifier("EXPANSION");
503-
matchAgainstExpr.setSearchModifier(MySqlMatchAgainstExpr.SearchModifier.IN_NATURAL_LANGUAGE_MODE_WITH_QUERY_EXPANSION);
503+
matchAgainstExpr.setSearchModifier(SQLMatchAgainstExpr.SearchModifier.IN_NATURAL_LANGUAGE_MODE_WITH_QUERY_EXPANSION);
504504
} else {
505-
matchAgainstExpr.setSearchModifier(MySqlMatchAgainstExpr.SearchModifier.IN_NATURAL_LANGUAGE_MODE);
505+
matchAgainstExpr.setSearchModifier(SQLMatchAgainstExpr.SearchModifier.IN_NATURAL_LANGUAGE_MODE);
506506
}
507507
} else if (lexer.identifierEquals(FnvHash.Constants.BOOLEAN)) {
508508
lexer.nextToken();
509509
acceptIdentifier("MODE");
510-
matchAgainstExpr.setSearchModifier(MySqlMatchAgainstExpr.SearchModifier.IN_BOOLEAN_MODE);
510+
matchAgainstExpr.setSearchModifier(SQLMatchAgainstExpr.SearchModifier.IN_BOOLEAN_MODE);
511511
} else {
512512
throw new ParserException("syntax error. " + lexer.info());
513513
}

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

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.nlpcn.es4sql.parse;
22

3+
import com.alibaba.druid.sql.ast.SQLCommentHint;
34
import com.alibaba.druid.sql.ast.SQLExpr;
45
import com.alibaba.druid.sql.ast.SQLName;
56
import com.alibaba.druid.sql.ast.SQLObject;
@@ -84,7 +85,7 @@ public SQLSelectQuery query(SQLObject parent, boolean acceptUnion) {
8485
lexer.nextToken();
8586

8687
SQLSelectQuery select = query();
87-
select.setBracket(true);
88+
select.setParenthesized(true);
8889
accept(Token.RPAREN);
8990

9091
return queryRest(select, acceptUnion);
@@ -238,7 +239,7 @@ public SQLTableSource parseTableSource() {
238239

239240
SQLSelectQuery query = queryRest(select.getQuery());
240241
if (query instanceof SQLUnionQuery && select.getWithSubQuery() == null) {
241-
select.getQuery().setBracket(true);
242+
select.getQuery().setParenthesized(true);
242243
tableSource = new SQLUnionQueryTableSource((SQLUnionQuery) query);
243244
} else {
244245
tableSource = new SQLSubqueryTableSource(select);
@@ -276,6 +277,37 @@ public SQLTableSource parseTableSource() {
276277
return tableSrc;
277278
}
278279

280+
@Override
281+
protected void parseTableSourceQueryTableExpr(SQLExprTableSource tableReference) {
282+
if (lexer.token() == Token.LITERAL_ALIAS || lexer.identifierEquals(FnvHash.Constants.IDENTIFIED)
283+
|| lexer.token() == Token.LITERAL_CHARS) {
284+
tableReference.setExpr(this.exprParser.name());
285+
return;
286+
}
287+
288+
if (lexer.token() == Token.HINT) {
289+
SQLCommentHint hint = this.exprParser.parseHint();
290+
tableReference.setHint(hint);
291+
}
292+
293+
SQLExpr expr;
294+
switch (lexer.token()) {
295+
case ALL:
296+
case SET:
297+
expr = this.exprParser.name();
298+
break;
299+
default:
300+
expr = expr();
301+
break;
302+
}
303+
304+
/*if (expr instanceof SQLBinaryOpExpr) {
305+
throw new ParserException("Invalid from clause : " + expr.toString().replace("\n", " "));
306+
}*/
307+
308+
tableReference.setExpr(expr);
309+
}
310+
279311
protected MySqlUpdateStatement parseUpdateStatment() {
280312
MySqlUpdateStatement update = new MySqlUpdateStatement();
281313

@@ -449,7 +481,7 @@ protected SQLTableSource primaryTableSourceRest(SQLTableSource tableSource) {
449481
}
450482

451483
@Override
452-
protected SQLTableSource parseTableSourceRest(SQLTableSource tableSource) {
484+
public SQLTableSource parseTableSourceRest(SQLTableSource tableSource) {
453485
if (lexer.identifierEquals(FnvHash.Constants.USING)) {
454486
return tableSource;
455487
}

0 commit comments

Comments
 (0)