You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/03/01 10:10:07 UTC

[GitHub] [spark] beliefer opened a new pull request #35696: [SPARK-38361][SQL] Factory method getConnection should take Partition as optional parameter.

beliefer opened a new pull request #35696:
URL: https://github.com/apache/spark/pull/35696


   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] pan3793 edited a comment on pull request #35696: [SPARK-38361][SQL] Factory method getConnection should take Partition as optional parameter.

Posted by GitBox <gi...@apache.org>.
pan3793 edited a comment on pull request #35696:
URL: https://github.com/apache/spark/pull/35696#issuecomment-1056221700


   @srowen Let me give some background how clickhouse shard works.
   
   The concept `distributed table` in clickhouse is something like "remote view", which is a logical union of `local table`s from all cluster nodes. Generally, all of nods has the same `distributed table`.
   
   When SQL `select * from distribute_table` summit to one clickhouse node, it will collect recrods from all nodes and send back to JDBC client. Pass partition infomation to JDBC Driver, then the driver can leverage it to determine which node(shard) has the best data locality, it can significant reduce the network traffic.


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] srowen commented on pull request #35696: [SPARK-38361][SQL] Factory method getConnection should take Partition as optional parameter.

Posted by GitBox <gi...@apache.org>.
srowen commented on pull request #35696:
URL: https://github.com/apache/spark/pull/35696#issuecomment-1056123928


   OK, but why is a connection specific to a shard, if the entire database is specific to a shard, or, can query data across shards anyway?


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] beliefer commented on a change in pull request #35696: [SPARK-38361][SQL] Factory method getConnection should take Partition as optional parameter.

Posted by GitBox <gi...@apache.org>.
beliefer commented on a change in pull request #35696:
URL: https://github.com/apache/spark/pull/35696#discussion_r817402419



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
##########
@@ -60,9 +60,9 @@ object JdbcUtils extends Logging with SQLConfHelper {
    * @param options - JDBC options that contains url, table and other information.
    * @throws IllegalArgumentException if the driver could not open a JDBC connection.
    */
-  def createConnectionFactory(options: JDBCOptions): () => Connection = {
+  def createConnectionFactory(options: JDBCOptions): Option[Partition] => Connection = {

Review comment:
       We get the jdbc connection looks like:
   ```
   private def createConnectionFactoryByShard(options: JDBCOptions): Partition => Connection = {
       val shards = ShardOptions.create(options)
       val driverClass: String = options.driverClass
       (thePart: Partition) => {
         require(thePart.index < shards.shards.length)
         val url = shards.shards.apply(thePart.index)
         logInfo(s"Create connection for shard: $url")
         DriverRegistry.register(driverClass)
         val driver: Driver = DriverManager.getDrivers.asScala.collectFirst {
           case d: DriverWrapper if d.wrapped.getClass.getCanonicalName == driverClass => d
           case d if d.getClass.getCanonicalName == driverClass => d
         }.getOrElse {
           throw new IllegalStateException(
             s"Did not find registered driver with class $driverClass")
         }
         driver.connect(url, options.asConnectionProperties)
       }
     }
   ```




-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] srowen commented on pull request #35696: [SPARK-38361][SQL] Factory method getConnection should take Partition as optional parameter.

Posted by GitBox <gi...@apache.org>.
srowen commented on pull request #35696:
URL: https://github.com/apache/spark/pull/35696#issuecomment-1055495878


   This isn't used in Spark though ... what's the use case? isn't your 'database' just a shard of a database in this case, so would be specified in a connection string or something?


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] beliefer commented on pull request #35696: [SPARK-38361][SQL] Factory method getConnection should take Partition as optional parameter.

Posted by GitBox <gi...@apache.org>.
beliefer commented on pull request #35696:
URL: https://github.com/apache/spark/pull/35696#issuecomment-1056281143


   > @srowen Let me give some background how clickhouse shard works.
   > 
   > The concept `distributed table` in clickhouse is something like "remote view", which is a logical union of `local table`s from all cluster nodes. Generally, all of nods has the same `distributed table`.
   > 
   > When submit SQL `select * from distribute_table` to one clickhouse node, it will collect recrods from all nodes and send back to JDBC client. Pass partition infomation to JDBC Driver, then the driver can leverage it to determine which node(shard) has the best data locality, it can significantly reduce the network traffic.
   
   Thank you for the explanation.


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] pan3793 commented on pull request #35696: [SPARK-38361][SQL] Factory method getConnection should take Partition as optional parameter.

Posted by GitBox <gi...@apache.org>.
pan3793 commented on pull request #35696:
URL: https://github.com/apache/spark/pull/35696#issuecomment-1056221700


   @srowen Let me give some background if how clickhouse shard works.
   
   The concept `distributed table` in clickhouse is something like "remote view", which is a logical union of `local table`s from all cluster nodes. Generally, all of nods has the same `distributed table`.
   
   When SQL `select * from distribute_table` summit to one clickhouse node, it will collect recrods from all nodes and send back to JDBC client. Pass partition infomation to JDBC Driver, then the driver can leverage it to determine which node(shard) has the best data locality, it can significant reduce the network traffic.


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] beliefer commented on pull request #35696: [SPARK-38361][SQL] Factory method getConnection should take Partition as optional parameter.

