Skip to content

Commit c06373e

Browse files
committed
es 8.5.3 support
1 parent 19713b4 commit c06373e

File tree

89 files changed

+14021
-12741
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+14021
-12741
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.mtj.tmp/
55

66
# Package Files #
7-
*.jar
7+
#*.jar
88
*.war
99
*.ear
1010
.classpath

.travis.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
language: java
22

33
jdk:
4-
- openjdk8
4+
- openjdk10
55

66
before_install:
7-
- wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.7-amd64.deb && sudo dpkg -i --force-confnew elasticsearch-7.17.7-amd64.deb
7+
- jdk_switcher use openjdk10
8+
- wget https://github.com/sormuras/bach/raw/master/install-jdk.sh
9+
- chmod +x $TRAVIS_BUILD_DIR/install-jdk.sh
10+
- export JAVA_HOME=$HOME/openjdk17
11+
- $TRAVIS_BUILD_DIR/install-jdk.sh -F 17 --target $JAVA_HOME
12+
- wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.5.3-amd64.deb && sudo dpkg -i --force-confnew elasticsearch-8.5.3-amd64.deb
813
- sudo cp ./src/test/resources/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml
914
- sudo cat /etc/elasticsearch/elasticsearch.yml
1015
- sudo java -version

lib/parent-join.jar

91.1 KB
Binary file not shown.

lib/reindex.jar

121 KB
Binary file not shown.

pom.xml

Lines changed: 37 additions & 28 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.1</version>
6+
<version>8.5.3.0</version>
77
<packaging>jar</packaging>
88
<description>Query elasticsearch using SQL</description>
99
<name>elasticsearch-sql</name>
@@ -44,10 +44,10 @@
4444
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4545
<runSuite>**/MainTestSuite.class</runSuite>
4646
<elasticsearch.plugin.name>sql</elasticsearch.plugin.name>
47-
<elasticsearch.version>7.17.7</elasticsearch.version>
47+
<elasticsearch.version>8.5.3</elasticsearch.version>
4848
<elasticsearch.plugin.classname>org.elasticsearch.plugin.nlpcn.SqlPlug</elasticsearch.plugin.classname>
4949
<druid.version>1.2.15</druid.version>
50-
<guava.version>30.1.1-jre</guava.version>
50+
<guava.version>31.1-jre</guava.version>
5151
</properties>
5252

5353
<repositories>
@@ -74,7 +74,7 @@
7474
<dependency>
7575
<groupId>junit</groupId>
7676
<artifactId>junit</artifactId>
77-
<version>4.13.1</version>
77+
<version>4.13.2</version>
7878
<scope>test</scope>
7979
</dependency>
8080

@@ -87,13 +87,13 @@
8787
<dependency>
8888
<groupId>org.locationtech.spatial4j</groupId>
8989
<artifactId>spatial4j</artifactId>
90-
<version>0.7</version>
90+
<version>0.8</version>
9191
</dependency>
9292

9393
<dependency>
9494
<groupId>org.locationtech.jts</groupId>
9595
<artifactId>jts-core</artifactId>
96-
<version>1.15.0</version>
96+
<version>1.19.0</version>
9797
<scope>provided</scope>
9898
</dependency>
9999

@@ -104,27 +104,50 @@
104104
<scope>provided</scope>
105105
</dependency>
106106

107-
<dependency>
108-
<groupId>org.elasticsearch.client</groupId>
109-
<artifactId>x-pack-transport</artifactId>
110-
<version>${elasticsearch.version}</version>
111-
<scope>provided</scope>
112-
</dependency>
107+
<dependency>
108+
<groupId>co.elastic.clients</groupId>
109+
<artifactId>elasticsearch-java</artifactId>
110+
<version>${elasticsearch.version}</version>
111+
<scope>provided</scope>
112+
</dependency>
113+
114+
<dependency>
115+
<groupId>com.fasterxml.jackson.core</groupId>
116+
<artifactId>jackson-databind</artifactId>
117+
<version>2.14.1</version>
118+
<scope>provided</scope>
119+
</dependency>
113120

114121
<dependency>
115122
<groupId>com.unboundid</groupId>
116123
<artifactId>unboundid-ldapsdk</artifactId>
117-
<version>6.0.5</version>
124+
<version>6.0.7</version>
118125
<scope>provided</scope>
119126
</dependency>
120127

121128
<dependency>
122129
<groupId>org.bouncycastle</groupId>
123130
<artifactId>bcprov-jdk15on</artifactId>
124-
<version>1.67</version>
131+
<version>1.70</version>
125132
<scope>provided</scope>
126133
</dependency>
127134

