-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-3247][SQL] An API for adding data sources to Spark SQL #2475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0fd3a07
Draft of data sources API
marmbrus 2957875
add override
marmbrus 360cb30
style and java api
marmbrus de3b68c
Remove empty file
marmbrus 3e06776
remove line wraps
marmbrus 0d74bcf
Add documention on object life cycle
marmbrus 34f836a
Make @DeveloperApi
marmbrus b069146
traits => abstract classes
marmbrus 22963ef
package objects compile wierdly...
marmbrus 5031ac3
Merge remote-tracking branch 'origin/master' into foreign
marmbrus 5545491
Address comments
marmbrus 7d948ae
Fix equality of AttributeReference.
marmbrus 70da6d9
Modify API to ease binary compatibility and interop with Java
marmbrus a70d602
Fix style, more tests, FilteredSuite => PrunedFilteredSuite
marmbrus e3e690e
Add hook for extraStrategies
marmbrus fab154a
Merge remote-tracking branch 'origin/master' into foreign
marmbrus 5b47901
Remove sealed, more filter types
marmbrus 1d41bb5
unify argument names
marmbrus ab2c31f
fix test
marmbrus 1ed6010
Merge remote-tracking branch 'origin/master' into foreign
marmbrus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
sql/core/src/main/scala/org/apache/spark/sql/json/JSONRelation.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.json | ||
|
|
||
| import org.apache.spark.sql.SQLContext | ||
| import org.apache.spark.sql.sources._ | ||
|
|
||
| private[sql] class DefaultSource extends RelationProvider { | ||
| /** Returns a new base relation with the given parameters. */ | ||
| override def createRelation( | ||
| sqlContext: SQLContext, | ||
| parameters: Map[String, String]): BaseRelation = { | ||
| val fileName = parameters.getOrElse("path", sys.error("Option 'path' not specified")) | ||
| val samplingRatio = parameters.get("samplingRatio").map(_.toDouble).getOrElse(1.0) | ||
|
|
||
| JSONRelation(fileName, samplingRatio)(sqlContext) | ||
| } | ||
| } | ||
|
|
||
| private[sql] case class JSONRelation(fileName: String, samplingRatio: Double)( | ||
| @transient val sqlContext: SQLContext) | ||
| extends TableScan { | ||
|
|
||
| private def baseRDD = sqlContext.sparkContext.textFile(fileName) | ||
|
|
||
| override val schema = | ||
| JsonRDD.inferSchema( | ||
| baseRDD, | ||
| samplingRatio, | ||
| sqlContext.columnNameOfCorruptRecord) | ||
|
|
||
| override def buildScan() = | ||
| JsonRDD.jsonStringToRow(baseRDD, schema, sqlContext.columnNameOfCorruptRecord) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is part of an internal refactor that is started below. RunnableCommands will prevent the need for having two classes for every single command as well as a special handler in the query planner for each.
Its pretty big though so I decided to not finish it in this PR.