-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-25538][SQL] Zero-out all bytes when writing decimal #22602
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
6 commits
Select commit
Hold shift + click to select a range
851d723
[SPARK-25582][SQL] Zero-out all bytes when writing decimal
mgaido91 6b84b41
add UT + address comment
mgaido91 64f4ed0
address comment
mgaido91 72b7c5c
improve ut
mgaido91 d7d17d8
address comment
mgaido91 be38c4c
address comments
mgaido91 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
53 changes: 53 additions & 0 deletions
53
...c/test/scala/org/apache/spark/sql/catalyst/expressions/codegen/UnsafeRowWriterSuite.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,53 @@ | ||
| /* | ||
| * 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.catalyst.expressions.codegen | ||
|
|
||
| import org.apache.spark.SparkFunSuite | ||
| import org.apache.spark.sql.types.Decimal | ||
|
|
||
| class UnsafeRowWriterSuite extends SparkFunSuite { | ||
|
|
||
| def checkDecimalSizeInBytes(decimal: Decimal, numBytes: Int): Unit = { | ||
| assert(decimal.toJavaBigDecimal.unscaledValue().toByteArray.length == numBytes) | ||
| } | ||
|
|
||
| test("SPARK-25538: zero-out all bits for decimals") { | ||
| val decimal1 = Decimal(0.431) | ||
| decimal1.changePrecision(38, 18) | ||
| checkDecimalSizeInBytes(decimal1, 8) | ||
|
|
||
| val decimal2 = Decimal(123456789.1232456789) | ||
| decimal2.changePrecision(38, 18) | ||
| checkDecimalSizeInBytes(decimal2, 11) | ||
| // On an UnsafeRowWriter we write decimal2 first and then decimal1 | ||
| val unsafeRowWriter1 = new UnsafeRowWriter(1) | ||
| unsafeRowWriter1.resetRowWriter() | ||
| unsafeRowWriter1.write(0, decimal2, decimal2.precision, decimal2.scale) | ||
| unsafeRowWriter1.reset() | ||
| unsafeRowWriter1.write(0, decimal1, decimal1.precision, decimal1.scale) | ||
| val res1 = unsafeRowWriter1.getRow | ||
| // On a second UnsafeRowWriter we write directly decimal1 | ||
| val unsafeRowWriter2 = new UnsafeRowWriter(1) | ||
| unsafeRowWriter2.resetRowWriter() | ||
| unsafeRowWriter2.write(0, decimal1, decimal1.precision, decimal1.scale) | ||
| val res2 = unsafeRowWriter2.getRow | ||
| // The two rows should be the equal | ||
| assert(res1 == res2) | ||
| } | ||
|
|
||
| } | ||
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.
Shall we verify the number of bytes?
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.
thanks, I added a check for that.