135+
<dependency>
136+
<groupId>org.elasticsearch.plugin</groupId>
137+
<artifactId>reindex-client</artifactId>
138+
<version>${elasticsearch.version}</version>
139+
<systemPath>${project.basedir}/lib/reindex.jar</systemPath>
140+
<scope>system</scope>
141+
</dependency>
142+
143+
<dependency>
144+
<groupId>org.elasticsearch.plugin</groupId>
145+
<artifactId>parent-join-client</artifactId>
146+
<version>${elasticsearch.version}</version>
147+
<systemPath>${project.basedir}/lib/parent-join.jar</systemPath>
148+
<scope>system</scope>
149+
</dependency>
150+
128151
<dependency>
129152
<groupId>com.google.guava</groupId>
130153
<artifactId>guava</artifactId>
@@ -203,20 +226,6 @@
203226
<configuration>
204227
<artifactItems>
205228
<artifactItem>
206-
<groupId>org.elasticsearch.plugin</groupId>
207-
<artifactId>parent-join-client</artifactId>
208-
<version>${elasticsearch.version}</version>
209-
<overWrite>false</overWrite>
210-
<outputDirectory>${project.build.directory}</outputDirectory>
211-
</artifactItem>
212-
<artifactItem>
213-
<groupId>org.elasticsearch.plugin</groupId>
214-
<artifactId>reindex-client</artifactId>
215-
<version>${elasticsearch.version}</version>
216-
<overWrite>false</overWrite>
217-
<outputDirectory>${project.build.directory}</outputDirectory>
218-
</artifactItem>
219-
<artifactItem>
220229
<groupId>com.alibaba</groupId>
221230
<artifactId>druid</artifactId>
222231
<version>${druid.version}</version>

src/assembly/zip.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,12 @@
2323
<include>plugin-descriptor.properties</include>
2424
</includes>
2525
</fileSet>
26+
<fileSet>
27+
<directory>${project.basedir}/lib</directory>
28+
<outputDirectory>/</outputDirectory>
29+
<includes>
30+
<include>*.jar</include>
31+
</includes>
32+
</fileSet>
2633
</fileSets>
2734
</assembly>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.alibaba.druid.pool;
22

3-
import org.elasticsearch.client.Client;
3+
import org.elasticsearch.client.internal.Client;
44

55
import java.sql.Array;
66
import java.sql.Blob;

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

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,12 @@
2626
import com.alibaba.druid.support.logging.Log;
2727
import com.alibaba.druid.support.logging.LogFactory;
2828
import com.alibaba.druid.util.JMXUtils;
29-
import com.alibaba.druid.util.JdbcConstants;
3029
import com.alibaba.druid.util.JdbcUtils;
3130
import com.alibaba.druid.util.StringUtils;
3231
import com.alibaba.druid.util.Utils;
3332
import com.alibaba.druid.wall.WallFilter;
3433
import com.alibaba.druid.wall.WallProviderStatValue;
35-
import org.elasticsearch.client.Client;
36-
import org.elasticsearch.common.settings.Settings;
37-
import org.elasticsearch.common.transport.TransportAddress;
38-
import org.elasticsearch.xpack.client.PreBuiltXPackTransportClient;
34+
import org.elasticsearch.client.internal.Client;
3935

