abhishekagarwal87 commented on code in PR #15408:
URL: https://github.com/apache/druid/pull/15408#discussion_r1407322340
##########
processing/src/main/java/org/apache/druid/utils/ConnectionUriUtils.java:
##########
@@ -177,19 +178,26 @@ public static Set<String>
tryParsePostgresConnectionUri(String connectionUri)
}
public static Set<String> tryParseMySqlConnectionUri(String connectionUri)
- throws ClassNotFoundException, NoSuchMethodException,
InstantiationException, IllegalAccessException,
+ throws ClassNotFoundException, NoSuchMethodException,
IllegalAccessException,
InvocationTargetException
{
- Class<?> driverClass = Class.forName(MYSQL_NON_REGISTERING_DRIVER);
- Method parseUrl = driverClass.getMethod("parseURL", String.class,
Properties.class);
- // almost the same as postgres, but is an instance level method
- Properties properties = (Properties) parseUrl.invoke(
- driverClass.getConstructor().newInstance(),
- connectionUri,
- null
- );
-
- if (properties == null) {
+ Class<?> connectionUrlParserClass =
Class.forName(MYSQL_CJ_CONF_CONNECTION_URL_PARSER);
+ Method parseUrl =
connectionUrlParserClass.getMethod("parseConnectionString", String.class);
+ // almost the same as postgres
+ Object connectionUrlParser = parseUrl.invoke(null, connectionUri);
+ Method getProperties = connectionUrlParserClass.getMethod("getProperties");
+ Properties properties = new Properties();
+ Map<String,String> propertyMap = (Map<String, String>)
getProperties.invoke(connectionUrlParser);
+ for (Map.Entry<String, String> entry : propertyMap.entrySet()) {
+ if (entry.getKey() != null) {
+ if(entry.getValue() == null) {
+ properties.setProperty(entry.getKey(), "");
+ }else {
+ properties.setProperty(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ if (properties.isEmpty()) {
Review Comment:
why would you throw an error if there are no properties associated with the
connection string? Instead you should throw an error if properties is null for
some reason.
##########
processing/src/main/java/org/apache/druid/utils/ConnectionUriUtils.java:
##########
@@ -177,19 +178,26 @@ public static Set<String>
tryParsePostgresConnectionUri(String connectionUri)
}
public static Set<String> tryParseMySqlConnectionUri(String connectionUri)
- throws ClassNotFoundException, NoSuchMethodException,
InstantiationException, IllegalAccessException,
+ throws ClassNotFoundException, NoSuchMethodException,
IllegalAccessException,
InvocationTargetException
{
- Class<?> driverClass = Class.forName(MYSQL_NON_REGISTERING_DRIVER);
- Method parseUrl = driverClass.getMethod("parseURL", String.class,
Properties.class);
- // almost the same as postgres, but is an instance level method
- Properties properties = (Properties) parseUrl.invoke(
- driverClass.getConstructor().newInstance(),
- connectionUri,
- null
- );
-
- if (properties == null) {
+ Class<?> connectionUrlParserClass =
Class.forName(MYSQL_CJ_CONF_CONNECTION_URL_PARSER);
+ Method parseUrl =
connectionUrlParserClass.getMethod("parseConnectionString", String.class);
+ // almost the same as postgres
+ Object connectionUrlParser = parseUrl.invoke(null, connectionUri);
+ Method getProperties = connectionUrlParserClass.getMethod("getProperties");
+ Properties properties = new Properties();
+ Map<String,String> propertyMap = (Map<String, String>)
getProperties.invoke(connectionUrlParser);
+ for (Map.Entry<String, String> entry : propertyMap.entrySet()) {
+ if (entry.getKey() != null) {
+ if(entry.getValue() == null) {
+ properties.setProperty(entry.getKey(), "");
+ }else {
+ properties.setProperty(entry.getKey(), entry.getValue());
+ }
+ }
+ }
Review Comment:
the code is not well formatted. You can import the checkstyle that's
available in dev folder.
##########
processing/src/main/java/org/apache/druid/utils/ConnectionUriUtils.java:
##########
@@ -177,19 +178,26 @@ public static Set<String>
tryParsePostgresConnectionUri(String connectionUri)
}
public static Set<String> tryParseMySqlConnectionUri(String connectionUri)
- throws ClassNotFoundException, NoSuchMethodException,
InstantiationException, IllegalAccessException,
+ throws ClassNotFoundException, NoSuchMethodException,
IllegalAccessException,
InvocationTargetException
{
- Class<?> driverClass = Class.forName(MYSQL_NON_REGISTERING_DRIVER);
- Method parseUrl = driverClass.getMethod("parseURL", String.class,
Properties.class);
- // almost the same as postgres, but is an instance level method
- Properties properties = (Properties) parseUrl.invoke(
- driverClass.getConstructor().newInstance(),
- connectionUri,
- null
- );
-
- if (properties == null) {
+ Class<?> connectionUrlParserClass =
Class.forName(MYSQL_CJ_CONF_CONNECTION_URL_PARSER);
+ Method parseUrl =
connectionUrlParserClass.getMethod("parseConnectionString", String.class);
+ // almost the same as postgres
+ Object connectionUrlParser = parseUrl.invoke(null, connectionUri);
+ Method getProperties = connectionUrlParserClass.getMethod("getProperties");
+ Properties properties = new Properties();
+ Map<String,String> propertyMap = (Map<String, String>)
getProperties.invoke(connectionUrlParser);
+ for (Map.Entry<String, String> entry : propertyMap.entrySet()) {
+ if (entry.getKey() != null) {
+ if(entry.getValue() == null) {
Review Comment:
is this actually possible?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]