[branch-2.1](functions) fix be crash for function random_bytes and mark_first/last_n (#36003)
pick #35884
This commit is contained in:
@ -792,10 +792,7 @@ public:
|
||||
|
||||
Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
|
||||
size_t result, size_t input_rows_count) const override {
|
||||
DCHECK_GE(arguments.size(), 1);
|
||||
DCHECK_LE(arguments.size(), 2);
|
||||
|
||||
int n = -1;
|
||||
int n = -1; // means unassigned
|
||||
|
||||
auto res = ColumnString::create();
|
||||
auto col = block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
|
||||
@ -803,17 +800,20 @@ public:
|
||||
|
||||
if (arguments.size() == 2) {
|
||||
const auto& col = *block.get_by_position(arguments[1]).column;
|
||||
// the 2nd arg is const. checked in fe.
|
||||
if (col.get_int(0) < 0) [[unlikely]] {
|
||||
return Status::InvalidArgument(
|
||||
"function {} only accept non-negative input for 2nd argument but got {}",
|
||||
name, col.get_int(0));
|
||||
}
|
||||
n = col.get_int(0);
|
||||
} else if (arguments.size() > 2) {
|
||||
return Status::InvalidArgument(
|
||||
fmt::format("too many arguments for function {}", get_name()));
|
||||
}
|
||||
|
||||
if (n == -1) {
|
||||
if (n == -1) { // no 2nd arg, just mask all
|
||||
FunctionMask::vector_mask(source_column, *res, FunctionMask::DEFAULT_UPPER_MASK,
|
||||
FunctionMask::DEFAULT_LOWER_MASK,
|
||||
FunctionMask::DEFAULT_NUMBER_MASK);
|
||||
} else if (n >= 0) {
|
||||
} else { // n >= 0
|
||||
vector(source_column, n, *res);
|
||||
}
|
||||
|
||||
@ -2901,19 +2901,18 @@ public:
|
||||
|
||||
ColumnPtr argument_column =
|
||||
block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
|
||||
const auto* length_col = check_and_get_column<ColumnInt32>(argument_column.get());
|
||||
|
||||
if (!length_col) {
|
||||
return Status::InternalError("Not supported input argument type");
|
||||
}
|
||||
const auto* length_col = assert_cast<const ColumnInt32*>(argument_column.get());
|
||||
|
||||
std::vector<uint8_t> random_bytes;
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
for (size_t i = 0; i < input_rows_count; ++i) {
|
||||
UInt64 length = length_col->get64(i);
|
||||
random_bytes.resize(length);
|
||||
if (length_col->get_element(i) < 0) [[unlikely]] {
|
||||
return Status::InvalidArgument("argument {} of function {} at row {} was invalid.",
|
||||
length_col->get_element(i), name, i);
|
||||
}
|
||||
random_bytes.resize(length_col->get_element(i));
|
||||
|
||||
std::uniform_int_distribution<uint8_t> distribution(0, 255);
|
||||
for (auto& byte : random_bytes) {
|
||||
|
||||
Reference in New Issue
Block a user