mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 01:51:59 +00:00
Merge pull request #50287 from kitaisreal/function-equals-nan-fix
Comparison functions NaN fix
This commit is contained in:
commit
e1d535c890
@ -1230,8 +1230,11 @@ public:
|
||||
/// The case when arguments are the same (tautological comparison). Return constant.
|
||||
/// NOTE: Nullable types are special case.
|
||||
/// (BTW, this function use default implementation for Nullable, so Nullable types cannot be here. Check just in case.)
|
||||
/// NOTE: We consider NaN comparison to be implementation specific (and in our implementation NaNs are sometimes equal sometimes not).
|
||||
if (left_type->equals(*right_type) && !left_type->isNullable() && !isTuple(left_type) && col_left_untyped == col_right_untyped)
|
||||
if (left_type->equals(*right_type) &&
|
||||
!left_type->isNullable() &&
|
||||
!isTuple(left_type) &&
|
||||
!WhichDataType(left_type).isFloat() &&
|
||||
col_left_untyped == col_right_untyped)
|
||||
{
|
||||
ColumnPtr result_column;
|
||||
|
||||
|
@ -0,0 +1,10 @@
|
||||
nan 0 0 0 0
|
||||
nan 0 0 0 0
|
||||
nan nan 0 0 0 0
|
||||
--
|
||||
--
|
||||
nan 1 1 1 1
|
||||
nan 1 1 1 1
|
||||
nan nan 1 1 1 1
|
||||
--
|
||||
nan
|
42
tests/queries/0_stateless/02769_nan_equality_comparison.sql
Normal file
42
tests/queries/0_stateless/02769_nan_equality_comparison.sql
Normal file
@ -0,0 +1,42 @@
|
||||
SET compile_expressions = 1;
|
||||
SET min_count_to_compile_expression = 0;
|
||||
|
||||
SELECT nan AS value, value = value, value = materialize(value), materialize(value) = value, materialize(value) = materialize(value);
|
||||
SELECT cast(nan, 'Float32') AS value, value = value, value = materialize(value), materialize(value) = value, materialize(value) = materialize(value);
|
||||
SELECT nan AS lhs, cast(nan, 'Float32') AS rhs, lhs = rhs, lhs = materialize(rhs), materialize(lhs) = rhs, materialize(lhs) = materialize(rhs);
|
||||
|
||||
SELECT '--';
|
||||
|
||||
CREATE TABLE test_table
|
||||
(
|
||||
id UInt32,
|
||||
value UInt32
|
||||
) ENGINE = MergeTree ORDER BY id;
|
||||
INSERT INTO test_table VALUES (76, 57);
|
||||
|
||||
SELECT value FROM (SELECT stddevSamp(id) AS value FROM test_table) as subquery
|
||||
WHERE ((value = value) AND (NOT (value = value)));
|
||||
|
||||
DROP TABLE test_table;
|
||||
|
||||
SELECT '--';
|
||||
|
||||
SELECT nan AS value, value != value, value != materialize(value), materialize(value) != value, materialize(value) != materialize(value);
|
||||
SELECT cast(nan, 'Float32') AS value, value != value, value != materialize(value), materialize(value) != value, materialize(value) != materialize(value);
|
||||
SELECT nan AS lhs, cast(nan, 'Float32') AS rhs, lhs != rhs, lhs != materialize(rhs), materialize(lhs) != rhs, materialize(lhs) != materialize(rhs);
|
||||
|
||||
SELECT '--';
|
||||
|
||||
CREATE TABLE test_table
|
||||
(
|
||||
id UInt32,
|
||||
value_1 UInt32,
|
||||
value_2 Float32
|
||||
) ENGINE = MergeTree ORDER BY id;
|
||||
INSERT INTO test_table VALUES (12000, 36, 77.94);
|
||||
|
||||
SELECT value
|
||||
FROM (SELECT (corr(value_1, value_1) OVER test_window) AS value FROM test_table WINDOW test_window AS (PARTITION BY value_2 ORDER BY id ASC)) as subquery
|
||||
WHERE not (not (value <> value));
|
||||
|
||||
DROP TABLE test_table;
|
Loading…
Reference in New Issue
Block a user