This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-java.git


The following commit(s) were added to refs/heads/main by this push:
     new 2721438820 Fix Impala Jdbc URL (including schema without properties) 
parsing exception (#644)
2721438820 is described below

commit 27214388200183c0a27ca57eb7041aa9d4aff921
Author: Chen Ziyan <clairelove.c...@gmail.com>
AuthorDate: Thu Nov 2 15:32:31 2023 +0800

    Fix Impala Jdbc URL (including schema without properties) parsing exception 
(#644)
---
 CHANGES.md                                         |  1 +
 .../connectionurl/parser/ImpalaJdbcURLParser.java  |  6 ++++++
 .../jdbc/connectionurl/parser/URLParserTest.java   | 22 ++++++++++++++++++++++
 3 files changed, 29 insertions(+)

diff --git a/CHANGES.md b/CHANGES.md
index 46c54f8a35..a63f4a9a58 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -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
diff --git 
a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/ImpalaJdbcURLParser.java
 
b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/ImpalaJdbcURLParser.java
index c11052e23d..c33c917774 100644
--- 
a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/ImpalaJdbcURLParser.java
+++ 
b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/ImpalaJdbcURLParser.java
@@ -36,6 +36,9 @@ public class ImpalaJdbcURLParser extends AbstractURLParser {
     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);
@@ -64,6 +67,9 @@ public class ImpalaJdbcURLParser extends AbstractURLParser {
         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) {
diff --git 
a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java
 
b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java
index a1d0a910c7..9556a0bc27 100644
--- 
a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java
+++ 
b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java
@@ -185,4 +185,26 @@ public class URLParserTest {
         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"));
+    }
 }

Reply via email to