Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 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 @@ -82,7 +82,8 @@ class CSVInferSchema(val options: CSVOptions) extends Serializable {
def inferRowType(rowSoFar: Array[DataType], next: Array[String]): Array[DataType] = {
var i = 0
while (i < math.min(rowSoFar.length, next.length)) { // May have columns on right missing.
rowSoFar(i) = inferField(rowSoFar(i), next(i))
val typeElemInfer = inferField(rowSoFar(i), next(i))
rowSoFar(i) = compatibleType(rowSoFar(i), typeElemInfer).getOrElse(StringType)
Comment thread
planga82 marked this conversation as resolved.
Outdated
i+=1
}
rowSoFar
Expand Down
4 changes: 4 additions & 0 deletions sql/core/src/test/resources/test-data/mixed-types1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
col_mixed_types
2012
1997
True
Comment thread
planga82 marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ abstract class CSVSuite extends QueryTest with SharedSparkSession with TestCsvDa
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 mixedTypes = "test-data/mixed-types1.csv"

/** Verifies data and schema. */
private def verifyCars(
Expand Down Expand Up @@ -2341,6 +2342,17 @@ abstract class CSVSuite extends QueryTest with SharedSparkSession with TestCsvDa
checkAnswer(csv, Row(null))
}
}

test("Test mixed types") {
Comment thread
planga82 marked this conversation as resolved.
Outdated
val data = spark
.read
.format("csv")
.option("header", "true")
.option("inferSchema", "true")
.load(testFile(mixedTypes))

assert(data.schema.fields.last == StructField("col_mixed_types", StringType, true))
}
}

class CSVv1Suite extends CSVSuite {
Expand Down