GitHub user gatorsmile opened a pull request:
https://github.com/apache/spark/pull/15046
[SPARK-17492] [SQL] Fix Reading Cataloged Data Sources without Extending
SchemaRelationProvider
### What changes were proposed in this pull request?
For data sources without extending `SchemaRelationProvider`, we expect
users to not specify schemas when they creating tables. If the schema is input
from users, an exception is issued.
Since Spark 2.1, for any data source, to avoid infer the schema every time,
we store the schema in the metastore catalog. Thus, when reading a cataloged
data source table, the schema could be read from metastore catalog. In this
case, we also got an exception. For example,
```Scala
sql(
s"""
|CREATE TABLE relationProvierWithSchema
|USING org.apache.spark.sql.sources.SimpleScanSource
|OPTIONS (
| From '1',
| To '10'
|)
""".stripMargin)
spark.table(tableName).show()
```
```
org.apache.spark.sql.sources.SimpleScanSource does not allow user-specified
schemas.;
```
This PR is to fix the above issue. When building a data source, we
introduce a flag `isSchemaFromUsers` to indicate whether the schema is really
input from users. If true, we issue an exception. Otherwise, we will call the
`createRelation` of `RelationProvider` to generate the `BaseRelation`, in which
it contains the actual schema.
### How was this patch tested?
Added a few cases.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/gatorsmile/spark tempViewCases
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/15046.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #15046
----
commit 17c2d50c9d4788aaa68f7f57fc873762940a8e9d
Author: gatorsmile <[email protected]>
Date: 2016-09-10T15:31:26Z
fix
commit 00a49fe60f86775e19f038791a766195d506087a
Author: gatorsmile <[email protected]>
Date: 2016-09-10T15:41:18Z
clean
commit 335e0d6d5a19b30ec000db8d935869e006dd81e7
Author: gatorsmile <[email protected]>
Date: 2016-09-10T15:42:11Z
clean
commit 4ab1b8a45c9a8b9ed1f7ee85202eddf397235df4
Author: gatorsmile <[email protected]>
Date: 2016-09-10T16:12:26Z
add one more test case
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]