Skip to content

Commit 8a1d818

Browse files
ravipesalamarmbrus
authored andcommitted
[SQL] Backport backtick and smallint JDBC fixes to 1.1
Author: Michael Armbrust <[email protected]> Author: ravipesala <[email protected]> Author: scwf <[email protected]> Closes #3199 from marmbrus/backport1.1 and squashes the following commits: 019a0dd [Michael Armbrust] Drop incorrectly ported test cases 4c9f3e6 [ravipesala] [SPARK-3708][SQL] Backticks aren't handled correctly is aliases 064750d [scwf] [SPARK-3704][SQL] Fix ColumnValue type for Short values in thrift server f4e17cd [ravipesala] [SPARK-3834][SQL] Backticks not correctly handled in subquery aliases
1 parent 01d233e commit 8a1d818

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/server/SparkSQLOperationManager.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private[thriftserver] class SparkSQLOperationManager(hiveContext: HiveContext)
113113
case ByteType =>
114114
to.addColumnValue(ColumnValue.byteValue(from.getByte(ordinal)))
115115
case ShortType =>
116-
to.addColumnValue(ColumnValue.intValue(from.getShort(ordinal)))
116+
to.addColumnValue(ColumnValue.shortValue(from.getShort(ordinal)))
117117
case TimestampType =>
118118
to.addColumnValue(
119119
ColumnValue.timestampValue(from.get(ordinal).asInstanceOf[Timestamp]))
@@ -145,7 +145,7 @@ private[thriftserver] class SparkSQLOperationManager(hiveContext: HiveContext)
145145
case ByteType =>
146146
to.addColumnValue(ColumnValue.byteValue(null))
147147
case ShortType =>
148-
to.addColumnValue(ColumnValue.intValue(null))
148+
to.addColumnValue(ColumnValue.shortValue(null))
149149
case TimestampType =>
150150
to.addColumnValue(ColumnValue.timestampValue(null))
151151
case BinaryType | _: ArrayType | _: StructType | _: MapType =>

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ private[hive] object HiveQl {
658658
def nodeToRelation(node: Node): LogicalPlan = node match {
659659
case Token("TOK_SUBQUERY",
660660
query :: Token(alias, Nil) :: Nil) =>
661-
Subquery(alias, nodeToPlan(query))
661+
Subquery(cleanIdentifier(alias), nodeToPlan(query))
662662

663663
case Token(laterViewToken(isOuter), selectClause :: relationClause :: Nil) =>
664664
val Token("TOK_SELECT",
@@ -843,7 +843,7 @@ private[hive] object HiveQl {
843843

844844
case Token("TOK_SELEXPR",
845845
e :: Token(alias, Nil) :: Nil) =>
846-
Some(Alias(nodeToExpr(e), alias)())
846+
Some(Alias(nodeToExpr(e), cleanIdentifier(alias))())
847847

848848
/* Hints are ignored */
849849
case Token("TOK_HINTLIST", _) => None

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,24 @@ class SQLQuerySuite extends QueryTest {
3939
test("ordering not in agg") {
4040
checkAnswer(
4141
sql("SELECT key FROM src GROUP BY key, value ORDER BY value"),
42-
sql("""
42+
sql( """
4343
SELECT key
4444
FROM (
4545
SELECT key, value
4646
FROM src
4747
GROUP BY key, value
4848
ORDER BY value) a""").collect().toSeq)
4949
}
50+
51+
test("SPARK-3708 Backticks aren't handled correctly is aliases") {
52+
checkAnswer(
53+
sql("SELECT k FROM (SELECT `key` AS `k` FROM src) a"),
54+
sql("SELECT `key` FROM src").collect().toSeq)
55+
}
56+
57+
test("SPARK-3834 Backticks not correctly handled in subquery aliases") {
58+
checkAnswer(
59+
sql("SELECT a.key FROM (SELECT key FROM src) `a`"),
60+
sql("SELECT `key` FROM src").collect().toSeq)
61+
}
5062
}

0 commit comments

Comments
 (0)