forked from pingcap/tiflash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ReverseUTF8/Reverse function push down pingcap#5111
- Loading branch information
1 parent
b2f0af8
commit 28ae999
Showing
3 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | | ||
+------------+ | ||
|
||
|