Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -64,7 +64,8 @@ private[sql] object JDBCRelation extends Logging {
s"bound. Lower bound: $lowerBound; Upper bound: $upperBound")

val numPartitions =
if ((upperBound - lowerBound) >= partitioning.numPartitions) {
if ((upperBound - lowerBound) >= partitioning.numPartitions ||
(upperBound - lowerBound) < 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Looks good. for bonus points, add a comment about what this is for, and indent this line two more spaces

partitioning.numPartitions
} else {
logWarning("The number of partitions is reduced because the specified number of " +
Expand Down
16 changes: 16 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ class JDBCSuite extends SparkFunSuite
| partitionColumn 'THEID', lowerBound '1', upperBound '4', numPartitions '3')
""".stripMargin.replaceAll("\n", " "))

sql(
s"""
|CREATE OR REPLACE TEMPORARY VIEW partsoverflow
|USING org.apache.spark.sql.jdbc
|OPTIONS (url '$url', dbtable 'TEST.PEOPLE', user 'testUser', password 'testPass',
| partitionColumn 'THEID', lowerBound '-9223372036854775808',
| upperBound '9223372036854775807', numPartitions '3')
""".stripMargin.replaceAll("\n", " "))

conn.prepareStatement("create table test.inttypes (a INT, b BOOLEAN, c TINYINT, "
+ "d SMALLINT, e BIGINT)").executeUpdate()
conn.prepareStatement("insert into test.inttypes values (1, false, 3, 4, 1234567890123)"
Expand Down Expand Up @@ -376,6 +385,13 @@ class JDBCSuite extends SparkFunSuite
assert(ids(2) === 3)
}

test("overflow of partition bound difference does not give negative stride") {
val df = sql("SELECT * FROM partsoverflow")
checkNumPartitions(df, expectedNumPartitions = 3)
assert(df.collect().length == 3)

Copy link
Member

Choose a reason for hiding this comment

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

And maybe delete this blank for tidiness

}

test("Register JDBC query with renamed fields") {
// Regression test for bug SPARK-7345
sql(
Expand Down