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 @@ -118,7 +118,9 @@ abstract class LogicalPlan
def resolve(schema: StructType, resolver: Resolver): Seq[Attribute] = {
schema.map { field =>
resolve(field.name :: Nil, resolver).map {
case a: AttributeReference => a
case a: AttributeReference =>
// Keep the metadata in given schema.
a.withMetadata(field.metadata)
case _ => throw QueryExecutionErrors.resolveCannotHandleNestedSchema(this)
}.getOrElse {
throw QueryCompilationErrors.cannotResolveAttributeError(
Expand Down
4 changes: 4 additions & 0 deletions sql/core/src/test/resources/test-data/char.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
color,name
pink,Bob
blue,Mike
grey,Tom
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ abstract class CSVSuite
private val valueMalformedFile = "test-data/value-malformed.csv"
private val badAfterGoodFile = "test-data/bad_after_good.csv"
private val malformedRowFile = "test-data/malformedRow.csv"
private val charFile = "test-data/char.csv"

/** Verifies data and schema. */
private def verifyCars(
Expand Down Expand Up @@ -3342,6 +3343,29 @@ abstract class CSVSuite
expected)
}
}

test("SPARK-48241: CSV parsing failure with char/varchar type columns") {
withTable("charVarcharTable") {
spark.sql(
s"""
|CREATE TABLE charVarcharTable(
| color char(4),
| name varchar(10))
|USING csv
|OPTIONS (
| header "true",
| path "${testFile(charFile)}"
|)
""".stripMargin)
val expected = Seq(
Row("pink", "Bob"),
Row("blue", "Mike"),
Row("grey", "Tom"))
checkAnswer(
sql("SELECT * FROM charVarcharTable"),
expected)
}
}
}

class CSVv1Suite extends CSVSuite {
Expand Down