mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Merge pull request #10110 from amosbird/tsm
more monotonicity for toString()
This commit is contained in:
commit
0372a6119a
@ -24,6 +24,12 @@ const Type * checkAndGetDataType(const IDataType * data_type)
|
||||
return typeid_cast<const Type *>(data_type);
|
||||
}
|
||||
|
||||
template <typename... Types>
|
||||
bool checkDataTypes(const IDataType * data_type)
|
||||
{
|
||||
return (... || typeid_cast<const Types *>(data_type));
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
const ColumnConst * checkAndGetColumnConst(const IColumn * column)
|
||||
{
|
||||
|
@ -1496,10 +1496,12 @@ struct ToStringMonotonicity
|
||||
IFunction::Monotonicity positive(true, true);
|
||||
IFunction::Monotonicity not_monotonic;
|
||||
|
||||
/// `toString` function is monotonous if the argument is Date or DateTime, or non-negative numbers with the same number of symbols.
|
||||
auto type_ptr = &type;
|
||||
if (auto * low_cardinality_type = checkAndGetDataType<DataTypeLowCardinality>(type_ptr))
|
||||
type_ptr = low_cardinality_type->getDictionaryType().get();
|
||||
|
||||
if (checkAndGetDataType<DataTypeDate>(&type)
|
||||
|| typeid_cast<const DataTypeDateTime *>(&type))
|
||||
/// `toString` function is monotonous if the argument is Date or DateTime or String, or non-negative numbers with the same number of symbols.
|
||||
if (checkDataTypes<DataTypeDate, DataTypeDateTime, DataTypeString>(type_ptr))
|
||||
return positive;
|
||||
|
||||
if (left.isNull() || right.isNull())
|
||||
|
@ -0,0 +1,2 @@
|
||||
1234
|
||||
1234
|
14
tests/queries/0_stateless/01234_to_string_monotonic.sql
Normal file
14
tests/queries/0_stateless/01234_to_string_monotonic.sql
Normal file
@ -0,0 +1,14 @@
|
||||
DROP TABLE IF EXISTS test1;
|
||||
DROP TABLE IF EXISTS test2;
|
||||
|
||||
CREATE TABLE test1 (s String) ENGINE = MergeTree ORDER BY s SETTINGS index_granularity = 1;
|
||||
CREATE TABLE test2 (s LowCardinality(String)) ENGINE = MergeTree ORDER BY s SETTINGS index_granularity = 1;
|
||||
|
||||
INSERT INTO test1 SELECT toString(number) FROM numbers(10000);
|
||||
INSERT INTO test2 SELECT toString(number) FROM numbers(10000);
|
||||
|
||||
SELECT s FROM test1 WHERE toString(s) = '1234' SETTINGS max_rows_to_read = 2;
|
||||
SELECT s FROM test2 WHERE toString(s) = '1234' SETTINGS max_rows_to_read = 2;
|
||||
|
||||
DROP TABLE test1;
|
||||
DROP TABLE test2;
|
Loading…
Reference in New Issue
Block a user