Skip to content

[Flink] fix data overflow while convert Integer to Long (#3738)#3740

Merged
rdblue merged 3 commits into
apache:masterfrom
chenzihao5:fix-data-overflow
Dec 23, 2021
Merged

[Flink] fix data overflow while convert Integer to Long (#3738)#3740
rdblue merged 3 commits into
apache:masterfrom
chenzihao5:fix-data-overflow

Conversation

@chenzihao5

Copy link
Copy Markdown
Contributor
  1. What this MR does ?
    Fix data overflow while writing data whose type is java.sql.Time.
  2. CHANGELOG
    Flink version: 1.12, 1.13, 1.14
    function: org.apache.iceberg.flink.data.FlinkValueWriters.TimeMicrosWriter#write

@openinx @JingsongLi Please help to confirm this Problem. Thanks very much.

@github-actions github-actions Bot added the flink label Dec 14, 2021

@kbendick kbendick left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this patch @chenzihao5!

I checked (with a Scala shell but using java.lang.Integer) and using the explicit float does indeed seem to prevent overflow.

scala> import java.lang.{Integer => JInt}
import java.lang.{Integer=>JInt}

scala> JInt.MAX_VALUE
res5: Int = 2147483647

scala> JInt.MAX_VALUE * 1000
res6: Int = -1000

scala> JInt.MAX_VALUE * 1000L
res7: Long = 2147483647000

Could you add test cases somewhere for writing a value that would have overflowed otherwise?

@chenzihao5

Copy link
Copy Markdown
Contributor Author

Thanks for this patch @chenzihao5!

I checked (with a Scala shell but using java.lang.Integer) and using the explicit float does indeed seem to prevent overflow.

scala> import java.lang.{Integer => JInt}
import java.lang.{Integer=>JInt}

scala> JInt.MAX_VALUE
res5: Int = 2147483647

scala> JInt.MAX_VALUE * 1000
res6: Int = -1000

scala> JInt.MAX_VALUE * 1000L
res7: Long = 2147483647000

Could you add test cases somewhere for writing a value that would have overflowed otherwise?

@kbendick Thanks for your review. I will add some unit tests.

@openinx

openinx commented Dec 15, 2021

Copy link
Copy Markdown
Member

Great finding, @chenzihao5 . It's indeed an overflow bug !

@rdblue rdblue added this to the Iceberg 0.13.0 Release milestone Dec 19, 2021
@rdblue

rdblue commented Dec 19, 2021

Copy link
Copy Markdown
Contributor

I'm marking this for inclusion in 0.13.0. We should wait for tests, but I want to make sure we include this in the release.

@chenzihao5

Copy link
Copy Markdown
Contributor Author

I'm marking this for inclusion in 0.13.0. We should wait for tests, but I want to make sure we include this in the release.

Thanks for reminding, I will complete the unit test today.

@chenzihao5

Copy link
Copy Markdown
Contributor Author

@rdblue @kbendick @openinx Hi, All. I have added unit tests in version 1.14, please help to review it, Thanks.

About these unit tests:
1. test for numeric type, such as: int, float, double, date, time, timestamp, long, decimal.
2. test MAX_VALUE and MIN_VALUE of all types.
3. If this version is completed, I will add unit tests in version 1.12 and 1.13 too.

Thanks for reviewing!


@RunWith(Parameterized.class)
public class TestFlinkIcebergSinkNumData extends TableTestBase {
@ClassRule

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Iceberg uses 2 spaces for an indent. Can you please reformat this file?

new Object[]{"parquet", 1, true},
new Object[]{"parquet", 1, false},
new Object[]{"parquet", 2, true},
new Object[]{"parquet", 2, false}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This many cases seems overkill to validate one method. Can you update an existing test suite for Avro writes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I will update it.

@chenzihao5

Copy link
Copy Markdown
Contributor Author

@rdblue I have updated test into existing test suite for Avro writer and reformat code style. Please help to review it.

@rdblue

rdblue commented Dec 23, 2021

Copy link
Copy Markdown
Contributor

Thanks, @chenzihao5! Looks good to me now. I'm running CI and will merge when it passes.

@rdblue rdblue merged commit b3b41f8 into apache:master Dec 23, 2021
@rdblue

rdblue commented Dec 23, 2021

Copy link
Copy Markdown
Contributor

Thanks, @chenzihao5! I merged this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants