Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,13 @@ public static String parsePropertyFromUrl(final String url, final String key) {
String[] tokens = url.split(";");
for (String token : tokens) {
if (token.trim().startsWith(key.trim() + "=")) {
return token.trim().substring((key.trim() + "=").length());
String value = token.trim().substring((key.trim() + "=").length());
// Remove query string part (anything after ?) to match extractURLComponents behavior
int queryIndex = value.indexOf('?');
Copy link
Member

Choose a reason for hiding this comment

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

/**
* Get the authority string from the supplied uri, which could potentially contain multiple
* host:port pairs.
*/
private static String getAuthorityFromJdbcURL(String uri) throws JdbcUriParseException {
String authorities;
/*
* For a jdbc uri like:
* jdbc:hive2://<host1>:<port1>,<host2>:<port2>/dbName;sess_var_list?conf_list#var_list Extract
* the uri host:port list starting after "jdbc:hive2://", till the 1st "/" or "?" or "#"
* whichever comes first & in the given order Examples:
* jdbc:hive2://host1:port1,host2:port2,host3:port3/db;k1=v1?k2=v2#k3=v3
* jdbc:hive2://host1:port1,host2:port2,host3:port3/;k1=v1?k2=v2#k3=v3
* jdbc:hive2://host1:port1,host2:port2,host3:port3?k2=v2#k3=v3
* jdbc:hive2://host1:port1,host2:port2,host3:port3#k3=v3
*/
String matchedUrlPrefix = getMatchedUrlPrefix(uri);
int fromIndex = matchedUrlPrefix.length();
int toIndex = -1;
ArrayList<String> toIndexChars = new ArrayList<>(Arrays.asList("/", "?", "#"));
for (String toIndexChar : toIndexChars) {
toIndex = uri.indexOf(toIndexChar, fromIndex);
if (toIndex > 0) {
break;
}
}
if (toIndex < 0) {
authorities = uri.substring(fromIndex);
} else {
authorities = uri.substring(fromIndex, toIndex);
}
return authorities;
}

Copy link
Member

Choose a reason for hiding this comment

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

see https://kyuubi.readthedocs.io/en/master/client/jdbc/kyuubi_jdbc.html#basic-connection-url-format

jdbc:subprotocol://host:port[/catalog]/[schema];<clientProperties;><[#|?]sessionProperties>

We can parse the clientProperties only to get auth property

if (queryIndex > 0) {
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

The condition queryIndex > 0 will fail to handle query strings at the start of the value (e.g., ?param=value). Change the condition to queryIndex >= 0 to correctly handle all cases where a query string is present, including when it appears at position 0.

Suggested change
if (queryIndex > 0) {
if (queryIndex >= 0) {

Copilot uses AI. Check for mistakes.
value = value.substring(0, queryIndex);
}
return value;
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,43 @@ public void testSplitSqlStatement() {
splitSql.get(0));
assertEquals("", splitSql.get(1));
}

@Test
public void testParsePropertyFromUrlConsistentWithExtractURLComponents()
throws JdbcUriParseException {
// Test case for JWT auth with query string
String url =
"jdbc:hive2://host:10012/access_views;transportMode=http;httpPath=cliservice;"
+ "ssl=true;auth=JWT?kyuubi.session.cluster=clusterA";

// Parse using parsePropertyFromUrl
String authFromParseProperty = Utils.parsePropertyFromUrl(url, "auth");

// Parse using extractURLComponents
JdbcConnectionParams params = Utils.extractURLComponents(url, new Properties());
String authFromExtract = params.getSessionVars().get("auth");

// Both methods should return "JWT", not "JWT?kyuubi.session.cluster=clusterA"
assertEquals("JWT", authFromParseProperty);
assertEquals("JWT", authFromExtract);
assertEquals(
"parsePropertyFromUrl and extractURLComponents should return the same auth value",
authFromExtract,
authFromParseProperty);

// Verify query string parameters are correctly parsed
assertEquals("clusterA", params.getHiveConfs().get("kyuubi.session.cluster"));
}

@Test
public void testParsePropertyFromUrlWithoutQueryString() {
// Test case without query string
String url = "jdbc:hive2://localhost:10009/db;auth=KERBEROS;transportMode=binary";

String authValue = Utils.parsePropertyFromUrl(url, "auth");
assertEquals("KERBEROS", authValue);

String transportMode = Utils.parsePropertyFromUrl(url, "transportMode");
assertEquals("binary", transportMode);
}
}
Loading