-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-18004][SQL] Make sure the date or timestamp related predicate can be pushed down to Oracle correctly #18451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
770bf9c
0d547d2
9808e63
8963b14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,9 @@ | |
|
|
||
| package org.apache.spark.sql.jdbc | ||
|
|
||
| import java.sql.Connection | ||
| import java.sql.{Connection, Date, Timestamp} | ||
|
|
||
| import org.apache.commons.lang3.StringUtils | ||
|
|
||
| import org.apache.spark.annotation.{DeveloperApi, InterfaceStability, Since} | ||
| import org.apache.spark.sql.types._ | ||
|
|
@@ -123,6 +125,29 @@ abstract class JdbcDialect extends Serializable { | |
| def beforeFetch(connection: Connection, properties: Map[String, String]): Unit = { | ||
| } | ||
|
|
||
| /** | ||
| * Escape special characters in SQL string literals. | ||
| * @param value The string to be escaped. | ||
| * @return Escaped string. | ||
| */ | ||
| @Since("2.3.0") | ||
| protected[jdbc] def escapeSql(value: String): String = | ||
| if (value == null) null else StringUtils.replace(value, "'", "''") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So far, it only covers single quotes. Actually, this is not complete. We need to improve it in the future PRs. If you have time, feel free to submit PRs.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am very glad to be involved! |
||
|
|
||
| /** | ||
| * Converts value to SQL expression. | ||
| * @param value The value to be converted. | ||
| * @return Converted value. | ||
| */ | ||
| @Since("2.3.0") | ||
| def compileValue(value: Any): Any = value match { | ||
| case stringValue: String => s"'${escapeSql(stringValue)}'" | ||
| case timestampValue: Timestamp => "'" + timestampValue + "'" | ||
| case dateValue: Date => "'" + dateValue + "'" | ||
| case arrayValue: Array[Any] => arrayValue.map(compileValue).mkString(", ") | ||
| case _ => value | ||
| } | ||
|
|
||
| /** | ||
| * Return Some[true] iff `TRUNCATE TABLE` causes cascading default. | ||
| * Some[true] : TRUNCATE TABLE causes cascading. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just want to confirm whether you run the docker test? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So sorry to reply so late. I added the docker test to confirm the date/timestamp-related predicates can be pushed down to Oracle and executed correctly. Before providing this patch , this kind of predicates can be pushed down to Oracle but can not be executed.