Skip to content

[WIP] support least() function.#3537

Closed
ywqzzy wants to merge 63 commits intopingcap:masterfrom
ywqzzy:ywq_least
Closed

[WIP] support least() function.#3537
ywqzzy wants to merge 63 commits intopingcap:masterfrom
ywqzzy:ywq_least

Conversation

@ywqzzy
Copy link
Contributor

@ywqzzy ywqzzy commented Nov 23, 2021

What problem does this PR solve?

Issue Number: close #xxx

Problem Summary:

What is changed and how it works?

Proposal: xxx

What's Changed:

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch:

Check List

Tests

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

Side effects

Release note

Please add a release note, or a 'None' if it is not needed.

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has not been approved.

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 Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 23, 2021
@ti-chi-bot ti-chi-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 24, 2021
@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 Dec 1, 2021
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 18, 2021
@ti-chi-bot
Copy link
Member

@ywqzzy: PR needs rebase.

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 kubernetes/test-infra repository.

@SeaRise SeaRise self-requested a review December 29, 2021 03:29
c_res->getChars(),
c_res->getOffsets());
else
throw Exception("Illegal columns "
Copy link
Contributor

Choose a reason for hiding this comment

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

fmt::format

c_res->getChars(),
c_res->getOffsets());
else
throw Exception("Illegal columns "
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

class FunctionTiDBLeastGreatest : public IFunction
{
public:
static constexpr auto name = kind == LeastGreatest::Least ? "tidbLeast" : "tidbGreatest";
Copy link
Contributor

Choose a reason for hiding this comment

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

how about `` static constexpr auto name = kind::name`

DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
{
if (arguments.size() < 2)
throw Exception("Number of arguments for function " + getName() + " doesn't match: passed " + toString(arguments.size())
Copy link
Contributor

Choose a reason for hiding this comment

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

fmt::format

size_t num_arguments = arguments.size();
if (num_arguments < 2)
{
throw Exception("Number of arguments for function " + getName() + " doesn't match: passed "
Copy link
Contributor

Choose a reason for hiding this comment

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

fmt::format

DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
{
if (arguments.size() < 2)
throw Exception("Number of arguments for function " + getName() + " doesn't match: passed " + toString(arguments.size())
Copy link
Contributor

Choose a reason for hiding this comment

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

fmt

size_t num_arguments = arguments.size();
if (num_arguments < 2)
{
throw Exception("Number of arguments for function " + getName() + " doesn't match: passed "
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

return data->compareAt(0, 0, *static_cast<const ColumnConst &>(rhs).data, nan_direction_hint);
}

int compareAtWithCollation(size_t, size_t m, const IColumn & rhs_, int null_direction_hint, const ICollator & collator) const override
Copy link
Contributor

Choose a reason for hiding this comment

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

how about int int compareAt(size_t, size_t, const IColumn & rhs, int nan_direction_hint, , const ICollator * collator = nullptr) const override

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe i can create another pr to make the interface clean in all related files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pr is #3790, PTAL

else
cmp_result = converted_columns[arg]->compareAt(row_num, row_num, *converted_columns[best_arg], 1);

if constexpr (kind == LeastGreatest::Least)
Copy link
Contributor

Choose a reason for hiding this comment

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

how about if (kind::xxx(cmp_result )) { best_arg = arg; }

DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
{
if (arguments.size() < 2)
throw Exception("Number of arguments for function " + getName() + " doesn't match: passed " + toString(arguments.size())
Copy link
Contributor

Choose a reason for hiding this comment

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

fmt

@SeaRise SeaRise self-requested a review December 29, 2021 10:54

TiDB::TiDBCollatorPtr getCollatorFromFieldType(const tipb::FieldType & field_type)
{
std::cout << "field type collate: " << field_type.collate() << std::endl;
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
std::cout << "field type collate: " << field_type.collate() << std::endl;

for (const auto & child : expr.children())
{
String name = getActions(child, actions);
std::cout << "name: " << name << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

clean up these debug lines

ExpressionActionsPtr & actions)
{
const String & func_name = getFunctionName(expr);
std::cout << "func_name: " << func_name << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

const TiDB::TiDBCollatorPtr & collator)
{
String result_name = genFuncString(func_name, arg_names, {collator});
std::cout << "result name: " << result_name << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Get.


struct CompareDecimalInferer
{
static inline void infer(PrecType left_prec, ScaleType left_scale, PrecType right_prec, ScaleType right_scale, PrecType & result_prec, ScaleType & result_scale)
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
static inline void infer(PrecType left_prec, ScaleType left_scale, PrecType right_prec, ScaleType right_scale, PrecType & result_prec, ScaleType & result_scale)
static std::tuple<PrecType, ScaleType> infer(PrecType left_prec, ScaleType left_scale, PrecType right_prec, ScaleType right_scale)

what is it used for?

{}

String toString(int fsp) const;
int fsp;
Copy link
Contributor

Choose a reason for hiding this comment

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

could you explain why MyDateTime need fsp and why not put it into the base class?

Copy link
Contributor Author

@ywqzzy ywqzzy Jan 4, 2022

Choose a reason for hiding this comment

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

ASSERT_COLUMN_EQ(
        createColumn<Nullable<String>>({"2020-10-20 00:00:00"}),
        executeFunction(
            func_name,
            createColumn<Nullable<String>>({"2021-12-28 11:19:09"}),
            createColumn<Nullable<String>>({"2020-10-20"})));

Without fsp, the result will be "2020-10-20", which is inconsistent with MYSQL and TIDB, the follwing getFsp() function was added to align with TIDB

return idx;
}

int getFsp(const String & s)
Copy link
Contributor

Choose a reason for hiding this comment

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

which format is s expected to be?

template <typename A, typename B>
struct ResultOfTiDBLeast
{
static constexpr auto result_size = std::max(actual_size_v<A>, actual_size_v<B>);
Copy link
Contributor

Choose a reason for hiding this comment

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

to align with TiDB, least/greatest for integers should always return Int64 or UInt64.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Get!

typename ResultOfIf<A, B>::Type>;

template <typename A, typename B>
constexpr bool TiDBLeastGreatestSpecialCase
Copy link
Contributor

Choose a reason for hiding this comment

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

It should be a type inferer and let the users get the return type of least/greatest like:

using ReturnType = TiDBLeastGreatestReturnTypeInferer<true /*least*/, A, B>;

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

Labels

do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants