Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Impala Jdbc URL (including schema without properties) parsing exception #644

Merged
merged 4 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Release Notes.
* Support collecting ZGC memory pool metrics. Require OAP 9.7.0 to support these new metrics.
* Upgrade netty-codec-http2 to 4.1.100.Final
* Add a netty-http 4.1.x plugin to trace HTTP requests.
* Fix Impala Jdbc URL (including schema without properties) parsing exception.


#### Documentation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public ImpalaJdbcURLParser(String url) {
protected URLLocation fetchDatabaseHostsIndexRange() {
int hostLabelStartIndex = url.indexOf("//");
int hostLabelEndIndex = url.length();
if (url.indexOf("/", hostLabelStartIndex + 2) != -1) {
hostLabelEndIndex = url.indexOf("/", hostLabelStartIndex + 2);
}
int hostLabelEndIndexWithParameter = url.indexOf(";", hostLabelStartIndex);
if (hostLabelEndIndexWithParameter != -1) {
String subUrl = url.substring(0, hostLabelEndIndexWithParameter);
Expand Down Expand Up @@ -64,6 +67,9 @@ protected URLLocation fetchDatabaseNameIndexRange(int startSize) {
if (databaseStartTag == -1 && firstParamIndex == -1) {
return null;
} else {
if (firstParamIndex == -1) {
firstParamIndex = url.length();
}
String subUrl = url.substring(startSize, firstParamIndex);
int schemaIndex = subUrl.indexOf("/");
if (schemaIndex == -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,26 @@ public void testParseClickhouseJDBCURL() {
assertThat(connectionInfo.getDatabasePeer(), is("localhost:8123"));
}

@Test
public void testParseImpalaJDBCURL() {
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:impala://localhost:21050/test;AuthMech=3;UID=UserName;PWD=Password");
assertThat(connectionInfo.getDBType(), is("Impala"));
assertThat(connectionInfo.getDatabaseName(), is("test"));
assertThat(connectionInfo.getDatabasePeer(), is("localhost:21050"));
}

@Test
public void testParseImpalaJDBCURLWithSchema() {
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:impala://localhost:21050/test");
assertThat(connectionInfo.getDBType(), is("Impala"));
assertThat(connectionInfo.getDatabaseName(), is("test"));
assertThat(connectionInfo.getDatabasePeer(), is("localhost:21050"));
}

@Test
public void testParseImpalaJDBCURLWithoutSchema() {
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:impala://localhost:21050");
assertThat(connectionInfo.getDBType(), is("Impala"));
assertThat(connectionInfo.getDatabasePeer(), is("localhost:21050"));
}
}
Loading