File tree Expand file tree Collapse file tree
core/src/main/scala/org/apache/spark/sql/execution/datasources/orc
hive/src/test/scala/org/apache/spark/sql/hive/execution Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,14 +38,19 @@ import org.apache.spark.sql.catalyst.InternalRow
3838import org .apache .spark .sql .catalyst .expressions ._
3939import org .apache .spark .sql .catalyst .expressions .codegen .GenerateUnsafeProjection
4040import org .apache .spark .sql .execution .datasources ._
41+ import org .apache .spark .sql .internal .SQLConf
4142import org .apache .spark .sql .sources ._
4243import org .apache .spark .sql .types ._
4344import org .apache .spark .util .{SerializableConfiguration , Utils }
4445
4546private [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 (
Original file line number Diff line number Diff 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 =
You can’t perform that action at this time.
0 commit comments