Skip to content

refine get type from decimal literal#5014

Merged
ti-chi-bot merged 4 commits intopingcap:masterfrom
windtalker:decimal_literal_type_enhance
May 30, 2022
Merged

refine get type from decimal literal#5014
ti-chi-bot merged 4 commits intopingcap:masterfrom
windtalker:decimal_literal_type_enhance

Conversation

@windtalker
Copy link
Contributor

Signed-off-by: xufei xufeixw@mail.ustc.edu.cn

What problem does this PR solve?

Issue Number: close #5007

Problem Summary:
As the issue described.

What is changed and how it works?

  1. DecimalField::getPrec() ensures that the returned precision is not less than decimal's scale
  2. FieldToDataType will return a more precise type for DecimalField

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented May 27, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • SeaRise
  • ywqzzy

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Details

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 27, 2022
@windtalker windtalker requested review from SeaRise and ywqzzy May 27, 2022 03:27
@windtalker windtalker force-pushed the decimal_literal_type_enhance branch from 2019915 to 4388a05 Compare May 27, 2022 03:28
@windtalker
Copy link
Contributor Author

/run-all-tests

/// inserted into a decimal column with type `Decimal(getPrecWithCurrentDecimalType, getScale)`
UInt32 getPrecWithCurrentDecimalType() const
{
auto raw_prec = getPrec();
Copy link
Contributor

Choose a reason for hiding this comment

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

Will getPrec() > maxDecimalPrecision<T>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, basically, getPrec() is getting the precision of a literal of type T, so getPrec() > maxDecimalPrecision<T> should not happen.

Copy link
Contributor

Choose a reason for hiding this comment

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

add assert(getPrec() <= maxDecimalPrecision<T>)?

Copy link
Contributor

@ywqzzy ywqzzy left a comment

Choose a reason for hiding this comment

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

LGTM

TEST(DecimalLiteralDataTypeTest, fieldToDataType)
try
{
ASSERT_TRUE(DataTypeFactory::instance().get("Decimal(1,0)")->equals(*applyVisitor(FieldToDataType(), Field(DecimalField<Decimal32>(0, 0)))));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ASSERT_TRUE(DataTypeFactory::instance().get("Decimal(1,0)")->equals(*applyVisitor(FieldToDataType(), Field(DecimalField<Decimal32>(0, 0)))));
/// decimal32
ASSERT_TRUE(DataTypeFactory::instance().get("Decimal(1,0)")->equals(*applyVisitor(FieldToDataType(), Field(DecimalField<Decimal32>(0, 0)))));

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Add annotation to make it clear to read the test.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label May 30, 2022
Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels May 30, 2022
Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
@windtalker windtalker force-pushed the decimal_literal_type_enhance branch from 8c70b2e to 565161b Compare May 30, 2022 02:23
@windtalker
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

@windtalker: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

DetailsCommit hash: 565161b

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label May 30, 2022
@sre-bot
Copy link
Collaborator

sre-bot commented May 30, 2022

Coverage for changed files

Filename                                               Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Common/Decimal.h                                            87                25    71.26%          48                 9    81.25%         199                60    69.85%          32                15    53.12%
Core/Field.h                                               198               104    47.47%          67                22    67.16%         422               201    52.37%         188               121    35.64%
DataTypes/DataTypeDecimal.h                                117                39    66.67%          29                13    55.17%         154                64    58.44%          74                24    67.57%
DataTypes/FieldToDataType.h                                  1                 0   100.00%           1                 0   100.00%           3                 0   100.00%           0                 0         -
DataTypes/tests/gtest_decimal_literal_datatype.cpp         958               191    80.06%           2                 0   100.00%          59                 0   100.00%         314               159    49.36%
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                     1361               359    73.62%         147                44    70.07%         837               325    61.17%         608               319    47.53%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18291      9796             46.44%    204923  98198        52.08%

full coverage report (for internal network access only)

@ti-chi-bot ti-chi-bot merged commit c8624a0 into pingcap:master May 30, 2022
@windtalker windtalker deleted the decimal_literal_type_enhance branch January 30, 2023 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get precise precision for Decimal literal in FieldToDataType and DecimalField::getPrec

5 participants