GitHub user gatorsmile opened a pull request:

    https://github.com/apache/spark/pull/13773

    [SPARK-16056] [SPARK-16057] [SPARK-16058] [SQL] Fix Multiple Bugs in Column 
Partitioning in JDBC Source 

    #### What changes were proposed in this pull request?
    This PR is to fix the following bugs:
    
    **Issue 1: Wrong Results when lowerBound is larger than upperBound in 
Column Partitioning**
    ```scala
    spark.read.jdbc(
      url = urlWithUserAndPass,
      table = "TEST.seq",
      columnName = "id",
      lowerBound = 4,
      upperBound = 0,
      numPartitions = 3,
      connectionProperties = new Properties)
    ```
    **Before code changes:**
    The generated partitions are wrong:
    ```
      Part 0 id < 3 or id is null
      Part 1 id >= 3 AND id < 2
      Part 2 id >= 2
    ```
    **After code changes:**
    Issue an `IllegalArgumentException` exception:
    ```
    Operation not allowed: the lower bound of partitioning column is larger 
than the upper bound. lowerBound: 5; higherBound: 1
    ```
    **Issue 2: numPartitions is More than the number of rows between upper and 
lower bounds**
    ```scala
    spark.read.jdbc(
      url = urlWithUserAndPass,
      table = "TEST.seq",
      columnName = "id",
      lowerBound = 1,
      upperBound = 5,
      numPartitions = 10,
      connectionProperties = new Properties)
    ```
    **Before code changes:**
    Generated partitions are like:
    ```
    Partition 0: id < 1 or id is null
    Partition 1: id >= 1 AND id < 1
    Partition 2: id >= 1 AND id < 1
    Partition 3: id >= 1 AND id < 1
    Partition 4: id >= 1 AND id < 1
    Partition 5: id >= 1 AND id < 1
    Partition 6: id >= 1 AND id < 1
    Partition 7: id >= 1 AND id < 1
    Partition 8: id >= 1 AND id < 1
    Partition 9: id >= 1
    ```
    **After code changes:**
    Adjust `numPartitions` and can return correct answers:
    ```
    Partition 0: id < 2 or id is null
    Partition 1: id >= 2 AND id < 3
    Partition 2: id >= 3 AND id < 4
    Partition 3: id >= 4
    ```
    **Issue 3: java.lang.ArithmeticException when numPartitions is zero**
    ```Scala
    spark.read.jdbc(
      url = urlWithUserAndPass,
      table = "TEST.seq",
      columnName = "id",
      lowerBound = 0,
      upperBound = 4,
      numPartitions = 0,
      connectionProperties = new Properties)
    ```
    **Before code changes:**
    Got the following exception:
    ```
      java.lang.ArithmeticException: / by zero
    ```
    **After code changes:**
    Return a right answer by disabling column partitioning
    
    #### How was this patch tested?
    Added test cases to verify the results

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/gatorsmile/spark jdbcPartitioning

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/13773.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #13773
    
----
commit 2198f5975a452daa8946ddb0bb084d826a448d54
Author: gatorsmile <[email protected]>
Date:   2016-06-19T17:00:45Z

    fix

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to