Skip to content

Commit 2721438

Browse files
authored
Fix Impala Jdbc URL (including schema without properties) parsing exception (#644)
1 parent d5cfd35 commit 2721438

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Release Notes.
1818
* Support collecting ZGC memory pool metrics. Require OAP 9.7.0 to support these new metrics.
1919
* Upgrade netty-codec-http2 to 4.1.100.Final
2020
* Add a netty-http 4.1.x plugin to trace HTTP requests.
21+
* Fix Impala Jdbc URL (including schema without properties) parsing exception.
2122

2223

2324
#### Documentation

apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/ImpalaJdbcURLParser.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public ImpalaJdbcURLParser(String url) {
3636
protected URLLocation fetchDatabaseHostsIndexRange() {
3737
int hostLabelStartIndex = url.indexOf("//");
3838
int hostLabelEndIndex = url.length();
39+
if (url.indexOf("/", hostLabelStartIndex + 2) != -1) {
40+
hostLabelEndIndex = url.indexOf("/", hostLabelStartIndex + 2);
41+
}
3942
int hostLabelEndIndexWithParameter = url.indexOf(";", hostLabelStartIndex);
4043
if (hostLabelEndIndexWithParameter != -1) {
4144
String subUrl = url.substring(0, hostLabelEndIndexWithParameter);
@@ -64,6 +67,9 @@ protected URLLocation fetchDatabaseNameIndexRange(int startSize) {
6467
if (databaseStartTag == -1 && firstParamIndex == -1) {
6568
return null;
6669
} else {
70+
if (firstParamIndex == -1) {
71+
firstParamIndex = url.length();
72+
}
6773
String subUrl = url.substring(startSize, firstParamIndex);
6874
int schemaIndex = subUrl.indexOf("/");
6975
if (schemaIndex == -1) {

apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,26 @@ public void testParseClickhouseJDBCURL() {
185185
assertThat(connectionInfo.getDatabasePeer(), is("localhost:8123"));
186186
}
187187

188+
@Test
189+
public void testParseImpalaJDBCURL() {
190+
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:impala://localhost:21050/test;AuthMech=3;UID=UserName;PWD=Password");
191+
assertThat(connectionInfo.getDBType(), is("Impala"));
192+
assertThat(connectionInfo.getDatabaseName(), is("test"));
193+
assertThat(connectionInfo.getDatabasePeer(), is("localhost:21050"));
194+
}
195+
196+
@Test
197+
public void testParseImpalaJDBCURLWithSchema() {
198+
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:impala://localhost:21050/test");
199+
assertThat(connectionInfo.getDBType(), is("Impala"));
200+
assertThat(connectionInfo.getDatabaseName(), is("test"));
201+
assertThat(connectionInfo.getDatabasePeer(), is("localhost:21050"));
202+
}
203+
204+
@Test
205+
public void testParseImpalaJDBCURLWithoutSchema() {
206+
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:impala://localhost:21050");
207+
assertThat(connectionInfo.getDBType(), is("Impala"));
208+
assertThat(connectionInfo.getDatabasePeer(), is("localhost:21050"));
209+
}
188210
}

0 commit comments

Comments
 (0)