-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
close #5113
- Loading branch information
1 parent
a6bc771
commit bf0d5fa
Showing
4 changed files
with
299 additions
and
1 deletion.
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
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,83 @@ | ||
// 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 <Functions/FunctionFactory.h> | ||
#include <Functions/FunctionsString.h> | ||
#include <Interpreters/Context.h> | ||
#include <TestUtils/FunctionTestUtils.h> | ||
#include <TestUtils/TiFlashTestBasic.h> | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
|
||
namespace DB::tests | ||
{ | ||
class StringSpace : public DB::tests::FunctionTest | ||
{ | ||
public: | ||
static constexpr auto func_name = "space"; | ||
|
||
protected: | ||
static ColumnWithTypeAndName toVec(const std::vector<String> & v) | ||
{ | ||
return createColumn<String>(v); | ||
} | ||
static ColumnWithTypeAndName toNullableVec(const std::vector<std::optional<String>> & v) | ||
{ | ||
return createColumn<Nullable<String>>(v); | ||
} | ||
|
||
static ColumnWithTypeAndName toVecInt(const std::vector<std::optional<Int64>> & v) | ||
{ | ||
return createColumn<Nullable<Int64>>(v); | ||
} | ||
|
||
static ColumnWithTypeAndName toConst(const Int64 & v) | ||
{ | ||
return createConstColumn<Int64>(8, v); | ||
} | ||
}; | ||
|
||
// test space | ||
TEST_F(StringSpace, spaceTest) | ||
try | ||
{ | ||
ASSERT_COLUMN_EQ( | ||
toNullableVec({" ", "", " ", "", " "}), | ||
executeFunction( | ||
func_name, | ||
toVecInt({2, 0, 10, -1, 6}))); | ||
} | ||
CATCH | ||
|
||
// test space NULL | ||
TEST_F(StringSpace, nullTest) | ||
try | ||
{ | ||
ASSERT_COLUMN_EQ( | ||
toNullableVec({{}, " "}), | ||
executeFunction( | ||
func_name, | ||
toVecInt({{}, 5}))); | ||
|
||
ASSERT_COLUMN_EQ( | ||
toNullableVec({{}}), | ||
executeFunction( | ||
func_name, | ||
toVecInt({16777217}))); | ||
} | ||
CATCH | ||
|
||
} // namespace DB::tests |
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,37 @@ | ||
# 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 int(64)); | ||
|
||
mysql> insert into test.t values(-1); | ||
mysql> insert into test.t values(0); | ||
mysql> insert into test.t values(NULL); | ||
mysql> insert into test.t values(10); | ||
mysql> insert into test.t values(16777216); | ||
mysql> insert into test.t values(16777217); | ||
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 length(space(a)) from test.t; | ||
+------------------+ | ||
| length(space(a)) | | ||
+------------------+ | ||
| 0 | | ||
| 0 | | ||
| NULL | | ||
| 10 | | ||
| 16777216 | | ||
| NULL | | ||
+------------------+ |