aboutsummaryrefslogtreecommitdiff
path: root/sql/catalyst/src/main/scala/org/apache
diff options
context:
space:
mode:
authorJosh Rosen <joshrosen@databricks.com>2016-08-23 22:31:58 +0200
committerHerman van Hovell <hvanhovell@databricks.com>2016-08-23 22:31:58 +0200
commitbf8ff833e30b39e5e5e35ba8dcac31b79323838c (patch)
tree976722854fb5da1fde0d485587ebb7e8cf31fb66 /sql/catalyst/src/main/scala/org/apache
parent6555ef0ccbecd09c3071670e10f0c1e2d7713bfe (diff)
downloadspark-bf8ff833e30b39e5e5e35ba8dcac31b79323838c.tar.gz
spark-bf8ff833e30b39e5e5e35ba8dcac31b79323838c.tar.bz2
spark-bf8ff833e30b39e5e5e35ba8dcac31b79323838c.zip
[SPARK-17194] Use single quotes when generating SQL for string literals
When Spark emits SQL for a string literal, it should wrap the string in single quotes, not double quotes. Databases which adhere more strictly to the ANSI SQL standards, such as Postgres, allow only single-quotes to be used for denoting string literals (see http://stackoverflow.com/a/1992331/590203). Author: Josh Rosen <joshrosen@databricks.com> Closes #14763 from JoshRosen/SPARK-17194.
Diffstat (limited to 'sql/catalyst/src/main/scala/org/apache')
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala4
1 files changed, 2 insertions, 2 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala
index 7040008769..55fd9c0834 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala
@@ -245,8 +245,8 @@ case class Literal (value: Any, dataType: DataType) extends LeafExpression with
case (_, NullType | _: ArrayType | _: MapType | _: StructType) if value == null => "NULL"
case _ if value == null => s"CAST(NULL AS ${dataType.sql})"
case (v: UTF8String, StringType) =>
- // Escapes all backslashes and double quotes.
- "\"" + v.toString.replace("\\", "\\\\").replace("\"", "\\\"") + "\""
+ // Escapes all backslashes and single quotes.
+ "'" + v.toString.replace("\\", "\\\\").replace("'", "\\'") + "'"
case (v: Byte, ByteType) => v + "Y"
case (v: Short, ShortType) => v + "S"
case (v: Long, LongType) => v + "L"