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.
Branch 2.2 #19070
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
Uh oh!
There was an error while loading. Please reload this page.
Branch 2.2 #19070
Changes from 1 commit
4fcd52b3aad598cfd1bf041d8d21af1ff8b50dba30c4b16dc81f63c8a575532a0bf5c42fd6138d8328d8ddc199e5e9541a06c985cdbb068fd20c64600dee39ee9d597e936a961d1072483aeac9c59ad42b7a2a162405afcae65d303f82d65e0aa239b52a06d8896c4e9cbf39fe01f1f2022a4955ae1c657a21de9289dd17fafe283f99456b92837ae2b59ed430922defc799d739f7665f2408bd25e87d8dc51be126640a23b79e4cf6730a75fdc7d8287440d3cad66e3686c2ef59f9a3a607a2614fda6f4ab7b826a4e023b81a7024cba3b5bb3d90025cc800ae00d49f36c3ee7f35f5b9a4a8e1cc5dbd50c422796c628e7b560c97377cfa8478874ec8bbab6acd44811388fdd421d8ec3f93d079a4341b2f5eaa902cf1783f6812c714153c869af5b815a0820b0be4726003dea4d78e4e67739492f7c8fa6b7875580ecfd48a843bdae1a9824836be039c4652bc2c15220943d53212c342cc8309bdc83562651193dda682e02e063af4f89cb5504f676ee41fa585c879909be3653e6f1d3deeb38747f8ec0d4accd3c79b7fab070cf7fcdec7b50736e329beacf10fa88bf7f1e514a7e6b8b80f662e442ee883498529c04f198e3a06ef7a5bd625734b99c0e9b6749ba9d29808f1602673394b06a3088d296c04f1ad44ab5d8e3a4a970f68c17a04b920cf5118de67e3c6ba647d16e2628b08fd029a0be2a2c7b2185fddf46fd39eadb21b67770fd2a6e1081c4e53a4e576fd4cab128487d0b1c9a64f108c8d7855964332b3bfad9d40fd0cea05edf4edcd9fb399aa01cb6fc8939eba30cf0719bbfe3ba81cb43698e85ce60ef98fd83bdb0499ce551df061fd5a0a76f4c212ee86cd3c0308bce09949fed88dccdada403b962ca13de5ec339c91191b1bfd1a806b2ef09379031df6cd3524a9bac66fa6bde2062b9174543479e580567c60d7397f904467ee8d690f4911bcfa2af9aae8e841bc2f098aaec7a04def4f0eb0c43f9c84fa92a7ba1c119986609a9e87ffcad0233147446be3f6d56d23ca55eac909496406eb1c7b9807748bacd3d9c8e62f1accc8f5ede0d2a96975fdea6426c2a38a0f640e9526087f236b2f4a5853672b4bd790d4ef2f59bb7eb59529b2917fe66a6a9944d10c9dc14054ff50f86e1fb1b5f01f7c4867da8fbf9afab9a342cc2a49968de0848df14304d0b781a1f808cb06a9ae7c969876821182478eb1b5a7f10c683663098dcb606dc1File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
…pressions ## What changes were proposed in this pull request? This PR changes the direction of expression transformation in the DecimalPrecision rule. Previously, the expressions were transformed down, which led to incorrect result types when decimal expressions had other decimal expressions as their operands. The root cause of this issue was in visiting outer nodes before their children. Consider the example below: ``` val inputSchema = StructType(StructField("col", DecimalType(26, 6)) :: Nil) val sc = spark.sparkContext val rdd = sc.parallelize(1 to 2).map(_ => Row(BigDecimal(12))) val df = spark.createDataFrame(rdd, inputSchema) // Works correctly since no nested decimal expression is involved // Expected result type: (26, 6) * (26, 6) = (38, 12) df.select($"col" * $"col").explain(true) df.select($"col" * $"col").printSchema() // Gives a wrong result since there is a nested decimal expression that should be visited first // Expected result type: ((26, 6) * (26, 6)) * (26, 6) = (38, 12) * (26, 6) = (38, 18) df.select($"col" * $"col" * $"col").explain(true) df.select($"col" * $"col" * $"col").printSchema() ``` The example above gives the following output: ``` // Correct result without sub-expressions == Parsed Logical Plan == 'Project [('col * 'col) AS (col * col)#4] +- LogicalRDD [col#1] == Analyzed Logical Plan == (col * col): decimal(38,12) Project [CheckOverflow((promote_precision(cast(col#1 as decimal(26,6))) * promote_precision(cast(col#1 as decimal(26,6)))), DecimalType(38,12)) AS (col * col)#4] +- LogicalRDD [col#1] == Optimized Logical Plan == Project [CheckOverflow((col#1 * col#1), DecimalType(38,12)) AS (col * col)#4] +- LogicalRDD [col#1] == Physical Plan == *Project [CheckOverflow((col#1 * col#1), DecimalType(38,12)) AS (col * col)#4] +- Scan ExistingRDD[col#1] // Schema root |-- (col * col): decimal(38,12) (nullable = true) // Incorrect result with sub-expressions == Parsed Logical Plan == 'Project [(('col * 'col) * 'col) AS ((col * col) * col)#11] +- LogicalRDD [col#1] == Analyzed Logical Plan == ((col * col) * col): decimal(38,12) Project [CheckOverflow((promote_precision(cast(CheckOverflow((promote_precision(cast(col#1 as decimal(26,6))) * promote_precision(cast(col#1 as decimal(26,6)))), DecimalType(38,12)) as decimal(26,6))) * promote_precision(cast(col#1 as decimal(26,6)))), DecimalType(38,12)) AS ((col * col) * col)#11] +- LogicalRDD [col#1] == Optimized Logical Plan == Project [CheckOverflow((cast(CheckOverflow((col#1 * col#1), DecimalType(38,12)) as decimal(26,6)) * col#1), DecimalType(38,12)) AS ((col * col) * col)#11] +- LogicalRDD [col#1] == Physical Plan == *Project [CheckOverflow((cast(CheckOverflow((col#1 * col#1), DecimalType(38,12)) as decimal(26,6)) * col#1), DecimalType(38,12)) AS ((col * col) * col)#11] +- Scan ExistingRDD[col#1] // Schema root |-- ((col * col) * col): decimal(38,12) (nullable = true) ``` ## How was this patch tested? This PR was tested with available unit tests. Moreover, there are tests to cover previously failing scenarios. Author: aokolnychyi <[email protected]> Closes #18583 from aokolnychyi/spark-21332. (cherry picked from commit 0be5fb4) Signed-off-by: gatorsmile <[email protected]>Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing