Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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 @@ -228,13 +228,4 @@ class OrcFileFormat

case _ => false
}

override def supportFieldName(name: String): Boolean = {
try {
TypeDescription.fromString(s"struct<`$name`:int>")
true
} catch {
case _: IllegalArgumentException => false
}
}
}
19 changes: 19 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4262,6 +4262,25 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession with AdaptiveSpark
Row(2, 4, 6, 8, 10, 12, 14, 16, 18, 20) :: Nil)
}
}

test("SPARK-37965: Spark support read/write orc file with invalid char in field name") {
withTempDir { dir =>
Seq((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), (2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22))
.toDF("max(t)", "max(t", "=", "\n", ";", "a b", "{", ".", "a.b", "a", ",")
.repartition(1)
.write.mode(SaveMode.Overwrite).orc(dir.getAbsolutePath)
val df = spark.read.orc(dir.getAbsolutePath)
checkAnswer(df,
Row(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) ::
Row(2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22) :: Nil)
assert(df.schema.names.sameElements(
Array("max(t)", "max(t", "=", "\n", ";", "a b", "{", ".", "a.b", "a", ",")))
checkAnswer(df.select("`max(t)`", "`a b`", "`{`", "`.`", "`a.b`"),
Row(1, 6, 7, 8, 9) :: Row(2, 12, 14, 16, 18) :: Nil)
checkAnswer(df.where("`a.b` > 10"),
Row(2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22) :: Nil)
}
}
}

case class Foo(bar: Option[String])
Original file line number Diff line number Diff line change
Expand Up @@ -2213,8 +2213,9 @@ abstract class SQLQuerySuiteBase extends QueryTest with SQLTestUtils with TestHi
}

test("SPARK-32889: ORC table column name supports special characters") {
// " " "," is not allowed.
Seq("$", ";", "{", "}", "(", ")", "\n", "\t", "=").foreach { name =>
// "," is not allowed since cannot create a table having a column whose name
// contains commas in Hive metastore.
Seq("$", ";", "{", "}", "(", ")", "\n", "\t", "=", " ", "a b").foreach { name =>
val source = "ORC"
Seq(s"CREATE TABLE t32889(`$name` INT) USING $source",
s"CREATE TABLE t32889 STORED AS $source AS SELECT 1 `$name`",
Expand Down