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 @@ -343,7 +343,12 @@ case class DataSource(
val baseRelation =
dataSource.createRelation(sparkSession.sqlContext, caseInsensitiveOptions)
if (baseRelation.schema != schema) {
throw new AnalysisException(s"$className does not allow user-specified schemas.")
throw new AnalysisException(
"The user-specified schema doesn't match the actual schema: " +
s"user-specified: ${schema.toDDL}, actual: ${baseRelation.schema.toDDL}. If " +
"you're using DataFrameReader.schema API or creating a table, please do not " +
"specify the schema. Or if you're scanning an existed table, please drop " +
"it and re-create it.")
}
baseRelation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class TableScanSuite extends DataSourceTest with SharedSparkSession {
// Make sure we do throw correct exception when users use a relation provider that
// only implements the RelationProvider or the SchemaRelationProvider.
Seq("TEMPORARY VIEW", "TABLE").foreach { tableType =>
val schemaNotAllowed = intercept[Exception] {
val schemaNotMatch = intercept[Exception] {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the variable name to make it be more readable according to current error message.

sql(
s"""
|CREATE $tableType relationProvierWithSchema (i int)
Expand All @@ -369,7 +369,8 @@ class TableScanSuite extends DataSourceTest with SharedSparkSession {
|)
""".stripMargin)
}
assert(schemaNotAllowed.getMessage.contains("does not allow user-specified schemas"))
assert(schemaNotMatch.getMessage.contains(
"The user-specified schema doesn't match the actual schema"))

val schemaNeeded = intercept[Exception] {
sql(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,11 +489,10 @@ class DataFrameReaderWriterSuite extends QueryTest with SharedSparkSession with
// when users do not specify the schema
checkAnswer(dfReader.load(), spark.range(1, 11).toDF())

// when users specify the schema
// when users specify a wrong schema
val inputSchema = new StructType().add("s", IntegerType, nullable = false)
val e = intercept[AnalysisException] { dfReader.schema(inputSchema).load() }
assert(e.getMessage.contains(
"org.apache.spark.sql.sources.SimpleScanSource does not allow user-specified schemas"))
assert(e.getMessage.contains("The user-specified schema doesn't match the actual schema"))
}

test("read a data source that does not extend RelationProvider") {
Expand Down