Skip to content
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

Refine function test framework #4861

Merged
merged 12 commits into from
May 26, 2022

Conversation

windtalker
Copy link
Contributor

@windtalker windtalker commented May 11, 2022

What problem does this PR solve?

Issue Number: close #4830

Problem Summary:

We have a function test framework used by unit test of functions, however, the current implementation of the test framework use the following code to test the function:

    auto & factory = FunctionFactory::instance();

    Block block(columns);
    ColumnNumbers cns;
    for (size_t i = 0; i < columns.size(); ++i)
        cns.push_back(i);

    auto bp = factory.tryGet(func_name, context);
    if (!bp)
        throw TiFlashTestException(fmt::format("Function {} not found!", func_name));
    auto func = bp->build(columns, collator);
    block.insert({nullptr, func->getReturnType(), "res"});
    func->execute(block, cns, columns.size());
    return block.getByPosition(columns.size());

This is not the same in the real world when we executing functions, in the real world, we first build the function:

 const String & func_name = getFunctionName(expr);
 if (DAGExpressionAnalyzerHelper::function_builder_map.count(func_name) != 0)
 {
     ret = DAGExpressionAnalyzerHelper::function_builder_map[func_name](this, expr, actions);
 }
 else
 {
     ret = buildFunction(expr, actions);
 }

Then execute the function later. When building the function, we may rewrite functions, take ifNull(col1, col2) for example, we rewrite it to
multiIf(isNull(col1), col2, assumeNotNull(col1))

Current function test framework does not take this rewrite into account, it will either testing ifNull(col1, col2) by executing ifNull(col1, col2) directly, or rewrite it manually. Both solutions can't guarantee the testing logic is the same as the real world executing logic, which makes function unit test meaningless for functions that will be rewritten during buildFunction.(#4829 is an example that we already add ut for ifNull, but not catch the real world bug)

What is changed and how it works?

  • add a new argument raw_function_test in FunctionTest::executeFunction, and if raw_function_test == true, will use the original way to test function, otherwise, will convert columns into TiPB expr first, then test the function after DAGExpressionAnalyzerHelper::buildFunction, raw_function_test is true by default

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 11, 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.

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 the release-note-none Denotes a PR that doesn't merit a release note. label May 11, 2022
@windtalker windtalker requested a review from SeaRise May 11, 2022 06:53
@ti-chi-bot ti-chi-bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label May 11, 2022
@ywqzzy ywqzzy self-requested a review May 11, 2022 06:56
dbms/src/Flash/Coprocessor/FunctionBuildHelper.cpp Outdated Show resolved Hide resolved
dbms/src/Flash/Coprocessor/FunctionBuildHelper.cpp Outdated Show resolved Hide resolved
dbms/src/Flash/Coprocessor/FunctionBuildHelper.cpp Outdated Show resolved Hide resolved
dbms/src/TestUtils/FunctionTestUtils.cpp Outdated Show resolved Hide resolved
dbms/src/TestUtils/FunctionTestUtils.cpp Outdated Show resolved Hide resolved
dbms/src/TestUtils/FunctionTestUtils.h Outdated Show resolved Hide resolved
dbms/src/Flash/Coprocessor/FunctionBuildHelper.cpp Outdated Show resolved Hide resolved
dbms/src/Flash/Coprocessor/FunctionBuildHelper.cpp Outdated Show resolved Hide resolved
dbms/src/TestUtils/FunctionTestUtils.cpp Outdated Show resolved Hide resolved
@ywqzzy ywqzzy self-requested a review May 11, 2022 07:24
dbms/src/TestUtils/FunctionTestUtils.cpp Outdated Show resolved Hide resolved
dbms/src/TestUtils/FunctionTestUtils.cpp Outdated Show resolved Hide resolved
dbms/src/TestUtils/FunctionTestUtils.cpp Show resolved Hide resolved
dbms/src/TestUtils/FunctionTestUtils.cpp Show resolved Hide resolved
dbms/src/Flash/Coprocessor/FunctionBuildHelper.cpp Outdated Show resolved Hide resolved
dbms/src/Flash/Coprocessor/FunctionBuildHelper.cpp Outdated Show resolved Hide resolved
dbms/src/Flash/Coprocessor/FunctionBuildHelper.cpp Outdated Show resolved Hide resolved
@SeaRise SeaRise requested review from SeaRise May 11, 2022 11:14
@windtalker windtalker force-pushed the refine_function_test_framework branch 2 times, most recently from 0c6e6a4 to 5c7eeb6 Compare May 13, 2022 09:08
@ti-chi-bot ti-chi-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 13, 2022
dbms/src/Flash/Coprocessor/DAGUtils.cpp Outdated Show resolved Hide resolved
dbms/src/TestUtils/FunctionTestUtils.cpp Outdated Show resolved Hide resolved
dbms/src/TestUtils/FunctionTestUtils.cpp Outdated Show resolved Hide resolved
dbms/src/TestUtils/FunctionTestUtils.cpp Outdated Show resolved Hide resolved
dbms/src/TestUtils/FunctionTestUtils.cpp Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 13, 2022
@windtalker
Copy link
Contributor Author

/run-all-tests

1 similar comment
@windtalker
Copy link
Contributor Author

/run-all-tests

@sre-bot
Copy link
Collaborator

sre-bot commented May 14, 2022

Coverage for changed files

too many lines from llvm-cov, please refer to full report instead

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18108      9813             45.81%    201878  98120        51.40%

