-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-34377][SQL] Add new parquet datasource options to control datetime rebasing in read #31489
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
14 commits
Select commit
Hold shift + click to select a range
984d9ea
Add parquet options names.
MaxGekk 2b6bf15
Add functions to ParquetOptions
MaxGekk 83eb2d8
Merge remote-tracking branch 'origin/master' into parquet-rebase-options
MaxGekk 1f8d429
Test options
MaxGekk bf2b77e
Support options in v1
MaxGekk db16d69
Support options in v2
MaxGekk 1bb9980
Fix imports
MaxGekk 018b171
Minor
MaxGekk 34f88de
typo
MaxGekk f898288
Fix test
MaxGekk eb77fc6
Update docs
MaxGekk f33b5a8
Trigger build
MaxGekk ae8288c
Merge remote-tracking branch 'origin/master' into parquet-rebase-options
MaxGekk ebc7298
Document the default values
MaxGekk 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,8 +24,8 @@ import org.apache.spark.{SparkConf, SparkException, SparkUpgradeException} | |
| import org.apache.spark.sql.{QueryTest, Row, SPARK_LEGACY_DATETIME, SPARK_LEGACY_INT96} | ||
| import org.apache.spark.sql.catalyst.util.DateTimeTestUtils | ||
| import org.apache.spark.sql.internal.SQLConf | ||
| import org.apache.spark.sql.internal.SQLConf.{LegacyBehaviorPolicy, ParquetOutputTimestampType} | ||
| import org.apache.spark.sql.internal.SQLConf.LegacyBehaviorPolicy.{CORRECTED, EXCEPTION, LEGACY} | ||
| import org.apache.spark.sql.internal.SQLConf.ParquetOutputTimestampType | ||
| import org.apache.spark.sql.test.SharedSparkSession | ||
|
|
||
| abstract class ParquetRebaseDatetimeSuite | ||
|
|
@@ -97,6 +97,27 @@ abstract class ParquetRebaseDatetimeSuite | |
| } | ||
| } | ||
|
|
||
| private def inReadConfToOptions( | ||
| conf: String, | ||
| mode: LegacyBehaviorPolicy.Value): Map[String, String] = conf match { | ||
| case SQLConf.LEGACY_PARQUET_INT96_REBASE_MODE_IN_READ.key => | ||
| Map(ParquetOptions.INT96_REBASE_MODE -> mode.toString) | ||
| case _ => Map(ParquetOptions.DATETIME_REBASE_MODE -> mode.toString) | ||
| } | ||
|
|
||
| private def runInMode( | ||
| conf: String, | ||
| modes: Seq[LegacyBehaviorPolicy.Value])(f: Map[String, String] => Unit): Unit = { | ||
| modes.foreach { mode => | ||
| withSQLConf(conf -> mode.toString) { f(Map.empty) } | ||
| } | ||
| withSQLConf(conf -> EXCEPTION.toString) { | ||
| modes.foreach { mode => | ||
| f(inReadConfToOptions(conf, mode)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-31159: compatibility with Spark 2.4 in reading dates/timestamps") { | ||
| val N = 8 | ||
| // test reading the existing 2.4 files and new 3.0 files (with rebase on/off) together. | ||
|
|
@@ -132,9 +153,9 @@ abstract class ParquetRebaseDatetimeSuite | |
| } | ||
| // For Parquet files written by Spark 3.0, we know the writer info and don't need the | ||
| // config to guide the rebase behavior. | ||
| withSQLConf(inReadConf -> LEGACY.toString) { | ||
| runInMode(inReadConf, Seq(LEGACY)) { options => | ||
| checkAnswer( | ||
| spark.read.format("parquet").load(path2_4, path3_0, path3_0_rebase), | ||
| spark.read.format("parquet").options(options).load(path2_4, path3_0, path3_0_rebase), | ||
| (0 until N).flatMap { i => | ||
| val (dictS, plainS) = rowFunc(i) | ||
| Seq.tabulate(3) { _ => | ||
|
|
@@ -235,12 +256,10 @@ abstract class ParquetRebaseDatetimeSuite | |
| withAllParquetReaders { | ||
| // The file metadata indicates if it needs rebase or not, so we can always get the | ||
| // correct result regardless of the "rebase mode" config. | ||
| Seq(LEGACY, CORRECTED, EXCEPTION).foreach { mode => | ||
| withSQLConf(inReadConf -> mode.toString) { | ||
| checkAnswer( | ||
| spark.read.parquet(path), | ||
| Seq.tabulate(N)(_ => Row(Timestamp.valueOf(tsStr)))) | ||
| } | ||
| runInMode(inReadConf, Seq(LEGACY, CORRECTED, EXCEPTION)) { options => | ||
| checkAnswer( | ||
| spark.read.options(options).parquet(path), | ||
| Seq.tabulate(N)(_ => Row(Timestamp.valueOf(tsStr)))) | ||
| } | ||
|
|
||
| // Force to not rebase to prove the written datetime values are rebased | ||
|
|
@@ -275,12 +294,12 @@ abstract class ParquetRebaseDatetimeSuite | |
| withAllParquetReaders { | ||
| // The file metadata indicates if it needs rebase or not, so we can always get the | ||
| // correct result regardless of the "rebase mode" config. | ||
| Seq(LEGACY, CORRECTED, EXCEPTION).foreach { mode => | ||
| withSQLConf(SQLConf.LEGACY_AVRO_REBASE_MODE_IN_READ.key -> mode.toString) { | ||
|
Member
Author
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. Fixed the wrong SQL conf: LEGACY_AVRO_REBASE_MODE_IN_READ |
||
| checkAnswer( | ||
| spark.read.parquet(path), | ||
| Seq.tabulate(N)(_ => Row(Date.valueOf("1001-01-01")))) | ||
| } | ||
| runInMode( | ||
| SQLConf.LEGACY_PARQUET_REBASE_MODE_IN_READ.key, | ||
| Seq(LEGACY, CORRECTED, EXCEPTION)) { options => | ||
| checkAnswer( | ||
| spark.read.options(options).parquet(path), | ||
| Seq.tabulate(N)(_ => Row(Date.valueOf("1001-01-01")))) | ||
| } | ||
|
|
||
| // Force to not rebase to prove the written datetime values are rebased and we will get | ||
|
|
||
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.
Does it really work? The 2 fields of
ParquetOptionsaretransient, and become null after (de)serialization.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.
ah nvm, we read the confs and put it in
val.