Skip to content

Commit a133389

Browse files
authored
Merge pull request #10791 from oandrew/key-condition-source-type
Use src_type for conversion in KeyCondition
2 parents 5115ac2 + 1ee875a commit a133389

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

src/Storages/MergeTree/KeyCondition.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,7 @@ static void castValueToType(const DataTypePtr & desired_type, Field & src_value,
710710

711711
try
712712
{
713-
/// NOTE: We don't need accurate info about src_type at this moment
714-
src_value = convertFieldToType(src_value, *desired_type);
713+
src_value = convertFieldToType(src_value, *desired_type, src_type.get());
715714
}
716715
catch (...)
717716
{
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
['2020-01-01 10:00:00']
2+
['2020-01-02 00:00:00']
3+
['2020-01-01 00:00:00','2020-01-01 10:00:00']
4+
['2020-01-01 00:00:00','2020-01-01 10:00:00','2020-01-02 00:00:00']
5+
['2020-01-01 00:00:00','2020-01-01 10:00:00','2020-01-02 00:00:00']
6+
['2020-01-01 00:00:00','2020-01-01 10:00:00','2020-01-02 00:00:00']
7+
['2020-01-01 00:00:00','2020-01-01 10:00:00','2020-01-02 00:00:00']
8+
[]
9+
[]
10+
[]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
DROP TABLE IF EXISTS test.date_datetime_key_condition;
2+
3+
CREATE TABLE test.date_datetime_key_condition (dt DateTime) ENGINE = MergeTree() ORDER BY dt;
4+
INSERT INTO test.date_datetime_key_condition VALUES ('2020-01-01 00:00:00'), ('2020-01-01 10:00:00'), ('2020-01-02 00:00:00');
5+
6+
-- partial
7+
SELECT groupArray(dt) from test.date_datetime_key_condition WHERE dt > toDate('2020-01-01') AND dt < toDate('2020-01-02');
8+
SELECT groupArray(dt) from test.date_datetime_key_condition WHERE dt >= toDate('2020-01-02');
9+
SELECT groupArray(dt) from test.date_datetime_key_condition WHERE dt < toDate('2020-01-02');
10+
11+
-- inside
12+
SELECT groupArray(dt) from test.date_datetime_key_condition WHERE dt > toDate('2019-01-02');
13+
SELECT groupArray(dt) from test.date_datetime_key_condition WHERE dt < toDate('2021-01-02');
14+
SELECT groupArray(dt) from test.date_datetime_key_condition WHERE dt >= toDate('2019-01-02') AND dt < toDate('2021-01-02');
15+
SELECT groupArray(dt) from test.date_datetime_key_condition WHERE dt > toDate('2019-01-02') OR dt <= toDate('2021-01-02');
16+
17+
-- outside
18+
SELECT groupArray(dt) from test.date_datetime_key_condition WHERE dt < toDate('2019-01-02');
19+
SELECT groupArray(dt) from test.date_datetime_key_condition WHERE dt > toDate('2021-01-02');
20+
SELECT groupArray(dt) from test.date_datetime_key_condition WHERE dt < toDate('2019-01-02') OR dt > toDate('2021-01-02');
21+
22+
DROP TABLE test.date_datetime_key_condition;

0 commit comments

Comments
 (0)