4036
import javax.management.JMException;
4137
import javax.management.MBeanServer;
@@ -46,8 +42,6 @@
4642
import javax.sql.ConnectionEvent;
4743
import javax.sql.ConnectionEventListener;
4844
import javax.sql.PooledConnection;
49-
import java.net.InetAddress;
50-
import java.net.UnknownHostException;
5145
import java.security.AccessController;
5246
import java.security.PrivilegedAction;
5347
import java.sql.Connection;
@@ -143,15 +137,17 @@ public class ElasticSearchDruidDataSource extends DruidDataSource {
143137
private boolean loadSpifilterSkip = false;
144138

145139
// elasticsearch client
146-
private volatile Client client;
140+
private final Client client;
147141

148-
public ElasticSearchDruidDataSource() {
149-
this(false);
142+
public ElasticSearchDruidDataSource(Client client) {
143+
this(false, client);
150144
}
151145

152-
public ElasticSearchDruidDataSource(boolean fairLock) {
146+
public ElasticSearchDruidDataSource(boolean fairLock, Client client) {
153147
super(fairLock);
154148

149+
this.client = client;
150+
155151
configFromPropety(System.getProperties());
156152
}
157153

@@ -1012,30 +1008,6 @@ public PhysicalConnectionInfo createPhysicalConnection() throws SQLException {
10121008

10131009
@Override
10141010
public Connection createPhysicalConnection(String url, Properties info) throws SQLException {
1015-
if (client == null) {
1016-
synchronized (this) {
1017-
if (client == null) {
1018-
Settings.Builder builder = Settings.builder();
1019-
info.forEach((k, v) -> builder.put(k.toString(), v.toString()));
1020-
1021-
String[] hostAndPortArray = url.split("/")[2].split(",");
1022-
int length = hostAndPortArray.length;
1023-
TransportAddress[] addresses = new TransportAddress[length];
1024-
try {
1025-
String[] hostAndPortArr;
1026-
for (int i = 0; i < length; ++i) {
1027-
hostAndPortArr = hostAndPortArray[i].split(":");
1028-
addresses[i] = new TransportAddress(InetAddress.getByName(hostAndPortArr[0]), Integer.parseInt(hostAndPortArr[1]));
1029-
}
1030-
} catch (UnknownHostException e) {
1031-
throw new SQLException(e);
1032-
}
1033-
1034-
client = new PreBuiltXPackTransportClient(builder.build()).addTransportAddresses(addresses);
1035-
}
1036-
}
1037-
}
1038-
10391011
Connection conn = new ElasticSearchConnection(client);
10401012
createCountUpdater.incrementAndGet(this);
10411013

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

3+
import org.elasticsearch.client.internal.Client;
4+
35
import javax.sql.DataSource;
4-
import java.util.Map;
56
import java.util.Properties;
67

78
/**
@@ -11,20 +12,10 @@ public class ElasticSearchDruidDataSourceFactory extends DruidDataSourceFactory
1112

1213
@Override
1314
protected DataSource createDataSourceInternal(Properties properties) throws Exception {
14-
DruidDataSource dataSource = new ElasticSearchDruidDataSource();
15-
config(dataSource, properties);
16-
return dataSource;
17-
}
18-
19-
@SuppressWarnings("rawtypes")
20-
public static DataSource createDataSource(Properties properties) throws Exception {
21-
return createDataSource((Map) properties);
15+
throw new UnsupportedOperationException();
2216
}
2317

24-
@SuppressWarnings("rawtypes")
25-
public static DataSource createDataSource(Map properties) throws Exception {
26-
DruidDataSource dataSource = new ElasticSearchDruidDataSource();
27-
config(dataSource, properties);
28-
return dataSource;
18+
public static DataSource createDataSource(Client client) {
19+
return new ElasticSearchDruidDataSource(client);
2920
}
3021
}

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

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

3-
import org.elasticsearch.client.Client;
3+
import org.elasticsearch.client.internal.Client;
44
import org.elasticsearch.plugin.nlpcn.QueryActionElasticExecutor;
55
import org.elasticsearch.plugin.nlpcn.executors.CsvExtractorException;
66
import org.nlpcn.es4sql.SearchDao;
@@ -37,7 +37,7 @@ public ResultSet executeQuery() throws SQLException {
3737

3838
conn.beforeExecute();
3939
try {
40-
ObjectResult extractor = getObjectResult(true, false, false, true);
40+
ObjectResult extractor = getObjectResult(true, false, true);
4141
List<String> headers = extractor.getHeaders();
4242
List<List<Object>> lines = extractor.getLines();
4343

@@ -67,7 +67,7 @@ public boolean execute() throws SQLException {
6767

6868
conn.beforeExecute();
6969
try {
70-
ObjectResult extractor = getObjectResult(true, false, false, true);
70+
ObjectResult extractor = getObjectResult(true, false, true);
7171
List<String> headers = extractor.getHeaders();
7272
List<List<Object>> lines = extractor.getLines();
7373

@@ -84,13 +84,13 @@ public boolean execute() throws SQLException {
8484
}
8585
}
8686

87-
private ObjectResult getObjectResult(boolean flat, boolean includeScore, boolean includeType, boolean includeId) throws SqlParseException, SQLFeatureNotSupportedException, Exception, CsvExtractorException {
87+
private ObjectResult getObjectResult(boolean flat, boolean includeScore, boolean includeId) throws SqlParseException, SQLFeatureNotSupportedException, Exception, CsvExtractorException {
8888
SearchDao searchDao = new org.nlpcn.es4sql.SearchDao(client);
8989

9090
String query = ((ElasticSearchPreparedStatement) getRawPreparedStatement()).getExecutableSql();
9191
QueryAction queryAction = searchDao.explain(query);
9292
Object execution = QueryActionElasticExecutor.executeAnyAction(searchDao.getClient(), queryAction);
93-
return new ObjectResultsExtractor(includeScore, includeType, includeId, false, queryAction).extractResults(execution, flat);
93+
return new ObjectResultsExtractor(includeScore, includeId, false, queryAction).extractResults(execution, flat);
9494
}
9595

9696
@Override

0 commit comments

Comments
 (0)