Skip to content

Commit

Permalink
Implement ReverseUTF8/Reverse function push down pingcap#5111
Browse files Browse the repository at this point in the history
  • Loading branch information
lizhenhuan committed Jun 25, 2022
1 parent b2f0af8 commit 28ae999
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 2 deletions.
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
74 changes: 74 additions & 0 deletions dbms/src/Functions/tests/gtest_strings_reverse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// 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>
#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>

#pragma GCC diagnostic pop

namespace DB
{
namespace tests
{
class StringReverse : public DB::tests::FunctionTest
{
public:
static constexpr auto func_name = "reverse";
protected:
ColumnWithTypeAndName toVec(const std::vector<std::optional<String>> & v)
{
return createColumn<Nullable<String>>(v);
}
};

// test string and string
TEST_F(StringReverse, strAndStrTest)
try
{
ASSERT_COLUMN_EQ(
toVec({"olleh", "dlrow,olleh","", "pacgnip.www", "。。。试.测.文中"}),
executeFunction(
func_name,
toVec({"hello", "hello,world","", "www.pingcap", "中文.测.试。。。"}),
));
}
CATCH

// test NULL
TEST_F(StringLength, nullTest)
{
ASSERT_COLUMN_EQ(
toVec({"", {}}),
executeFunction(
func_name,
toVec({"", {}}),
));
}

} // namespace tests
} // namespace DB
49 changes: 49 additions & 0 deletions tests/fullstack-test/expr/reverse.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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 char(20));

mysql> insert into test.t values('hello');
mysql> insert into test.t values('hello,world');
mysql> insert into test.t values('');
mysql> insert into test.t values('www.pingcap');
mysql> insert into test.t values('中文.测.试。。。');
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) |
+-------------------------+
| olleh |
| dlrow,olleh |
| |
| pacgnip.www |
| 。。。试.测.文中 |
+-------------------------+

mysql> drop table if exists test.t;
mysql> create table if not exists test.t(a char(20));
mysql> insert into test.t values(NULL);

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) |
+------------+
| NULL |
+------------+


0 comments on commit 28ae999

Please sign in to comment.