Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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,32 @@ 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 = {
LastOptions.parameters = parameters

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmmm, is it a convention to assign parameters to LastOptions? I think the test can work without it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, sure. Let me remove all these things. Thanks!

FakeRelation(sqlContext)
}

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

class DataFrameReaderWriterSuite extends QueryTest with SharedSQLContext with BeforeAndAfter {

Expand Down Expand Up @@ -120,6 +146,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