Skip to content

Commit

Permalink
[fix](sleep) sleep with character const make be crash (apache#37681)
Browse files Browse the repository at this point in the history
  • Loading branch information
cambyzju authored and seawinde committed Jul 17, 2024
1 parent 8d3332c commit 0892257
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
19 changes: 7 additions & 12 deletions be/src/vec/functions/function_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,26 @@ class FunctionSleep : public IFunction {
size_t get_number_of_arguments() const override { return 1; }

DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
if (arguments[0].get()->is_nullable()) {
if (arguments[0]->is_nullable()) {
return make_nullable(std::make_shared<DataTypeUInt8>());
}
return std::make_shared<DataTypeUInt8>();
}

bool use_default_implementation_for_nulls() const override { return false; }

// Sleep function should not be executed during open stage, this will makes fragment prepare
// waiting too long, so we do not use default impl.
bool use_default_implementation_for_constants() const override { return false; }

Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
size_t result, size_t input_rows_count) const override {
ColumnPtr& argument_column = block.get_by_position(arguments[0]).column;
const auto& argument_column =
block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();

auto res_column = ColumnUInt8::create();

if (is_column_const(*argument_column)) {
Int64 seconds = argument_column->get_int(0);
for (int i = 0; i < input_rows_count; i++) {
std::this_thread::sleep_for(std::chrono::seconds(seconds));
res_column->insert(1);
}

block.replace_by_position(result, std::move(res_column));
} else if (auto* nullable_column = check_and_get_column<ColumnNullable>(*argument_column)) {
if (auto* nullable_column = check_and_get_column<ColumnNullable>(*argument_column)) {
auto null_map_column = ColumnUInt8::create();

auto nested_column = nullable_column->get_nested_column_ptr();
Expand Down Expand Up @@ -154,4 +149,4 @@ void register_function_utility(SimpleFunctionFactory& factory) {
factory.register_function<FunctionVersion>();
}

} // namespace doris::vectorized
} // namespace doris::vectorized
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ suite("test_query_sys", "query,p0") {
sql "select pi();"
sql "select e();"
sql "select sleep(2);"
sql "select sleep('1.1');"

// INFORMATION_SCHEMA
sql "SELECT table_name FROM INFORMATION_SCHEMA.TABLES where table_schema=\"nereids_test_query_db\" and TABLE_TYPE = \"BASE TABLE\" order by table_name"
Expand Down

0 comments on commit 0892257

Please sign in to comment.