full coverage report (for internal network access only)

@windtalker
Copy link
Contributor Author

/run-all-tests

@sre-bot
Copy link
Collaborator

sre-bot commented May 14, 2022

Coverage for changed files

too many lines from llvm-cov, please refer to full report instead

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18109      9814             45.81%    201802  98129        51.37%

full coverage report (for internal network access only)

@windtalker windtalker force-pushed the refine_function_test_framework branch from 3f9f33a to c66539b Compare May 16, 2022 00:12
@SeaRise
Copy link
Contributor

SeaRise commented May 16, 2022

There are many changes to the gtest case.
Can you give some comments

dbms/src/Core/Field.h Outdated Show resolved Hide resolved
dbms/src/DataTypes/FieldToDataType.h Outdated Show resolved Hide resolved
dbms/src/TestUtils/ColumnsToTiPBExpr.cpp Outdated Show resolved Hide resolved
@windtalker
Copy link
Contributor Author

There are many changes to the gtest case. Can you give some comments

Ok, add the main changes of unit test in issue description.

@SeaRise SeaRise self-requested a review May 16, 2022 08:04
dbms/src/DataTypes/FieldToDataType.h Outdated Show resolved Hide resolved
dbms/src/Functions/tests/gtest_bitand.cpp Outdated Show resolved Hide resolved
dbms/src/Functions/tests/gtest_bitand.cpp Outdated Show resolved Hide resolved
dbms/src/Functions/tests/gtest_datetime_daymonthyear.cpp Outdated Show resolved Hide resolved
dbms/src/Functions/tests/gtest_ifnull.cpp Outdated Show resolved Hide resolved
dbms/src/Functions/tests/gtest_ifnull.cpp Outdated Show resolved Hide resolved
dbms/src/Functions/tests/gtest_regexp.cpp Outdated Show resolved Hide resolved
@SeaRise
Copy link
Contributor

SeaRise commented May 16, 2022

how about making raw_function_test be true by default and just fix gtest_is_null in this pr?
Fix other gtest in other pr.
and make raw_function_test be false after all gtest are fixed.

@SeaRise SeaRise self-requested a review May 26, 2022 07:55
Signed-off-by: xufei <[email protected]>
…r/tiflash into refine_function_test_framework
dbms/src/Core/Field.h Outdated Show resolved Hide resolved
dbms/src/DataTypes/FieldToDataType.h Outdated Show resolved Hide resolved
dbms/src/TestUtils/FunctionTestUtils.cpp Outdated Show resolved Hide resolved
dbms/src/TestUtils/ColumnsToTiPBExpr.cpp Outdated Show resolved Hide resolved
@SeaRise SeaRise self-requested a review May 26, 2022 10:10
Copy link
Contributor

@SeaRise SeaRise left a comment

Choose a reason for hiding this comment

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

other LGTM

dbms/src/TestUtils/ColumnsToTiPBExpr.cpp Outdated Show resolved Hide resolved
dbms/src/TestUtils/ColumnsToTiPBExpr.cpp Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label May 26, 2022
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

@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 26, 2022
@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.

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.

Commit hash: 1b0239d

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label May 26, 2022
Signed-off-by: xufei <[email protected]>
…r/tiflash into refine_function_test_framework
@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label May 26, 2022
@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.

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.

Commit hash: 5e81690

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

sre-bot commented May 26, 2022

Coverage for changed files

Filename                                              Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Debug/astToExecutor.cpp                                   514               213    58.56%          49                 9    81.63%        1347               580    56.94%         512               246    51.95%
Debug/astToExecutor.h                                      29                10    65.52%          18                 5    72.22%          44                16    63.64%          10                 6    40.00%
Flash/Coprocessor/DAGExpressionAnalyzer.cpp               383               177    53.79%          50                10    80.00%         903               392    56.59%         298               166    44.30%
Flash/Coprocessor/DAGExpressionAnalyzer.h                   2                 2     0.00%           2                 2     0.00%           2                 2     0.00%           0                 0         -
Flash/Coprocessor/DAGExpressionAnalyzerHelper.cpp          92                87     5.43%          14                12    14.29%         244               226     7.38%          68                65     4.41%
Flash/Coprocessor/DAGUtils.cpp                            344               204    40.70%          45                18    60.00%         634               386    39.12%         410               239    41.71%
Flash/Coprocessor/DAGUtils.h                                3                 0   100.00%           1                 0   100.00%          12                 0   100.00%           2                 0   100.00%
TestUtils/ColumnsToTiPBExpr.cpp                            55                55     0.00%           6                 6     0.00%         122               122     0.00%          40                40     0.00%
TestUtils/FunctionTestUtils.cpp                           131                28    78.63%          12                 2    83.33%         126                44    65.08%          56                25    55.36%
TestUtils/FunctionTestUtils.h                             113                 9    92.04%          33                 0   100.00%         264                 7    97.35%          48                 6    87.50%
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                    1666               785    52.88%         230                64    72.17%        3698              1775    52.00%        1444               793    45.08%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18277      9786             46.46%    204780  98132        52.08%

full coverage report (for internal network access only)

@ti-chi-bot ti-chi-bot merged commit 973de13 into pingcap:master May 26, 2022
@windtalker windtalker deleted the refine_function_test_framework 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/XXL Denotes a PR that changes 1000+ 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.

Function unit test should follow the same logic in DAGExpressionAnalyzer when building function
5 participants