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 @@ -999,8 +999,11 @@ private[hive] object HiveClientImpl extends Logging {
// For Hive Serde, we still need to to restore the raw type for char and varchar type.
// When reading data in parquet, orc, or avro file format with string type for char,
// the tailing spaces may lost if we are not going to pad it.
val typeString = CharVarcharUtils.getRawTypeString(c.metadata)
.getOrElse(c.dataType.catalogString)
val typeString = if (SQLConf.get.charVarcharAsString) {
c.dataType.catalogString
} else {
CharVarcharUtils.getRawTypeString(c.metadata).getOrElse(c.dataType.catalogString)
}
new FieldSchema(c.name, typeString, c.getComment().orNull)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ class HiveCharVarcharTestSuite extends CharVarcharTestSuite with TestHiveSinglet
checkAnswer(sql("SELECT v from t where c = 'Spark' and v = 'kyuubi'"), Row("kyuubi"))
}
}

test("SPARK-36552: Fix different behavior of writing char/varchar to hive and datasource table") {
Seq("true", "false").foreach { v =>
withSQLConf(
"spark.sql.hive.convertMetastoreParquet" -> v,
"spark.sql.legacy.charVarcharAsString" -> "true") {
withTable("t") {
sql(s"CREATE TABLE t (c varchar(2)) USING $format")
sql("INSERT INTO t SELECT 'kyuubi'")
checkAnswer(sql("SELECT c from t"), Row("kyuubi"))
}
}
}
}
}

class HiveCharVarcharDDLTestSuite extends CharVarcharDDLTestBase with TestHiveSingleton {
Expand Down