Skip to content

Commit 0a2cca7

Browse files
jzcjzc
authored andcommitted
orc table column name supports special characters.
1 parent 7a9b066 commit 0a2cca7

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/orc/OrcFileFormat.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,19 @@ import org.apache.spark.sql.catalyst.InternalRow
3838
import org.apache.spark.sql.catalyst.expressions._
3939
import org.apache.spark.sql.catalyst.expressions.codegen.GenerateUnsafeProjection
4040
import org.apache.spark.sql.execution.datasources._
41+
import org.apache.spark.sql.internal.SQLConf
4142
import org.apache.spark.sql.sources._
4243
import org.apache.spark.sql.types._
4344
import org.apache.spark.util.{SerializableConfiguration, Utils}
4445

4546
private[sql] object OrcFileFormat {
4647
private def checkFieldName(name: String): Unit = {
4748
try {
48-
TypeDescription.fromString(s"struct<$name:int>")
49+
if (SQLConf.get.getConfString("spark.sql.orc.column.allowSpecialChar", "false").toBoolean) {
50+
TypeDescription.fromString(s"struct<`$name`:int>")
51+
} else {
52+
TypeDescription.fromString(s"struct<$name:int>")
53+
}
4954
} catch {
5055
case _: IllegalArgumentException =>
5156
throw new AnalysisException(

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,6 +2242,29 @@ abstract class SQLQuerySuiteBase extends QueryTest with SQLTestUtils with TestHi
22422242
}
22432243
}
22442244

2245+
test("SPARK-32889 ORC table column name supports special characters like $ eg.") {
2246+
Seq("$").foreach { name =>
2247+
Seq("ORC").foreach { source =>
2248+
withSQLConf("spark.sql.orc.column.allowSpecialChar" -> "true") {
2249+
Seq(s"CREATE TABLE t32889(`col$name` INT) USING $source",
2250+
s"CREATE TABLE t32889 STORED AS $source AS SELECT 1 `col$name`",
2251+
s"CREATE TABLE t32889 USING $source AS SELECT 1 `col$name`",
2252+
s"CREATE TABLE t32889(`col$name` INT) USING hive OPTIONS (fileFormat '$source')")
2253+
.foreach { command =>
2254+
withTable("t32889") {
2255+
sql(command)
2256+
}
2257+
}
2258+
2259+
withTable("t32889") {
2260+
sql(s"CREATE TABLE t32889(`col` INT) USING $source")
2261+
sql(s"ALTER TABLE t32889 ADD COLUMNS(`col$name` INT)")
2262+
}
2263+
}
2264+
}
2265+
}
2266+
}
2267+
22452268
Seq("orc", "parquet").foreach { format =>
22462269
test(s"SPARK-18355 Read data from a hive table with a new column - $format") {
22472270
val client =

0 commit comments

Comments
 (0)