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 @@ -485,12 +485,11 @@ case class DataSource(
data.logicalPlan,
mode)
sparkSession.sessionState.executePlan(plan).toRdd
// Replace the schema with that of the DataFrame we just wrote out to avoid re-inferring it.
copy(userSpecifiedSchema = Some(data.schema.asNullable)).resolveRelation()

case _ =>
sys.error(s"${providingClass.getCanonicalName} does not allow create table as select.")
}

// We replace the schema with that of the DataFrame we just wrote out to avoid re-inferring it.
copy(userSpecifiedSchema = Some(data.schema.asNullable)).resolveRelation()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,29 @@ class DefaultSource
}
}

/** Dummy provider with only RelationProvider and CreatableRelationProvider. */
class DefaultSourceWithoutUserSpecifiedSchema
extends RelationProvider
with CreatableRelationProvider {

case class FakeRelation(sqlContext: SQLContext) extends BaseRelation {
override def schema: StructType = StructType(Seq(StructField("a", StringType)))
}

override def createRelation(
sqlContext: SQLContext,
parameters: Map[String, String]): BaseRelation = {
FakeRelation(sqlContext)
}

override def createRelation(
sqlContext: SQLContext,
mode: SaveMode,
parameters: Map[String, String],
data: DataFrame): BaseRelation = {
FakeRelation(sqlContext)
}
}

class DataFrameReaderWriterSuite extends QueryTest with SharedSQLContext with BeforeAndAfter {

Expand Down Expand Up @@ -120,6 +143,15 @@ class DataFrameReaderWriterSuite extends QueryTest with SharedSQLContext with Be
.save()
}

test("resolve default source without extending SchemaRelationProvider") {
spark.read
.format("org.apache.spark.sql.test.DefaultSourceWithoutUserSpecifiedSchema")
.load()
.write
.format("org.apache.spark.sql.test.DefaultSourceWithoutUserSpecifiedSchema")
.save()
}

test("resolve full class") {
spark.read
.format("org.apache.spark.sql.test.DefaultSource")
Expand Down