From b065839f440495c5f182de34ea02339c16d3e127 Mon Sep 17 00:00:00 2001 From: Alexander Gololobov <440544+davenger@users.noreply.github.com> Date: Wed, 25 May 2022 16:29:12 +0200 Subject: [PATCH] always return Float64 --- src/Functions/array/arrayDistance.cpp | 4 --- src/Functions/array/arrayNorm.cpp | 4 --- .../02282_array_distance.reference | 29 ++++++++++--------- .../0_stateless/02282_array_distance.sql | 8 +++++ .../0_stateless/02283_array_norm.reference | 19 ++++++------ .../queries/0_stateless/02283_array_norm.sql | 7 +++++ 6 files changed, 40 insertions(+), 31 deletions(-) diff --git a/src/Functions/array/arrayDistance.cpp b/src/Functions/array/arrayDistance.cpp index 87b8f1979f7..87e53193139 100644 --- a/src/Functions/array/arrayDistance.cpp +++ b/src/Functions/array/arrayDistance.cpp @@ -145,7 +145,6 @@ public: case TypeIndex::Int16: case TypeIndex::Int32: case TypeIndex::Float32: - return std::make_shared(); case TypeIndex::UInt64: case TypeIndex::Int64: case TypeIndex::Float64: @@ -164,9 +163,6 @@ public: { switch (result_type->getTypeId()) { - case TypeIndex::Float32: - return executeWithResultType(arguments, input_rows_count); - break; case TypeIndex::Float64: return executeWithResultType(arguments, input_rows_count); break; diff --git a/src/Functions/array/arrayNorm.cpp b/src/Functions/array/arrayNorm.cpp index 19ca43d34f5..b166d1f2e7e 100644 --- a/src/Functions/array/arrayNorm.cpp +++ b/src/Functions/array/arrayNorm.cpp @@ -102,7 +102,6 @@ public: case TypeIndex::Int16: case TypeIndex::Int32: case TypeIndex::Float32: - return std::make_shared(); case TypeIndex::UInt64: case TypeIndex::Int64: case TypeIndex::Float64: @@ -125,9 +124,6 @@ public: switch (result_type->getTypeId()) { - case TypeIndex::Float32: - return executeWithResultType(*arr, type, input_rows_count); - break; case TypeIndex::Float64: return executeWithResultType(*arr, type, input_rows_count); break; diff --git a/tests/queries/0_stateless/02282_array_distance.reference b/tests/queries/0_stateless/02282_array_distance.reference index 2fd6c66c817..b7db2dceee8 100644 --- a/tests/queries/0_stateless/02282_array_distance.reference +++ b/tests/queries/0_stateless/02282_array_distance.reference @@ -1,21 +1,22 @@ 6 -3.7416575 +3.7416573867739413 3 -0.002585097 +0.00258509695694209 \N nan +0 0 0 0 12 14 21 -7.071068 -9.165152 -12.124355 +7.0710678118654755 +9.16515138991168 +12.12435565298214 2 5 4 -0.16847816 -0.35846698 -0.0741799 +0.16847815937970012 +0.3584669721282153 +0.07417990022744847 6 8 9 @@ -28,12 +29,12 @@ nan 2 2 1347.4008312302617 3 1 214.35251339790725 3 2 1342.8856987845243 -1 1 218.74643 -1 2 1348.2118 -2 1 219.28064 -2 2 1347.4009 -3 1 214.35251 -3 2 1342.8857 +1 1 218.74642854227358 +1 2 1348.2117786164013 +2 1 219.28064210048274 +2 2 1347.4008312302617 +3 1 214.35251339790725 +3 2 1342.8856987845243 1 1 218.74642854227358 1 2 1348.2117786164013 2 1 219.28064210048274 diff --git a/tests/queries/0_stateless/02282_array_distance.sql b/tests/queries/0_stateless/02282_array_distance.sql index 04de01d7d66..89214c57441 100644 --- a/tests/queries/0_stateless/02282_array_distance.sql +++ b/tests/queries/0_stateless/02282_array_distance.sql @@ -6,6 +6,14 @@ SELECT arrayCosineDistance([1, 2, 3], [3, 5, 7]); SELECT arrayL2Distance([1, 2, 3], NULL); SELECT arrayCosineDistance([1, 2, 3], [0, 0, 0]); +-- Overflows +WITH CAST([-547274980, 1790553898, 1981517754, 1908431500, 1352428565, -573412550, -552499284, 2096941042], 'Array(Int32)') AS a +SELECT + arrayL1Distance(a,a), + arrayL2Distance(a,a), + arrayLinfDistance(a,a), + arrayCosineDistance(a, a); + DROP TABLE IF EXISTS vec1; DROP TABLE IF EXISTS vec2; DROP TABLE IF EXISTS vec2f; diff --git a/tests/queries/0_stateless/02283_array_norm.reference b/tests/queries/0_stateless/02283_array_norm.reference index 6dd6b79e6d9..68dbce0b436 100644 --- a/tests/queries/0_stateless/02283_array_norm.reference +++ b/tests/queries/0_stateless/02283_array_norm.reference @@ -1,17 +1,18 @@ 6 7.0710678118654755 2 +10803059573 4234902446.7343364 2096941042 1 5 2 2 -3 5.196152 -4 0 -1 11 -2 11 -3 11 -4 11 -1 5 -2 2 -3 5.196152 +3 5.196152422706632 +4 0 +1 11 +2 11 +3 11 +4 11 +1 5 +2 2 +3 5.196152422706632 4 0 1 11 2 11 diff --git a/tests/queries/0_stateless/02283_array_norm.sql b/tests/queries/0_stateless/02283_array_norm.sql index e11caea7cc1..a759a47d79c 100644 --- a/tests/queries/0_stateless/02283_array_norm.sql +++ b/tests/queries/0_stateless/02283_array_norm.sql @@ -2,6 +2,13 @@ SELECT arrayL1Norm([1, 2, 3]); SELECT arrayL2Norm([3., 4., 5.]); SELECT arrayLinfNorm([0, 0, 2]); +-- Overflows +WITH CAST([-547274980, 1790553898, 1981517754, 1908431500, 1352428565, -573412550, -552499284, 2096941042], 'Array(Int32)') AS a +SELECT + arrayL1Norm(a), + arrayL2Norm(a), + arrayLinfNorm(a); + DROP TABLE IF EXISTS vec1; DROP TABLE IF EXISTS vec1f; DROP TABLE IF EXISTS vec1d;