-
Notifications
You must be signed in to change notification settings - Fork 409
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
Add to_seconds support for tiflash #4866
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
380e28c
Add to_seconds support for tiflash
yibin87 16a39ee
Fix format issue
yibin87 e4dbeff
Disable the test that is different from tidb when tidb push down is n…
yibin87 95baddd
Merge branch 'master' into dev_feature_branch
ti-chi-bot bad7d14
Merge branch 'master' into dev_feature_branch
ti-chi-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,100 @@ | ||
// 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 TestToSeconds : public DB::tests::FunctionTest | ||
{ | ||
}; | ||
|
||
TEST_F(TestToSeconds, TestAll) | ||
try | ||
{ | ||
DAGContext * dag_context = context.getDAGContext(); | ||
UInt64 ori_flags = dag_context->getFlags(); | ||
dag_context->addFlag(TiDBSQLFlags::TRUNCATE_AS_WARNING); | ||
/// ColumnVector(nullable) | ||
const String func_name = "tidbToSeconds"; | ||
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 | ||
MyDateTime(0, 0, 0, 0, 0, 0, 0).toPackedUInt(), | ||
MyDateTime(0, 1, 1, 0, 0, 0, 0).toPackedUInt(), | ||
MyDateTime(1969, 1, 2, 1, 1, 1, 1).toPackedUInt(), | ||
MyDateTime(2000, 12, 31, 10, 10, 10, 700).toPackedUInt(), | ||
MyDateTime(2022, 3, 13, 6, 7, 8, 9).toPackedUInt(), | ||
}) | ||
.column; | ||
auto input_col = ColumnWithTypeAndName(data_col_ptr, nullable_datetime_type_ptr, "input"); | ||
auto output_col = createColumn<Nullable<UInt64>>({{}, {}, 86400, 62135773261ULL, 63145476610ULL, 63814370828ULL}); | ||
ASSERT_COLUMN_EQ(output_col, executeFunction(func_name, input_col)); | ||
|
||
/// ColumnVector(non-null) | ||
data_col_ptr = createColumn<DataTypeMyDateTime::FieldType>( | ||
{ | ||
MyDateTime(0, 0, 0, 0, 0, 0, 0).toPackedUInt(), | ||
MyDateTime(1969, 1, 2, 1, 1, 1, 1).toPackedUInt(), | ||
MyDateTime(2000, 12, 31, 10, 10, 10, 700).toPackedUInt(), | ||
MyDateTime(2022, 3, 13, 6, 7, 8, 9).toPackedUInt(), | ||
}) | ||
.column; | ||
input_col = ColumnWithTypeAndName(data_col_ptr, datetime_type_ptr, "input"); | ||
output_col = createColumn<Nullable<UInt64>>({{}, 62135773261ULL, 63145476610ULL, 63814370828ULL}); | ||
ASSERT_COLUMN_EQ(output_col, executeFunction(func_name, input_col)); | ||
|
||
/// ColumnConst(non-null) | ||
input_col = ColumnWithTypeAndName(createConstColumn<DataTypeMyDateTime::FieldType>(1, MyDateTime(2022, 3, 13, 6, 7, 8, 9).toPackedUInt()).column, datetime_type_ptr, "input"); | ||
output_col = createConstColumn<Nullable<UInt64>>(1, {63814370828ULL}); | ||
ASSERT_COLUMN_EQ(output_col, executeFunction(func_name, input_col)); | ||
|
||
/// ColumnConst(nullable) | ||
input_col = ColumnWithTypeAndName(createConstColumn<Nullable<DataTypeMyDateTime::FieldType>>(1, MyDateTime(2022, 3, 13, 6, 7, 8, 9).toPackedUInt()).column, nullable_datetime_type_ptr, "input"); | ||
output_col = createConstColumn<Nullable<UInt64>>(1, {63814370828ULL}); | ||
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<UInt64>>(1, {}); | ||
ASSERT_COLUMN_EQ(output_col, executeFunction(func_name, input_col)); | ||
|
||
/// MyDate ColumnVector(non-null) | ||
data_col_ptr = createColumn<DataTypeMyDate::FieldType>( | ||
{ | ||
MyDate(0000, 0, 1).toPackedUInt(), | ||
MyDate(0000, 1, 1).toPackedUInt(), | ||
MyDate(1969, 1, 1).toPackedUInt(), | ||
MyDate(2000, 12, 1).toPackedUInt(), | ||
MyDate(2022, 3, 14).toPackedUInt(), | ||
}) | ||
.column; | ||
input_col = ColumnWithTypeAndName(data_col_ptr, date_type_ptr, "input"); | ||
output_col = createColumn<Nullable<UInt64>>({{}, 86400, 62135683200ULL, 63142848000ULL, 63814435200ULL}); | ||
ASSERT_COLUMN_EQ(output_col, executeFunction(func_name, input_col)); | ||
dag_context->setFlags(ori_flags); | ||
} | ||
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,61 @@ | ||
# 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.t1; | ||
mysql> create table test.t1(c1 varchar(100), c2 datetime, c3 date); | ||
mysql> insert into test.t1 values('', '1999-10-10 10:10:10.123', '1999-01-10'), ('200', '1999-02-10 10:10:10.123', '1999-11-10'), ('1999-01-10', '1999-10-10 10:10:10.123', '1999-01-10'); | ||
# leap year | ||
mysql> insert into test.t1 values('2000-2-10', '2000-2-10 10:10:10', '2000-2-10'); | ||
# non leap year | ||
mysql> insert into test.t1 values('2001-2-10', '2001-2-10 10:10:10', '2001-2-10'); | ||
# zero day | ||
mysql> insert into test.t1 values('2000-2-0', '2000-2-10 10:10:10', '2000-2-10'); | ||
mysql> alter table test.t1 set tiflash replica 1; | ||
func> wait_table test t1 | ||
mysql> set @@tidb_isolation_read_engines='tiflash'; set @@tidb_enforce_mpp = 1; select c1, to_seconds(c1) from test.t1 order by 1; | ||
+------------+----------------+ | ||
| c1 | to_seconds(c1) | | ||
+------------+----------------+ | ||
| | NULL | | ||
| 1999-01-10 | 63083145600 | | ||
| 200 | NULL | | ||
| 2000-2-0 | NULL | | ||
| 2000-2-10 | 63117360000 | | ||
| 2001-2-10 | 63148982400 | | ||
+------------+----------------+ | ||
mysql> set @@tidb_isolation_read_engines='tiflash'; set @@tidb_enforce_mpp = 1; select c2, to_seconds(c2) from test.t1 order by 1; | ||
+---------------------+----------------+ | ||
| c2 | to_seconds(c2) | | ||
+---------------------+----------------+ | ||
| 1999-02-10 10:10:10 | 63085860610 | | ||
| 1999-10-10 10:10:10 | 63106769410 | | ||
| 1999-10-10 10:10:10 | 63106769410 | | ||
| 2000-02-10 10:10:10 | 63117396610 | | ||
| 2000-02-10 10:10:10 | 63117396610 | | ||
| 2001-02-10 10:10:10 | 63149019010 | | ||
+---------------------+----------------+ | ||
mysql> set @@tidb_isolation_read_engines='tiflash'; set @@tidb_enforce_mpp = 1; select c3, to_seconds(c3) from test.t1 order by 1; | ||
+------------+----------------+ | ||
| c3 | to_seconds(c3) | | ||
+------------+----------------+ | ||
| 1999-01-10 | 63083145600 | | ||
| 1999-01-10 | 63083145600 | | ||
| 1999-11-10 | 63109411200 | | ||
| 2000-02-10 | 63117360000 | | ||
| 2000-02-10 | 63117360000 | | ||
| 2001-02-10 | 63148982400 | | ||
+------------+----------------+ | ||
|
||
mysql> drop table if exists test.t1; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems a TiDB bug, please fire a issue for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK,I'll fire one later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pingcap/tidb#34629