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

Implement ReverseUTF8/Reverse function push down #5233

Merged
merged 15 commits into from
Jul 7, 2022
Merged
4 changes: 2 additions & 2 deletions dbms/src/Flash/Coprocessor/DAGUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,8 @@ const std::unordered_map<tipb::ScalarFuncSig, String> scalar_func_map({
//{tipb::ScalarFuncSig::Quote, "cast"},
//{tipb::ScalarFuncSig::Repeat, "cast"},
{tipb::ScalarFuncSig::Replace, "replaceAll"},
//{tipb::ScalarFuncSig::ReverseUTF8, "cast"},
//{tipb::ScalarFuncSig::Reverse, "cast"},
{tipb::ScalarFuncSig::ReverseUTF8, "reverseUTF8"},
{tipb::ScalarFuncSig::Reverse, "reverse"},
{tipb::ScalarFuncSig::RightUTF8, "rightUTF8"},
//{tipb::ScalarFuncSig::Right, "cast"},
{tipb::ScalarFuncSig::RpadUTF8, "rpadUTF8"},
Expand Down
99 changes: 99 additions & 0 deletions dbms/src/Functions/tests/gtest_strings_reverse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright 2022 PingCAP, Ltd.
//
// Licensed 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.

#include <Columns/ColumnString.h>
#include <Columns/ColumnsNumber.h>
#include <DataTypes/DataTypeNullable.h>
#include <DataTypes/DataTypesNumber.h>
ywqzzy marked this conversation as resolved.
Show resolved Hide resolved
#include <Functions/FunctionFactory.h>
#include <Functions/FunctionsString.h>
#include <Interpreters/Context.h>
#include <TestUtils/FunctionTestUtils.h>
#include <TestUtils/TiFlashTestBasic.h>

#include <string>
#include <vector>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <Poco/Types.h>
ywqzzy marked this conversation as resolved.
Show resolved Hide resolved

#pragma GCC diagnostic pop

namespace DB
{
namespace tests
{
class StringReverse : public DB::tests::FunctionTest
{
public:
static constexpr auto func_name = "reverse";
lizhenhuan marked this conversation as resolved.
Show resolved Hide resolved

protected:
ColumnWithTypeAndName toVec(const std::vector<std::optional<String>> & v)
Copy link
Contributor

Choose a reason for hiding this comment

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

Testing nullable means that the column can be null, you can refer here

static ColumnWithTypeAndName toNullableVec(const std::vector<std::optional<String>> & v)
,

{
return createColumn<Nullable<String>>(v);
}
};
// test reverse
TEST_F(StringReverse, stringReverseTest)
mengxin9014 marked this conversation as resolved.
Show resolved Hide resolved
try
{
std::vector<std::optional<String>> candidate_strings = {"one week's time test", "abcdef", "abcabc", "moc.pacgnip"};
std::vector<std::optional<String>> reversed_strings = {"tset emit s'keew eno", "fedcba", "cbacba", "pingcap.com"};
ASSERT_COLUMN_EQ(
toVec(reversed_strings),
executeFunction(
func_name,
toVec(candidate_strings)));
}
CATCH

// test reverseUTF8
TEST_F(StringReverse, stringReverseUTF8Test)
try
{
std::vector<std::optional<String>> candidate_strings = {"one week's time test", "abc测试def", "abcテストabc", "ѐёђѓєѕіїјљњћќѝўџ", "+ѐ-ё*ђ/ѓ!є@ѕ#і$@ї%ј……љ&њ(ћ)ќ¥ѝ#ў@џ!^", "αβγδεζηθικλμνξοπρστυφχψωσ", "▲α▼βγ➨δε☎ζη✂θι€κλ♫μν✓ξο✚πρ℉στ♥υφ♖χψ♘ω★σ✕", "թփձջրչճժծքոեռտըւիօպասդֆգհյկլխզղցվբնմշ"};
std::vector<std::optional<String>> reversed_strings = {"tset emit s'keew eno", "fed试测cba", "cbaトステcba", "џўѝќћњљјїіѕєѓђёѐ", "^!џ@ў#ѝ¥ќ)ћ(њ&љ……ј%ї@$і#ѕ@є!ѓ/ђ*ё-ѐ+", "σωψχφυτσρποξνμλκιθηζεδγβα", "✕σ★ω♘ψχ♖φυ♥τσ℉ρπ✚οξ✓νμ♫λκ€ιθ✂ηζ☎εδ➨γβ▼α▲", "շմնբվցղզխլկյհգֆդսապօիւըտռեոքծժճչրջձփթ"};
ywqzzy marked this conversation as resolved.
Show resolved Hide resolved
// ASSERT_COLUMN_EQ(
mengxin9014 marked this conversation as resolved.
Show resolved Hide resolved
// toVec(reversed_strings),
// executeFunction(
// func_name,
// toVec(candidate_strings)));
ASSERT_COLUMN_EQ(
toVec(reversed_strings),
executeFunction(
"reverseUTF8",
mengxin9014 marked this conversation as resolved.
Show resolved Hide resolved
toVec(candidate_strings)));
}
CATCH


// test NULL
TEST_F(StringReverse, nullTest)
{
ASSERT_COLUMN_EQ(
ywqzzy marked this conversation as resolved.
Show resolved Hide resolved
toVec({"", {}}),
executeFunction(
func_name,
toVec({"", {}})));
ASSERT_COLUMN_EQ(
toVec({"", {}}),
executeFunction(
"reverseUTF8",
toVec({"", {}})));
}

} // namespace tests
} // namespace DB
44 changes: 44 additions & 0 deletions tests/fullstack-test/expr/reverse.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2022 PingCAP, Ltd.
#
# Licensed 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.

mysql> drop table if exists test.t;
mysql> create table if not exists test.t(a varchar(256));


mysql> insert into test.t values('one week’s time test');
mysql> insert into test.t values('abc测试def');
mysql> insert into test.t values('abcテストabc');
mysql> insert into test.t values('ѐёђѓєѕіїјљњћќѝўџ');
mysql> insert into test.t values('+ѐ-ё*ђ/ѓ!є@ѕ#і@ї%ј……љ&њ(ћ)ќ¥ѝ#ў@џ!^');
mysql> insert into test.t values('αβγδεζηθικλμνξοπρστυφχψωσ');
mysql> insert into test.t values('▲α▼βγ➨δε☎ζη✂θι€κλ♫μν✓ξο✚πρ℉στ♥υφ♖χψ♘ω★σ✕');
mysql> insert into test.t values('թփձջրչճժծքոեռտըւիօպասդֆգհյկլխզղցվբնմշ');
mysql> insert into test.t values(NULL);
mysql> alter table test.t set tiflash replica 1;
func> wait_table test t

mysql> set tidb_enforce_mpp=1; set tidb_isolation_read_engines='tiflash'; select reverse(a) from test.t;
+-------------------------------------------------------------------------------------------------+
| reverse(a) |
+-------------------------------------------------------------------------------------------------+
| tset emit s’keew eno |
| fed试测cba |
| cbaトステcba |
| џўѝќћњљјїіѕєѓђёѐ |
| ^!џ@ў#ѝ¥ќ)ћ(њ&љ……ј%ї@і#ѕ@є!ѓ/ђ*ё-ѐ+ |
| σωψχφυτσρποξνμλκιθηζεδγβα |
| ✕σ★ω♘ψχ♖φυ♥τσ℉ρπ✚οξ✓νμ♫λκ€ιθ✂ηζ☎εδ➨γβ▼α▲ |
| շմնբվցղզխլկյհգֆդսապօիւըտռեոքծժճչրջձփթ |
| NULL |
+-------------------------------------------------------------------------------------------------+