Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -38,14 +38,19 @@ import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.expressions.codegen.GenerateUnsafeProjection
import org.apache.spark.sql.execution.datasources._
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.sources._
import org.apache.spark.sql.types._
import org.apache.spark.util.{SerializableConfiguration, Utils}

private[sql] object OrcFileFormat {
private def checkFieldName(name: String): Unit = {
try {
TypeDescription.fromString(s"struct<$name:int>")
if (SQLConf.get.getConfString("spark.sql.orc.column.allowSpecialChar", "false").toBoolean) {
TypeDescription.fromString(s"struct<`$name`:int>")
} else {
TypeDescription.fromString(s"struct<$name:int>")
}
} catch {
case _: IllegalArgumentException =>
throw new AnalysisException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2242,6 +2242,29 @@ abstract class SQLQuerySuiteBase extends QueryTest with SQLTestUtils with TestHi
}
}

test("SPARK-32889 ORC table column name supports special characters like $ eg.") {
Seq("$").foreach { name =>
Seq("ORC").foreach { source =>
withSQLConf("spark.sql.orc.column.allowSpecialChar" -> "true") {
Seq(s"CREATE TABLE t32889(`col$name` INT) USING $source",
s"CREATE TABLE t32889 STORED AS $source AS SELECT 1 `col$name`",
s"CREATE TABLE t32889 USING $source AS SELECT 1 `col$name`",
s"CREATE TABLE t32889(`col$name` INT) USING hive OPTIONS (fileFormat '$source')")
.foreach { command =>
withTable("t32889") {
sql(command)
}
}

withTable("t32889") {
sql(s"CREATE TABLE t32889(`col` INT) USING $source")
sql(s"ALTER TABLE t32889 ADD COLUMNS(`col$name` INT)")
}
}
}
}
}

Seq("orc", "parquet").foreach { format =>
test(s"SPARK-18355 Read data from a hive table with a new column - $format") {
val client =
Expand Down