mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-19 16:20:50 +00:00
Merge pull request #61766 from ditgittube/master_fix_window
Fix RANGE frame is not supported for Nullable columns.
This commit is contained in:
commit
233a75505b
@ -10,6 +10,7 @@
|
||||
#include <base/arithmeticOverflow.h>
|
||||
#include <Columns/ColumnConst.h>
|
||||
#include <Columns/ColumnAggregateFunction.h>
|
||||
#include <Columns/ColumnNullable.h>
|
||||
#include <DataTypes/DataTypesNumber.h>
|
||||
#include <DataTypes/getLeastSupertype.h>
|
||||
#include <DataTypes/DataTypeLowCardinality.h>
|
||||
@ -172,6 +173,79 @@ static int compareValuesWithOffsetFloat(const IColumn * _compared_column,
|
||||
return result;
|
||||
}
|
||||
|
||||
// Helper macros to dispatch on type of the ORDER BY column
|
||||
#define APPLY_FOR_ONE_NEST_TYPE(FUNCTION, TYPE) \
|
||||
else if (typeid_cast<const TYPE *>(nest_compared_column.get())) \
|
||||
{ \
|
||||
/* clang-tidy you're dumb, I can't put FUNCTION in braces here. */ \
|
||||
nest_compare_function = FUNCTION<TYPE>; /* NOLINT */ \
|
||||
}
|
||||
|
||||
#define APPLY_FOR_NEST_TYPES(FUNCTION) \
|
||||
if (false) /* NOLINT */ \
|
||||
{ \
|
||||
/* Do nothing, a starter condition. */ \
|
||||
} \
|
||||
APPLY_FOR_ONE_NEST_TYPE(FUNCTION, ColumnVector<UInt8>) \
|
||||
APPLY_FOR_ONE_NEST_TYPE(FUNCTION, ColumnVector<UInt16>) \
|
||||
APPLY_FOR_ONE_NEST_TYPE(FUNCTION, ColumnVector<UInt32>) \
|
||||
APPLY_FOR_ONE_NEST_TYPE(FUNCTION, ColumnVector<UInt64>) \
|
||||
\
|
||||
APPLY_FOR_ONE_NEST_TYPE(FUNCTION, ColumnVector<Int8>) \
|
||||
APPLY_FOR_ONE_NEST_TYPE(FUNCTION, ColumnVector<Int16>) \
|
||||
APPLY_FOR_ONE_NEST_TYPE(FUNCTION, ColumnVector<Int32>) \
|
||||
APPLY_FOR_ONE_NEST_TYPE(FUNCTION, ColumnVector<Int64>) \
|
||||
APPLY_FOR_ONE_NEST_TYPE(FUNCTION, ColumnVector<Int128>) \
|
||||
\
|
||||
APPLY_FOR_ONE_NEST_TYPE(FUNCTION##Float, ColumnVector<Float32>) \
|
||||
APPLY_FOR_ONE_NEST_TYPE(FUNCTION##Float, ColumnVector<Float64>) \
|
||||
\
|
||||
else \
|
||||
{ \
|
||||
throw Exception(ErrorCodes::NOT_IMPLEMENTED, \
|
||||
"The RANGE OFFSET frame for '{}' ORDER BY nest column is not implemented", \
|
||||
demangle(typeid(nest_compared_column).name())); \
|
||||
}
|
||||
|
||||
// A specialization of compareValuesWithOffset for nullable.
|
||||
template <typename ColumnType>
|
||||
static int compareValuesWithOffsetNullable(const IColumn * _compared_column,
|
||||
size_t compared_row, const IColumn * _reference_column,
|
||||
size_t reference_row,
|
||||
const Field & _offset,
|
||||
bool offset_is_preceding)
|
||||
{
|
||||
const auto * compared_column = assert_cast<const ColumnType *>(
|
||||
_compared_column);
|
||||
const auto * reference_column = assert_cast<const ColumnType *>(
|
||||
_reference_column);
|
||||
|
||||
if (compared_column->isNullAt(compared_row) && !reference_column->isNullAt(reference_row))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (compared_column->isNullAt(compared_row) && reference_column->isNullAt(reference_row))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (!compared_column->isNullAt(compared_row) && reference_column->isNullAt(reference_row))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
ColumnPtr nest_compared_column = compared_column->getNestedColumnPtr();
|
||||
ColumnPtr nest_reference_column = reference_column->getNestedColumnPtr();
|
||||
|
||||
std::function<int(
|
||||
const IColumn * compared_column, size_t compared_row,
|
||||
const IColumn * reference_column, size_t reference_row,
|
||||
const Field & offset,
|
||||
bool offset_is_preceding)> nest_compare_function;
|
||||
APPLY_FOR_NEST_TYPES(compareValuesWithOffset)
|
||||
return nest_compare_function(nest_compared_column.get(), compared_row,
|
||||
nest_reference_column.get(), reference_row, _offset, offset_is_preceding);
|
||||
}
|
||||
|
||||
// Helper macros to dispatch on type of the ORDER BY column
|
||||
#define APPLY_FOR_ONE_TYPE(FUNCTION, TYPE) \
|
||||
else if (typeid_cast<const TYPE *>(column)) \
|
||||
@ -199,6 +273,7 @@ APPLY_FOR_ONE_TYPE(FUNCTION, ColumnVector<Int128>) \
|
||||
APPLY_FOR_ONE_TYPE(FUNCTION##Float, ColumnVector<Float32>) \
|
||||
APPLY_FOR_ONE_TYPE(FUNCTION##Float, ColumnVector<Float64>) \
|
||||
\
|
||||
APPLY_FOR_ONE_TYPE(FUNCTION##Nullable, ColumnNullable) \
|
||||
else \
|
||||
{ \
|
||||
throw Exception(ErrorCodes::NOT_IMPLEMENTED, \
|
||||
|
@ -0,0 +1,5 @@
|
||||
1 4
|
||||
1 4
|
||||
2 5
|
||||
3 3
|
||||
\N \N
|
@ -0,0 +1,4 @@
|
||||
SELECT
|
||||
number,
|
||||
sum(number) OVER (ORDER BY number ASC RANGE BETWEEN CURRENT ROW AND 1 FOLLOWING) AS sum
|
||||
FROM values('number Nullable(Int8)', 1, 1, 2, 3, NULL)
|
Loading…
Reference in New Issue
Block a user