-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into grace_shutdown
- Loading branch information
Showing
5 changed files
with
266 additions
and
4 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
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,196 @@ | ||
// 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 <Common/MyTime.h> | ||
#include <Functions/FunctionFactory.h> | ||
#include <TestUtils/FunctionTestUtils.h> | ||
#include <TestUtils/TiFlashTestBasic.h> | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace DB::tests | ||
{ | ||
class TestDayOfWeekYear : public DB::tests::FunctionTest | ||
{ | ||
}; | ||
|
||
TEST_F(TestDayOfWeekYear, TestDayOfWeek) | ||
try | ||
{ | ||
/// ColumnVector(nullable) | ||
const String func_name = "toDayOfWeek"; | ||
static auto const nullable_datetime_type_ptr = makeNullable(std::make_shared<DataTypeMyDateTime>(6)); | ||
static auto const datetime_type_ptr = std::make_shared<DataTypeMyDateTime>(6); | ||
static auto const date_type_ptr = std::make_shared<DataTypeMyDate>(); | ||
auto data_col_ptr = createColumn<Nullable<DataTypeMyDateTime::FieldType>>( | ||
{ | ||
{}, // Null | ||
// FIXME: https://github.com/pingcap/tiflash/issues/4186 | ||
// MyDateTime(2022, 12, 0, 1, 1, 1, 1).toPackedUInt(), | ||
// MyDateTime(2022, 13, 31, 1, 1, 1, 1).toPackedUInt(), | ||
MyDateTime(1969, 1, 2, 1, 1, 1, 1).toPackedUInt(), | ||
MyDateTime(2022, 3, 13, 6, 7, 8, 9).toPackedUInt(), | ||
MyDateTime(2022, 3, 14, 9, 8, 7, 6).toPackedUInt(), | ||
MyDateTime(2022, 3, 15, 0, 0, 0, 0).toPackedUInt(), | ||
MyDateTime(2022, 3, 16, 1, 2, 3, 4).toPackedUInt(), | ||
MyDateTime(2022, 3, 17, 4, 3, 2, 1).toPackedUInt(), | ||
MyDateTime(2022, 3, 18, 0, 0, 0, 0).toPackedUInt(), | ||
MyDateTime(2022, 3, 19, 1, 1, 1, 1).toPackedUInt(), | ||
}) | ||
.column; | ||
auto input_col = ColumnWithTypeAndName(data_col_ptr, nullable_datetime_type_ptr, "input"); | ||
auto output_col = createColumn<Nullable<UInt8>>({{}, 5, 1, 2, 3, 4, 5, 6, 7}); | ||
ASSERT_COLUMN_EQ(output_col, executeFunction(func_name, input_col)); | ||
|
||
/// ColumnVector(non-null) | ||
data_col_ptr = createColumn<DataTypeMyDateTime::FieldType>( | ||
{ | ||
MyDateTime(1969, 1, 2, 1, 1, 1, 1).toPackedUInt(), | ||
MyDateTime(2022, 3, 13, 6, 7, 8, 9).toPackedUInt(), | ||
MyDateTime(2022, 3, 14, 9, 8, 7, 6).toPackedUInt(), | ||
MyDateTime(2022, 3, 15, 0, 0, 0, 0).toPackedUInt(), | ||
MyDateTime(2022, 3, 16, 1, 2, 3, 4).toPackedUInt(), | ||
MyDateTime(2022, 3, 17, 4, 3, 2, 1).toPackedUInt(), | ||
MyDateTime(2022, 3, 18, 0, 0, 0, 0).toPackedUInt(), | ||
MyDateTime(2022, 3, 19, 1, 1, 1, 1).toPackedUInt(), | ||
}) | ||
.column; | ||
input_col = ColumnWithTypeAndName(data_col_ptr, datetime_type_ptr, "input"); | ||
output_col = createColumn<UInt8>({5, 1, 2, 3, 4, 5, 6, 7}); | ||
ASSERT_COLUMN_EQ(output_col, executeFunction(func_name, input_col)); | ||
|
||
/// ColumnConst(non-null) | ||
input_col = ColumnWithTypeAndName(createConstColumn<DataTypeMyDateTime::FieldType>(1, MyDateTime(2022, 3, 19, 1, 1, 1, 1).toPackedUInt()).column, datetime_type_ptr, "input"); | ||
output_col = createConstColumn<UInt8>(1, {7}); | ||
ASSERT_COLUMN_EQ(output_col, executeFunction(func_name, input_col)); | ||
|
||
/// ColumnConst(nullable) | ||
input_col = ColumnWithTypeAndName(createConstColumn<Nullable<DataTypeMyDateTime::FieldType>>(1, MyDateTime(2022, 3, 19, 1, 1, 1, 1).toPackedUInt()).column, nullable_datetime_type_ptr, "input"); | ||
output_col = createConstColumn<Nullable<UInt8>>(1, {7}); | ||
ASSERT_COLUMN_EQ(output_col, executeFunction(func_name, input_col)); | ||
|
||
/// ColumnConst(nullable(null)) | ||
input_col = ColumnWithTypeAndName(createConstColumn<Nullable<DataTypeMyDateTime::FieldType>>(1, {}).column, nullable_datetime_type_ptr, "input"); | ||
output_col = createConstColumn<Nullable<UInt8>>(1, {}); | ||
ASSERT_COLUMN_EQ(output_col, executeFunction(func_name, input_col)); | ||
|
||
/// MyDate ColumnVector(non-null) | ||
data_col_ptr = createColumn<DataTypeMyDate::FieldType>( | ||
{ | ||
MyDate(1969, 1, 2).toPackedUInt(), | ||
MyDate(2022, 3, 13).toPackedUInt(), | ||
MyDate(2022, 3, 14).toPackedUInt(), | ||
MyDate(2022, 3, 15).toPackedUInt(), | ||
MyDate(2022, 3, 16).toPackedUInt(), | ||
MyDate(2022, 3, 17).toPackedUInt(), | ||
MyDate(2022, 3, 18).toPackedUInt(), | ||
MyDate(2022, 3, 19).toPackedUInt(), | ||
}) | ||
.column; | ||
input_col = ColumnWithTypeAndName(data_col_ptr, date_type_ptr, "input"); | ||
output_col = createColumn<UInt8>({5, 1, 2, 3, 4, 5, 6, 7}); | ||
ASSERT_COLUMN_EQ(output_col, executeFunction(func_name, input_col)); | ||
} | ||
CATCH | ||
|
||
TEST_F(TestDayOfWeekYear, TestDayOfYear) | ||
try | ||
{ | ||
/// ColumnVector(nullable) | ||
const String func_name = "toDayOfYear"; | ||
static auto const nullable_datetime_type_ptr = makeNullable(std::make_shared<DataTypeMyDateTime>(6)); | ||
static auto const datetime_type_ptr = std::make_shared<DataTypeMyDateTime>(6); | ||
static auto const date_type_ptr = std::make_shared<DataTypeMyDate>(); | ||
auto data_col_ptr = createColumn<Nullable<DataTypeMyDateTime::FieldType>>( | ||
{ | ||
{}, // Null | ||
// FIXME: https://github.com/pingcap/tiflash/issues/4186 | ||
// MyDateTime(2022, 12, 0, 1, 1, 1, 1).toPackedUInt(), | ||
// MyDateTime(2022, 13, 31, 1, 1, 1, 1).toPackedUInt(), | ||
MyDateTime(1969, 1, 2, 1, 1, 1, 1).toPackedUInt(), | ||
MyDateTime(2022, 3, 13, 6, 7, 8, 9).toPackedUInt(), | ||
MyDateTime(2022, 3, 14, 9, 8, 7, 6).toPackedUInt(), | ||
MyDateTime(2022, 3, 15, 0, 0, 0, 0).toPackedUInt(), | ||
MyDateTime(2022, 3, 16, 1, 2, 3, 4).toPackedUInt(), | ||
MyDateTime(2022, 3, 17, 4, 3, 2, 1).toPackedUInt(), | ||
MyDateTime(2022, 3, 18, 0, 0, 0, 0).toPackedUInt(), | ||
MyDateTime(2022, 3, 19, 1, 1, 1, 1).toPackedUInt(), | ||
MyDateTime(1900, 12, 31, 1, 1, 1, 1).toPackedUInt(), | ||
MyDateTime(2020, 12, 31, 1, 1, 1, 1).toPackedUInt(), | ||
MyDateTime(2022, 12, 31, 1, 1, 1, 1).toPackedUInt(), | ||
}) | ||
.column; | ||
auto input_col = ColumnWithTypeAndName(data_col_ptr, nullable_datetime_type_ptr, "input"); | ||
auto output_col = createColumn<Nullable<UInt16>>({{}, 2, 72, 73, 74, 75, 76, 77, 78, 365, 366, 365}); | ||
ASSERT_COLUMN_EQ(output_col, executeFunction(func_name, input_col)); | ||
|
||
/// ColumnVector(non-null) | ||
data_col_ptr = createColumn<DataTypeMyDateTime::FieldType>( | ||
{ | ||
MyDateTime(1969, 1, 2, 1, 1, 1, 1).toPackedUInt(), | ||
MyDateTime(2022, 3, 13, 6, 7, 8, 9).toPackedUInt(), | ||
MyDateTime(2022, 3, 14, 9, 8, 7, 6).toPackedUInt(), | ||
MyDateTime(2022, 3, 15, 0, 0, 0, 0).toPackedUInt(), | ||
MyDateTime(2022, 3, 16, 1, 2, 3, 4).toPackedUInt(), | ||
MyDateTime(2022, 3, 17, 4, 3, 2, 1).toPackedUInt(), | ||
MyDateTime(2022, 3, 18, 0, 0, 0, 0).toPackedUInt(), | ||
MyDateTime(2022, 3, 19, 1, 1, 1, 1).toPackedUInt(), | ||
MyDateTime(1900, 12, 31, 1, 1, 1, 1).toPackedUInt(), | ||
MyDateTime(2020, 12, 31, 1, 1, 1, 1).toPackedUInt(), | ||
MyDateTime(2022, 12, 31, 1, 1, 1, 1).toPackedUInt(), | ||
}) | ||
.column; | ||
input_col = ColumnWithTypeAndName(data_col_ptr, datetime_type_ptr, "input"); | ||
output_col = createColumn<UInt16>({2, 72, 73, 74, 75, 76, 77, 78, 365, 366, 365}); | ||
ASSERT_COLUMN_EQ(output_col, executeFunction(func_name, input_col)); | ||
|
||
/// ColumnConst(non-null) | ||
input_col = ColumnWithTypeAndName(createConstColumn<DataTypeMyDateTime::FieldType>(1, MyDateTime(2022, 3, 19, 1, 1, 1, 1).toPackedUInt()).column, datetime_type_ptr, "input"); | ||
output_col = createConstColumn<UInt16>(1, {78}); | ||
ASSERT_COLUMN_EQ(output_col, executeFunction(func_name, input_col)); | ||
|
||
/// ColumnConst(nullable) | ||
input_col = ColumnWithTypeAndName(createConstColumn<Nullable<DataTypeMyDateTime::FieldType>>(1, MyDateTime(2022, 3, 19, 1, 1, 1, 1).toPackedUInt()).column, nullable_datetime_type_ptr, "input"); | ||
output_col = createConstColumn<Nullable<UInt16>>(1, {78}); | ||
ASSERT_COLUMN_EQ(output_col, executeFunction(func_name, input_col)); | ||
|
||
/// ColumnConst(nullable(null)) | ||
input_col = ColumnWithTypeAndName(createConstColumn<Nullable<DataTypeMyDateTime::FieldType>>(1, {}).column, nullable_datetime_type_ptr, "input"); | ||
output_col = createConstColumn<Nullable<UInt16>>(1, {}); | ||
ASSERT_COLUMN_EQ(output_col, executeFunction(func_name, input_col)); | ||
|
||
/// MyDate ColumnVector(non-null) | ||
data_col_ptr = createColumn<DataTypeMyDate::FieldType>( | ||
{ | ||
MyDate(1969, 1, 2).toPackedUInt(), | ||
MyDate(2022, 3, 13).toPackedUInt(), | ||
MyDate(2022, 3, 14).toPackedUInt(), | ||
MyDate(2022, 3, 15).toPackedUInt(), | ||
MyDate(2022, 3, 16).toPackedUInt(), | ||
MyDate(2022, 3, 17).toPackedUInt(), | ||
MyDate(2022, 3, 18).toPackedUInt(), | ||
MyDate(2022, 3, 19).toPackedUInt(), | ||
MyDate(1900, 12, 31).toPackedUInt(), | ||
MyDate(2020, 12, 31).toPackedUInt(), | ||
MyDate(2022, 12, 31).toPackedUInt(), | ||
}) | ||
.column; | ||
input_col = ColumnWithTypeAndName(data_col_ptr, date_type_ptr, "input"); | ||
output_col = createColumn<UInt16>({2, 72, 73, 74, 75, 76, 77, 78, 365, 366, 365}); | ||
ASSERT_COLUMN_EQ(output_col, executeFunction(func_name, input_col)); | ||
} | ||
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,42 @@ | ||
# 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 test.t(a char(20), b datetime, c date); | ||
mysql> insert into test.t values('', '1970-1-1 12:12:12', '1970-1-1'); | ||
mysql> insert into test.t values('123', '1989-6-6 12:12:12', '1989-6-6'); | ||
mysql> insert into test.t values('2022-3-10', '2000-3-4 12:12:12', '2000-3-4'); | ||
mysql> alter table test.t set tiflash replica 1; | ||
|
||
func> wait_table test t | ||
|
||
mysql> set @@tidb_isolation_read_engines='tiflash'; set @@tidb_enforce_mpp = 1; select dayofweek(a), dayofweek(b), dayofweek(c) from test.t; | ||
+--------------+--------------+--------------+ | ||
| dayofweek(a) | dayofweek(b) | dayofweek(c) | | ||
+--------------+--------------+--------------+ | ||
| NULL | 5 | 5 | | ||
| NULL | 3 | 3 | | ||
| 5 | 7 | 7 | | ||
+--------------+--------------+--------------+ | ||
|
||
mysql> set @@tidb_isolation_read_engines='tiflash'; set @@tidb_enforce_mpp = 1; select dayofyear(a), dayofyear(b), dayofyear(c) from test.t; | ||
+--------------+--------------+--------------+ | ||
| dayofyear(a) | dayofyear(b) | dayofyear(c) | | ||
+--------------+--------------+--------------+ | ||
| NULL | 1 | 1 | | ||
| NULL | 157 | 157 | | ||
| 69 | 64 | 64 | | ||
+--------------+--------------+--------------+ | ||
|
||
mysql> drop table if exists test.t; |