You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "azexcy (via GitHub)" <gi...@apache.org> on 2023/07/07 06:46:43 UTC

[GitHub] [shardingsphere] azexcy opened a new pull request, #26808: Refactor JdbcQueryPropertiesExtension

azexcy opened a new pull request, #26808:
URL: https://github.com/apache/shardingsphere/pull/26808

   Fixes #ISSUSE_ID.
   
   Changes proposed in this pull request:
     -
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [ ] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [ ] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the pull request.
   - [ ] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [ ] I have added corresponding unit tests for my changes.
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] sandynz commented on a diff in pull request #26808: Refactor JdbcQueryPropertiesExtension

Posted by "sandynz (via GitHub)" <gi...@apache.org>.
sandynz commented on code in PR #26808:
URL: https://github.com/apache/shardingsphere/pull/26808#discussion_r1255353713


##########
kernel/data-pipeline/api/src/main/java/org/apache/shardingsphere/data/pipeline/api/datasource/config/impl/ShardingSpherePipelineDataSourceConfiguration.java:
##########
@@ -88,18 +91,15 @@ private String getJdbcUrl(final Map<String, Object> props) {
     
     private void appendJdbcQueryProperties(final String databaseType) {
         Optional<JdbcQueryPropertiesExtension> extension = PipelineTypedSPILoader.findDatabaseTypedService(JdbcQueryPropertiesExtension.class, databaseType);
-        if (!extension.isPresent()) {
+        if (!extension.isPresent() || extension.get().extendQueryProperties(new Properties()).isEmpty()) {
             return;
         }

Review Comment:
   Could we remove ` || extension.get().extendQueryProperties(new Properties()).isEmpty()`? There's another `extendQueryProperties` invocation



##########
kernel/data-pipeline/dialect/postgresql/src/main/java/org/apache/shardingsphere/data/pipeline/postgresql/datasource/PostgreSQLJdbcQueryPropertiesExtension.java:
##########
@@ -29,7 +29,7 @@ public final class PostgreSQLJdbcQueryPropertiesExtension implements JdbcQueryPr
     private final Properties queryProps = new Properties();
     
     @Override
-    public Properties extendQueryProperties() {
+    public Properties extendQueryProperties(final Properties props) {
         queryProps.setProperty("stringtype", "unspecified");

Review Comment:
   These `queryProps.setProperty` should be in constructor



##########
kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/datasource/MySQLJdbcQueryPropertiesExtension.java:
##########
@@ -64,7 +64,13 @@ private static String initMysqlConnectorVersion() {
     }
     
     @Override
-    public Properties extendQueryProperties() {
+    public Properties extendQueryProperties(final Properties props) {
+        if (props.isEmpty()) {
+            return queryProps;
+        }
+        if (props.containsKey("netTimeoutForStreamingResults")) {
+            queryProps.setProperty("netTimeoutForStreamingResults", props.getProperty("netTimeoutForStreamingResults"));
+        }
         return queryProps;

Review Comment:
   `queryProps` should not be modified, else it'll break other invocations



##########
kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/datasource/MySQLJdbcQueryPropertiesExtension.java:
##########
@@ -64,7 +64,13 @@ private static String initMysqlConnectorVersion() {
     }
     
     @Override
-    public Properties extendQueryProperties() {
+    public Properties extendQueryProperties(final Properties props) {
+        if (props.isEmpty()) {
+            return queryProps;
+        }
+        if (props.containsKey("netTimeoutForStreamingResults")) {
+            queryProps.setProperty("netTimeoutForStreamingResults", props.getProperty("netTimeoutForStreamingResults"));
+        }

Review Comment:
   Could we add a strategy to decide which one is used, but not hard-coded? e.g. which one is greater for timeout?



##########
kernel/data-pipeline/api/src/main/java/org/apache/shardingsphere/data/pipeline/spi/datasource/JdbcQueryPropertiesExtension.java:
##########
@@ -31,7 +31,8 @@ public interface JdbcQueryPropertiesExtension extends TypedSPI {
     /**
      * Extend query properties.
      *
+     * @param props props
      * @return JDBC query properties for extension. Could NOT be null
      */
-    Properties extendQueryProperties();
+    Properties extendQueryProperties(Properties props);

Review Comment:
   And update all of the implementations



##########
kernel/data-pipeline/api/src/main/java/org/apache/shardingsphere/data/pipeline/spi/datasource/JdbcQueryPropertiesExtension.java:
##########
@@ -31,7 +31,8 @@ public interface JdbcQueryPropertiesExtension extends TypedSPI {
     /**
      * Extend query properties.
      *
+     * @param props props
      * @return JDBC query properties for extension. Could NOT be null
      */
-    Properties extendQueryProperties();
+    Properties extendQueryProperties(Properties props);

Review Comment:
   1, `Properties` result type should be removed.
   
   2, Just extend properties of `props` parameter.



##########
kernel/data-pipeline/dialect/opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/datasource/OpenGaussJdbcQueryPropertiesExtension.java:
##########
@@ -29,7 +29,7 @@ public final class OpenGaussJdbcQueryPropertiesExtension implements JdbcQueryPro
     private final Properties queryProps = new Properties();
     
     @Override
-    public Properties extendQueryProperties() {
+    public Properties extendQueryProperties(final Properties props) {
         queryProps.setProperty("stringtype", "unspecified");
         queryProps.setProperty("bitToString", "true");

Review Comment:
   These `queryProps.setProperty` should be in constructor



##########
kernel/data-pipeline/api/src/main/java/org/apache/shardingsphere/data/pipeline/api/datasource/config/impl/ShardingSpherePipelineDataSourceConfiguration.java:
##########
@@ -88,18 +91,15 @@ private String getJdbcUrl(final Map<String, Object> props) {
     
     private void appendJdbcQueryProperties(final String databaseType) {
         Optional<JdbcQueryPropertiesExtension> extension = PipelineTypedSPILoader.findDatabaseTypedService(JdbcQueryPropertiesExtension.class, databaseType);
-        if (!extension.isPresent()) {
+        if (!extension.isPresent() || extension.get().extendQueryProperties(new Properties()).isEmpty()) {
             return;
         }
-        Properties queryProps = extension.get().extendQueryProperties();
-        if (queryProps.isEmpty()) {
-            return;
+        for (Entry<String, Map<String, Object>> entry : rootConfig.getDataSources().entrySet()) {
+            String jdbcUrlKey = entry.getValue().containsKey("url") ? "url" : "jdbcUrl";
+            JdbcUrl jdbcUrl = new StandardJdbcUrlParser().parse(entry.getValue().get(jdbcUrlKey).toString());
+            Properties extendedQueryProperties = extension.get().extendQueryProperties(jdbcUrl.getQueryProperties());
+            entry.getValue().replace(jdbcUrlKey, new JdbcUrlAppender().appendQueryProperties(entry.getValue().get(jdbcUrlKey).toString(), extendedQueryProperties));
         }
-        rootConfig.getDataSources()
-                .forEach((key, value) -> {
-                    String jdbcUrlKey = value.containsKey("url") ? "url" : "jdbcUrl";
-                    value.replace(jdbcUrlKey, new JdbcUrlAppender().appendQueryProperties(value.get(jdbcUrlKey).toString(), queryProps));
-                });
     }

Review Comment:
   Looks the new block of code has much more characters, could we just add some new line of code in existing forEach block?



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] sandynz commented on a diff in pull request #26808: Refactor JdbcQueryPropertiesExtension

Posted by "sandynz (via GitHub)" <gi...@apache.org>.
sandynz commented on code in PR #26808:
URL: https://github.com/apache/shardingsphere/pull/26808#discussion_r1255607330


##########
kernel/data-pipeline/dialect/opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/datasource/OpenGaussJdbcQueryPropertiesExtension.java:
##########
@@ -28,11 +28,14 @@ public final class OpenGaussJdbcQueryPropertiesExtension implements JdbcQueryPro
     
     private final Properties queryProps = new Properties();
     
-    @Override
-    public Properties extendQueryProperties() {
+    public OpenGaussJdbcQueryPropertiesExtension() {
         queryProps.setProperty("stringtype", "unspecified");
         queryProps.setProperty("bitToString", "true");
-        return queryProps;
+    }
+    
+    @Override
+    public void extendQueryProperties(final Properties props) {
+        queryProps.stringPropertyNames().forEach(each -> props.setProperty(each, queryProps.getProperty(each)));

Review Comment:
   Could we just use `props.putAll`?



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] sandynz merged pull request #26808: Refactor JdbcQueryPropertiesExtension

Posted by "sandynz (via GitHub)" <gi...@apache.org>.
sandynz merged PR #26808:
URL: https://github.com/apache/shardingsphere/pull/26808


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org