Posted by GitBox <gi...@apache.org>.
beliefer commented on pull request #35696:
URL: https://github.com/apache/spark/pull/35696#issuecomment-1056060523


   > This isn't used in Spark though ... what's the use case? isn't your 'database' just a shard of a database in this case, so would be specified in a connection string or something?
   
   ClickHouse have more than one shard. Each shard node has a own's jdbc url. Shard partition is a real partition could tell me which jdbc url should be used. The current JDBCRDD has a factory method `getConnection: () => Connection` which difficult tell me which partition or shard is.


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a change in pull request #35696: [SPARK-38361][SQL] Factory method getConnection should take Partition as optional parameter.

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #35696:
URL: https://github.com/apache/spark/pull/35696#discussion_r817377155



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
##########
@@ -60,9 +60,9 @@ object JdbcUtils extends Logging with SQLConfHelper {
    * @param options - JDBC options that contains url, table and other information.
    * @throws IllegalArgumentException if the driver could not open a JDBC connection.
    */
-  def createConnectionFactory(options: JDBCOptions): () => Connection = {
+  def createConnectionFactory(options: JDBCOptions): Option[Partition] => Connection = {

Review comment:
       how do you overwrite this in your clickhouse data source?




-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] beliefer commented on pull request #35696: [SPARK-38361][SQL] Factory method getConnection should take Partition as optional parameter.

Posted by GitBox <gi...@apache.org>.
beliefer commented on pull request #35696:
URL: https://github.com/apache/spark/pull/35696#issuecomment-1058773907


   https://github.com/apache/spark/pull/35727 used to replace this PR.


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] beliefer closed pull request #35696: [SPARK-38361][SQL] Factory method getConnection should take Partition as optional parameter.

Posted by GitBox <gi...@apache.org>.
beliefer closed pull request #35696:
URL: https://github.com/apache/spark/pull/35696


   


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] srowen commented on pull request #35696: [SPARK-38361][SQL] Factory method getConnection should take Partition as optional parameter.

Posted by GitBox <gi...@apache.org>.
srowen commented on pull request #35696:
URL: https://github.com/apache/spark/pull/35696#issuecomment-1056068111


   If the JDBC connection is already to one shard, then why does anything else have to select a shard?


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] pan3793 edited a comment on pull request #35696: [SPARK-38361][SQL] Factory method getConnection should take Partition as optional parameter.

Posted by GitBox <gi...@apache.org>.
pan3793 edited a comment on pull request #35696:
URL: https://github.com/apache/spark/pull/35696#issuecomment-1056221700


   @srowen Let me give some background how clickhouse shard works.
   
   The concept `distributed table` in clickhouse is something like "remote view", which is a logical union of `local table`s from all cluster nodes. Generally, all of nods has the same `distributed table`.
   
   When submit SQL `select * from distribute_table` to one clickhouse node, it will collect recrods from all nodes and send back to JDBC client. Pass partition infomation to JDBC Driver, then the driver can leverage it to determine which node(shard) has the best data locality, it can significant reduce the network traffic.


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] beliefer commented on pull request #35696: [SPARK-38361][SQL] Factory method getConnection should take Partition as optional parameter.

Posted by GitBox <gi...@apache.org>.
beliefer commented on pull request #35696:
URL: https://github.com/apache/spark/pull/35696#issuecomment-1055367060


   ping @huaxingao cc @cloud-fan 


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on pull request #35696: [SPARK-38361][SQL] Factory method getConnection should take Partition as optional parameter.

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #35696:
URL: https://github.com/apache/spark/pull/35696#issuecomment-1058060107


   I agree with the requirement that some JDBC dialects may want to customize the connection creation logic, shall we put this in the dialect API then?


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] beliefer commented on pull request #35696: [SPARK-38361][SQL] Factory method getConnection should take Partition as optional parameter.

Posted by GitBox <gi...@apache.org>.
beliefer commented on pull request #35696:
URL: https://github.com/apache/spark/pull/35696#issuecomment-1056084990


   > If the JDBC connection is already to one shard, then why does anything else have to select a shard?
   
   For example, select data from a table distributed across multiple shard nodes.


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] pan3793 edited a comment on pull request #35696: [SPARK-38361][SQL] Factory method getConnection should take Partition as optional parameter.

Posted by GitBox <gi...@apache.org>.
pan3793 edited a comment on pull request #35696:
URL: https://github.com/apache/spark/pull/35696#issuecomment-1056221700


   @srowen Let me give some background how clickhouse shard works.
   
   The concept `distributed table` in clickhouse is something like "remote view", which is a logical union of `local table`s from all cluster nodes. Generally, all of nods has the same `distributed table`.
   
   When submit SQL `select * from distribute_table` to one clickhouse node, it will collect recrods from all nodes and send back to JDBC client. Pass partition infomation to JDBC Driver, then the driver can leverage it to determine which node(shard) has the best data locality, it can significantly reduce the network traffic.


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] beliefer commented on pull request #35696: [SPARK-38361][SQL] Factory method getConnection should take Partition as optional parameter.

Posted by GitBox <gi...@apache.org>.
beliefer commented on pull request #35696:
URL: https://github.com/apache/spark/pull/35696#issuecomment-1058073476


   > I agree with the requirement that some JDBC dialects may want to customize the connection creation logic, shall we put this in the dialect API then?
   
   Good idea.


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a change in pull request #35696: [SPARK-38361][SQL] Factory method getConnection should take Partition as optional parameter.

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #35696:
URL: https://github.com/apache/spark/pull/35696#discussion_r817377438



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
##########
@@ -60,9 +60,9 @@ object JdbcUtils extends Logging with SQLConfHelper {
    * @param options - JDBC options that contains url, table and other information.
    * @throws IllegalArgumentException if the driver could not open a JDBC connection.
    */
-  def createConnectionFactory(options: JDBCOptions): () => Connection = {
+  def createConnectionFactory(options: JDBCOptions): Option[Partition] => Connection = {

Review comment:
       Seems like Spark does not allow JDBC dialects to customize the connection creation yet.




-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org