-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-19152][SQL]DataFrameWriter.saveAsTable support hive append #16552
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
25b39fa
[WIP][SPARK-19152][SQL]DataFrameWriter.saveAsTable support hive append
windpiger b463ac7
fix type mismatch
windpiger 29e1ee2
merge with mater, and add a testcase
windpiger 429a0ab
remove a empty line
windpiger 21c5e3f
fix test failed
windpiger 2bf67c7
modify the append logic
windpiger 6b8f625
modify the append logic
windpiger 1145e52
fix a tc failed
windpiger 0b9dc3a
merge with master to fix conflict
windpiger 2f542ff
fix test failed
windpiger cb7a1be
Merge branch 'master' into saveAsTableWithHiveAppend
windpiger 7186938
merge with master and register hive as a datasource
windpiger b167b51
remove a comment
windpiger d3c81d4
remove a empty line
windpiger 6c09477
modify constructor
windpiger 98ec55a
fix tc failed
windpiger f34ab6d
fix some logic for unsupported hive datasource
windpiger 722ad76
fix some review comment
windpiger 7bf5b50
fix a tc
windpiger 59db8e4
fix a comment
windpiger 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
1 change: 1 addition & 0 deletions
1
...hive/src/main/resources/META-INF/services/org.apache.spark.sql.sources.DataSourceRegister
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
org.apache.spark.sql.hive.orc.OrcFileFormat | ||
org.apache.spark.sql.hive.execution.HiveFileFormat | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ package org.apache.spark.sql.hive.execution | |
|
||
import scala.util.control.NonFatal | ||
|
||
import org.apache.spark.sql.{AnalysisException, Row, SparkSession} | ||
import org.apache.spark.sql.{AnalysisException, Row, SaveMode, SparkSession} | ||
import org.apache.spark.sql.catalyst.catalog.{CatalogTable, SimpleCatalogRelation} | ||
import org.apache.spark.sql.catalyst.plans.logical.{InsertIntoTable, LogicalPlan, SubqueryAlias} | ||
import org.apache.spark.sql.execution.command.RunnableCommand | ||
|
@@ -31,13 +31,12 @@ import org.apache.spark.sql.hive.MetastoreRelation | |
* | ||
* @param tableDesc the Table Describe, which may contains serde, storage handler etc. | ||
* @param query the query whose result will be insert into the new relation | ||
* @param ignoreIfExists allow continue working if it's already exists, otherwise | ||
* raise exception | ||
* @param mode SaveMode | ||
*/ | ||
case class CreateHiveTableAsSelectCommand( | ||
tableDesc: CatalogTable, | ||
query: LogicalPlan, | ||
ignoreIfExists: Boolean) | ||
mode: SaveMode) | ||
extends RunnableCommand { | ||
|
||
private val tableIdentifier = tableDesc.identifier | ||
|
@@ -67,7 +66,7 @@ case class CreateHiveTableAsSelectCommand( | |
withFormat | ||
} | ||
|
||
sparkSession.sessionState.catalog.createTable(withSchema, ignoreIfExists = false) | ||
sparkSession.sessionState.catalog.createTable(withSchema, ignoreIfExists = true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like we don't need to build |
||
|
||
// Get the Metastore Relation | ||
sparkSession.sessionState.catalog.lookupRelation(tableIdentifier) match { | ||
|
@@ -80,11 +79,18 @@ case class CreateHiveTableAsSelectCommand( | |
// add the relation into catalog, just in case of failure occurs while data | ||
// processing. | ||
if (sparkSession.sessionState.catalog.tableExists(tableIdentifier)) { | ||
if (ignoreIfExists) { | ||
// table already exists, will do nothing, to keep consistent with Hive | ||
} else { | ||
assert(mode != SaveMode.Overwrite, | ||
s"Expect the table $tableIdentifier has been dropped when the save mode is Overwrite") | ||
|
||
if (mode == SaveMode.ErrorIfExists) { | ||
throw new AnalysisException(s"$tableIdentifier already exists.") | ||
} | ||
if (mode == SaveMode.Ignore) { | ||
// Since the table already exists and the save mode is Ignore, we will just return. | ||
return Seq.empty | ||
} | ||
sparkSession.sessionState.executePlan(InsertIntoTable( | ||
metastoreRelation, Map(), query, overwrite = false, ifNotExists = false)).toRdd | ||
} else { | ||
try { | ||
sparkSession.sessionState.executePlan(InsertIntoTable( | ||
|
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
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.
is this auto-generated?