Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -35,7 +35,7 @@ public ImpalaJdbcURLParser(String url) {
@Override
protected URLLocation fetchDatabaseHostsIndexRange() {
int hostLabelStartIndex = url.indexOf("//");
int hostLabelEndIndex = url.length();
int 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 +64,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 Expand Up @@ -99,7 +102,7 @@ public ConnectionInfo parse() {
} else {
String[] hostAndPort = hostSegment[0].split(":");
if (hostAndPort.length != 1) {
return new ConnectionInfo(component, DB_TYPE, hostAndPort[0], Integer.valueOf(hostAndPort[1]), fetchDatabaseNameFromURL(location
return new ConnectionInfo(component, DB_TYPE, hostAndPort[0], Integer.parseInt(hostAndPort[1]), fetchDatabaseNameFromURL(location
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why change this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ConnectionInfo's param port need type int not Integer, whether Integer.parseInt is better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My question is why do you use parseInt insteads of valueOf.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the ConnectionInfo's port need type int, so Integer.parseInt is enough, and Integer.valueOf(Integer.valueOf(parseInt()) here return Integer may be unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert Integer .valueOf changes, and fix impala url parse exception only first.

.endIndex()));
} else {
return new ConnectionInfo(component, DB_TYPE, hostAndPort[0], DEFAULT_PORT, fetchDatabaseNameFromURL(location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,18 @@ public void testParseClickhouseJDBCURL() {
assertThat(connectionInfo.getDatabasePeer(), is("localhost:8123"));
}

@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 testParseImpalaJDBCURL() {
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:impala://localhost:21050;AuthMech=3;UID=UserName;PWD=Password");
assertThat(connectionInfo.getDBType(), is("Impala"));
assertThat(connectionInfo.getDatabasePeer(), is("localhost:21050"));
}
}