mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 00:30:49 +00:00
Backport #60150 to 23.8: Fix cosineDistance crash with Nullable
This commit is contained in:
parent
2c48367f25
commit
3ec5f0d025
@ -509,7 +509,7 @@ Result:
|
|||||||
|
|
||||||
## cosineDistance
|
## cosineDistance
|
||||||
|
|
||||||
Calculates the cosine distance between two vectors (the values of the tuples are the coordinates). The less the returned value is, the more similar are the vectors.
|
Calculates the cosine distance between two vectors (the values of the tuples are the coordinates). The smaller the returned value is, the more similar are the vectors.
|
||||||
|
|
||||||
**Syntax**
|
**Syntax**
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#include <Columns/ColumnTuple.h>
|
#include <Columns/ColumnTuple.h>
|
||||||
#include <DataTypes/DataTypeArray.h>
|
#include <DataTypes/DataTypeArray.h>
|
||||||
#include <DataTypes/DataTypeInterval.h>
|
#include <DataTypes/DataTypeInterval.h>
|
||||||
|
#include <DataTypes/DataTypeNullable.h>
|
||||||
#include <DataTypes/DataTypeTuple.h>
|
#include <DataTypes/DataTypeTuple.h>
|
||||||
#include <DataTypes/DataTypesNumber.h>
|
#include <DataTypes/DataTypesNumber.h>
|
||||||
#include <DataTypes/DataTypeNothing.h>
|
|
||||||
#include <Functions/FunctionFactory.h>
|
#include <Functions/FunctionFactory.h>
|
||||||
#include <Functions/FunctionHelpers.h>
|
#include <Functions/FunctionHelpers.h>
|
||||||
#include <Functions/ITupleFunction.h>
|
#include <Functions/ITupleFunction.h>
|
||||||
@ -1364,11 +1364,11 @@ public:
|
|||||||
|
|
||||||
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override
|
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override
|
||||||
{
|
{
|
||||||
if (getReturnTypeImpl(arguments)->isNullable())
|
/// TODO: cosineDistance does not support nullable arguments
|
||||||
{
|
/// https://github.com/ClickHouse/ClickHouse/pull/27933#issuecomment-916670286
|
||||||
return DataTypeNullable(std::make_shared<DataTypeNothing>())
|
auto return_type = getReturnTypeImpl(arguments);
|
||||||
.createColumnConstWithDefaultValue(input_rows_count);
|
if (return_type->isNullable())
|
||||||
}
|
return return_type->createColumnConstWithDefaultValue(input_rows_count);
|
||||||
|
|
||||||
FunctionDotProduct dot(context);
|
FunctionDotProduct dot(context);
|
||||||
ColumnWithTypeAndName dot_result{dot.executeImpl(arguments, DataTypePtr(), input_rows_count),
|
ColumnWithTypeAndName dot_result{dot.executeImpl(arguments, DataTypePtr(), input_rows_count),
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
\N
|
||||||
|
\N
|
||||||
|
\N
|
||||||
|
\N
|
||||||
|
\N
|
||||||
|
\N
|
||||||
|
\N
|
||||||
|
\N
|
||||||
|
\N
|
||||||
|
\N
|
||||||
|
\N
|
@ -0,0 +1,3 @@
|
|||||||
|
-- https://github.com/ClickHouse/ClickHouse/issues/59596
|
||||||
|
SELECT cosineDistance((1, 1), (toNullable(0.5), 0.1));
|
||||||
|
SELECT cosineDistance((1, 1), (toNullable(0.5), 0.1)) from numbers(10);
|
Loading…
Reference in New Issue
Block a user