Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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 @@ -269,6 +269,13 @@ private[sql] class JDBCRDD(
case stringValue: String => s"'${escapeSql(stringValue)}'"
case timestampValue: Timestamp => "'" + timestampValue + "'"
case dateValue: Date => "'" + dateValue + "'"
case objectValue: Array[Object] => {
val str = objectValue.map {
case string: String => s"'${escapeSql(string)}'"
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Remove unnecessary space by referring other codes

case other => s"${escapeSql(other.toString)}"
}
str.mkString(",")
}
case _ => value
}

Expand All @@ -288,6 +295,12 @@ private[sql] class JDBCRDD(
case GreaterThanOrEqual(attr, value) => s"$attr >= ${compileValue(value)}"
case IsNull(attr) => s"$attr IS NULL"
case IsNotNull(attr) => s"$attr IS NOT NULL"
case In(attr, value) => s"$attr IN (${compileValue(value)})"
case Not(In(attr, value)) => s"$attr NOT IN (${compileValue(value)})"
Copy link
Member

Choose a reason for hiding this comment

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

ISTM we do not need this entry by calling compileFilter recursively.
Basically, we should take ParquetFilters#createFilter as an example implementation.

case Or(filter1, filter2) =>
"(" + compileFilter (filter1) + ") OR (" + compileFilter (filter2) + ")"
Copy link
Member

Choose a reason for hiding this comment

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

s"(${compileFilter(filter1)}) OR (${compileFilter(filter2)})" is better.

case And(filter1, filter2) =>
"(" + compileFilter (filter1) + ") AND (" + compileFilter (filter2) + ")"
Copy link
Member

Choose a reason for hiding this comment

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

The same fixes needed above.

case _ => null
}

Expand Down
12 changes: 12 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 @@ -184,6 +184,18 @@ class JDBCSuite extends SparkFunSuite with BeforeAndAfter with SharedSQLContext
assert(stripSparkFilter(sql("SELECT * FROM foobar WHERE NAME != 'fred'")).collect().size == 2)
assert(stripSparkFilter(sql("SELECT * FROM nulltypes WHERE A IS NULL")).collect().size == 1)
assert(stripSparkFilter(sql("SELECT * FROM nulltypes WHERE A IS NOT NULL")).collect().size == 0)
assert(stripSparkFilter(sql(
"SELECT * FROM foobar WHERE NAME IN ('mary', 'fred')")).collect().size === 2)
assert(stripSparkFilter(sql(
"SELECT * FROM foobar WHERE NAME NOT IN ('mary', 'fred')")).collect().size === 1)
assert(stripSparkFilter(sql(
"SELECT * FROM foobar WHERE THEID IN (1,3)")).collect().size === 2)
assert(stripSparkFilter(sql(
"SELECT * FROM foobar WHERE THEID NOT IN (1,3)")).collect().size === 1)
assert(stripSparkFilter(sql(
"SELECT * FROM foobar WHERE THEID=1 OR NAME = 'mary'")).collect().size === 2)
assert(stripSparkFilter(sql(
"SELECT * FROM foobar WHERE THEID = 1 OR NAME = 'mary' AND THEID = 2")).collect().size === 2)
}

test("SELECT * WHERE (quoted strings)") {
Expand Down