mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-18 12:22:12 +00:00
Backport #66654 to 24.6: Disable getConstantResultForNonConstArguments for IS NULL with old analyzer
This commit is contained in:
parent
754d0d94e1
commit
f55f4b95ac
@ -22,7 +22,9 @@ class FunctionIsNotNull : public IFunction
|
||||
public:
|
||||
static constexpr auto name = "isNotNull";
|
||||
|
||||
static FunctionPtr create(ContextPtr) { return std::make_shared<FunctionIsNotNull>(); }
|
||||
static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionIsNotNull>(context->getSettingsRef().allow_experimental_analyzer); }
|
||||
|
||||
explicit FunctionIsNotNull(bool use_analyzer_) : use_analyzer(use_analyzer_) {}
|
||||
|
||||
std::string getName() const override
|
||||
{
|
||||
@ -31,6 +33,10 @@ public:
|
||||
|
||||
ColumnPtr getConstantResultForNonConstArguments(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type) const override
|
||||
{
|
||||
/// (column IS NULL) triggers a bug in old analyzer when it is replaced to constant.
|
||||
if (!use_analyzer)
|
||||
return nullptr;
|
||||
|
||||
const ColumnWithTypeAndName & elem = arguments[0];
|
||||
if (elem.type->onlyNull())
|
||||
return result_type->createColumnConst(1, UInt8(0));
|
||||
@ -123,6 +129,8 @@ private:
|
||||
#endif
|
||||
vectorImpl(null_map, res);
|
||||
}
|
||||
|
||||
bool use_analyzer;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <Columns/ColumnLowCardinality.h>
|
||||
#include <Columns/ColumnVariant.h>
|
||||
#include <Columns/ColumnDynamic.h>
|
||||
#include <Core/Settings.h>
|
||||
#include <Interpreters/Context.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
@ -21,11 +23,13 @@ class FunctionIsNull : public IFunction
|
||||
public:
|
||||
static constexpr auto name = "isNull";
|
||||
|
||||
static FunctionPtr create(ContextPtr)
|
||||
static FunctionPtr create(ContextPtr context)
|
||||
{
|
||||
return std::make_shared<FunctionIsNull>();
|
||||
return std::make_shared<FunctionIsNull>(context->getSettingsRef().allow_experimental_analyzer);
|
||||
}
|
||||
|
||||
explicit FunctionIsNull(bool use_analyzer_) : use_analyzer(use_analyzer_) {}
|
||||
|
||||
std::string getName() const override
|
||||
{
|
||||
return name;
|
||||
@ -33,6 +37,10 @@ public:
|
||||
|
||||
ColumnPtr getConstantResultForNonConstArguments(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type) const override
|
||||
{
|
||||
/// (column IS NULL) triggers a bug in old analyzer when it is replaced to constant.
|
||||
if (!use_analyzer)
|
||||
return nullptr;
|
||||
|
||||
const ColumnWithTypeAndName & elem = arguments[0];
|
||||
if (elem.type->onlyNull())
|
||||
return result_type->createColumnConst(1, UInt8(1));
|
||||
@ -95,6 +103,9 @@ public:
|
||||
return DataTypeUInt8().createColumnConst(elem.column->size(), 0u);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool use_analyzer;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include <DataTypes/DataTypesNumber.h>
|
||||
#include <Columns/ColumnsNumber.h>
|
||||
#include <DataTypes/DataTypeNullable.h>
|
||||
#include <Core/Settings.h>
|
||||
#include <Interpreters/Context.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
@ -14,11 +16,13 @@ class FunctionIsNullable : public IFunction
|
||||
{
|
||||
public:
|
||||
static constexpr auto name = "isNullable";
|
||||
static FunctionPtr create(ContextPtr)
|
||||
static FunctionPtr create(ContextPtr context)
|
||||
{
|
||||
return std::make_shared<FunctionIsNullable>();
|
||||
return std::make_shared<FunctionIsNullable>(context->getSettingsRef().allow_experimental_analyzer);
|
||||
}
|
||||
|
||||
explicit FunctionIsNullable(bool use_analyzer_) : use_analyzer(use_analyzer_) {}
|
||||
|
||||
String getName() const override
|
||||
{
|
||||
return name;
|
||||
@ -26,6 +30,10 @@ public:
|
||||
|
||||
ColumnPtr getConstantResultForNonConstArguments(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type) const override
|
||||
{
|
||||
/// isNullable(column) triggers a bug in old analyzer when it is replaced to constant.
|
||||
if (!use_analyzer)
|
||||
return nullptr;
|
||||
|
||||
const ColumnWithTypeAndName & elem = arguments[0];
|
||||
if (elem.type->onlyNull() || canContainNull(*elem.type))
|
||||
return result_type->createColumnConst(1, UInt8(1));
|
||||
@ -60,6 +68,9 @@ public:
|
||||
const auto & elem = arguments[0];
|
||||
return ColumnUInt8::create(input_rows_count, isColumnNullable(*elem.column) || elem.type->isLowCardinalityNullable());
|
||||
}
|
||||
|
||||
private:
|
||||
bool use_analyzer;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ select count(), sum(number) from file('02892.orc', ORC, 'number UInt64, negative
|
||||
600 419700
|
||||
select count(), min(negative_or_null), max(negative_or_null) from file('02892.orc', ORC, 'number UInt64, negative_or_null Int64') where (negative_or_null < -500);
|
||||
596 -1099 -501
|
||||
select count(), sum(number) from file('02892.orc', ORC, 'number UInt64, negative_or_null Int64') where indexHint(negative_or_null is null);
|
||||
select count(), sum(number) from file('02892.orc', ORC, 'number UInt64, negative_or_null Int64') where indexHint(negative_or_null is null) settings allow_experimental_analyzer=1;
|
||||
0 0
|
||||
select count(), min(negative_or_null), max(negative_or_null) from file('02892.orc', ORC, 'number UInt64, negative_or_null Int64') where (negative_or_null is null);
|
||||
0 0 0
|
||||
|
@ -206,7 +206,7 @@ select count(), min(nEgAtIvE_oR_nUlL), max(nEgAtIvE_oR_nUlL) from file('02892.or
|
||||
select count(), sum(number) from file('02892.orc', ORC, 'number UInt64, negative_or_null Int64') where indexHint(negative_or_null < -500);
|
||||
select count(), min(negative_or_null), max(negative_or_null) from file('02892.orc', ORC, 'number UInt64, negative_or_null Int64') where (negative_or_null < -500);
|
||||
|
||||
select count(), sum(number) from file('02892.orc', ORC, 'number UInt64, negative_or_null Int64') where indexHint(negative_or_null is null);
|
||||
select count(), sum(number) from file('02892.orc', ORC, 'number UInt64, negative_or_null Int64') where indexHint(negative_or_null is null) settings allow_experimental_analyzer=1;
|
||||
select count(), min(negative_or_null), max(negative_or_null) from file('02892.orc', ORC, 'number UInt64, negative_or_null Int64') where (negative_or_null is null);
|
||||
|
||||
select count(), sum(number) from file('02892.orc', ORC, 'number UInt64, negative_or_null Int64') where indexHint(negative_or_null in (0, -1, -10, -100, -1000));
|
||||
|
@ -0,0 +1,23 @@
|
||||
CREATE TABLE left (x UUID) ORDER BY tuple();
|
||||
|
||||
CREATE TABLE right (x UUID) ORDER BY tuple();
|
||||
|
||||
set allow_experimental_analyzer=0;
|
||||
|
||||
SELECT left.x, (right.x IS NULL)::Boolean FROM left LEFT OUTER JOIN right ON left.x = right.x GROUP BY ALL;
|
||||
|
||||
SELECT isNullable(number)::Boolean, now() FROM numbers(2) GROUP BY isNullable(number)::Boolean, now() FORMAT Null;
|
||||
|
||||
SELECT isNull(number)::Boolean, now() FROM numbers(2) GROUP BY isNull(number)::Boolean, now() FORMAT Null;
|
||||
|
||||
SELECT (number IS NULL)::Boolean, now() FROM numbers(2) GROUP BY (number IS NULL)::Boolean, now() FORMAT Null;
|
||||
|
||||
set allow_experimental_analyzer=1;
|
||||
|
||||
SELECT left.x, (right.x IS NULL)::Boolean FROM left LEFT OUTER JOIN right ON left.x = right.x GROUP BY ALL;
|
||||
|
||||
SELECT isNullable(number)::Boolean, now() FROM numbers(2) GROUP BY isNullable(number)::Boolean, now() FORMAT Null;
|
||||
|
||||
SELECT isNull(number)::Boolean, now() FROM numbers(2) GROUP BY isNull(number)::Boolean, now() FORMAT Null;
|
||||
|
||||
SELECT (number IS NULL)::Boolean, now() FROM numbers(2) GROUP BY (number IS NULL)::Boolean, now() FORMAT Null;
|
Loading…
Reference in New Issue
Block a user