Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions be/src/vec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ set(VEC_FILES
functions/function_cast.cpp
functions/function_string.cpp
functions/function_timestamp.cpp
functions/function_utility.cpp
functions/comparison_equal_for_null.cpp
functions/function_json.cpp
functions/hll_cardinality.cpp
Expand Down
118 changes: 118 additions & 0 deletions be/src/vec/functions/function_utility.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#include "util/monotime.h"
#include "vec/data_types/data_type_number.h"
#include "vec/data_types/data_type_string.h"
#include "vec/functions/simple_function_factory.h"

namespace doris::vectorized {

class FunctionSleep : public IFunction {
public:
static constexpr auto name = "sleep";
static FunctionPtr create() { return std::make_shared<FunctionSleep>(); }

String get_name() const override { return name; }

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()) {
return make_nullable(std::make_shared<DataTypeUInt8>());
}
return std::make_shared<DataTypeUInt8>();
}

bool use_default_implementation_for_constants() const override { return true; }
bool use_default_implementation_for_nulls() const override { return false; }

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

auto res_column = ColumnUInt8::create();

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();
auto data_column = assert_cast<const ColumnVector<Int32>*>(nested_column.get());

for (int i = 0; i < input_rows_count; i++) {
if (nullable_column->is_null_at(i)) {
res_column->insert(0);
null_map_column->insert(1);
} else {
int seconds = data_column->get_data()[i];
SleepFor(MonoDelta::FromSeconds(seconds));
res_column->insert(1);
null_map_column->insert(0);
}
}

block.replace_by_position(result, ColumnNullable::create(std::move(res_column),
std::move(null_map_column)));
} else {
auto data_column = assert_cast<const ColumnVector<Int32>*>(argument_column.get());

for (int i = 0; i < input_rows_count; i++) {
int seconds = data_column->get_element(i);
SleepFor(MonoDelta::FromSeconds(seconds));
res_column->insert(1);
}

block.replace_by_position(result, std::move(res_column));
}
return Status::OK();
}
};

class FunctionVersion : public IFunction {
public:
static constexpr auto name = "version";

static const std::string version;

static FunctionPtr create() { return std::make_shared<FunctionVersion>(); }

String get_name() const override { return name; }

size_t get_number_of_arguments() const override { return 0; }

DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override {
return std::make_shared<DataTypeString>();
}

Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
size_t result, size_t input_rows_count) override {
auto res_column = ColumnString::create();
res_column->insert_data(version.c_str(), version.length());
block.replace_by_position(result, std::move(res_column));
return Status::OK();
}
};

const std::string FunctionVersion::version = "5.1.0";

void register_function_utility(SimpleFunctionFactory& factory) {
factory.register_function<FunctionSleep>();
factory.register_function<FunctionVersion>();
}

} // namespace doris::vectorized
1 change: 1 addition & 0 deletions be/src/vec/functions/math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ void register_function_math(SimpleFunctionFactory& factory) {
factory.register_function<FunctionPositive>();
factory.register_function<FunctionSin>();
factory.register_function<FunctionSqrt>();
factory.register_alias("sqrt", "dsqrt");
factory.register_function<FunctionTan>();
factory.register_function<FunctionFloor>();
factory.register_alias("floor", "dfloor");
Expand Down
2 changes: 2 additions & 0 deletions be/src/vec/functions/simple_function_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void register_function_if(SimpleFunctionFactory& factory);
void register_function_nullif(SimpleFunctionFactory& factory);
void register_function_date_time_computation(SimpleFunctionFactory& factory);
void register_function_timestamp(SimpleFunctionFactory& factory);
void register_function_utility(SimpleFunctionFactory& factory);
void register_function_json(SimpleFunctionFactory& factory);
void register_function_function_hash(SimpleFunctionFactory& factory);
void register_function_function_ifnull(SimpleFunctionFactory& factory);
Expand Down Expand Up @@ -159,6 +160,7 @@ class SimpleFunctionFactory {
register_function_nullif(instance);
register_function_date_time_computation(instance);
register_function_timestamp(instance);
register_function_utility(instance);
register_function_date_time_to_string(instance);
register_function_date_time_string_to_string(instance);
register_function_json(instance);
Expand Down
4 changes: 2 additions & 2 deletions gensrc/script/doris_builtins_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,10 +1069,10 @@
# Utility functions
[['sleep'], 'BOOLEAN', ['INT'],
'_ZN5doris16UtilityFunctions5sleepEPN9doris_udf15FunctionContextERKNS1_6IntValE',
'', '', '', ''],
'', '', 'vec', ''],
[['version'], 'VARCHAR', [],
'_ZN5doris16UtilityFunctions7versionEPN9doris_udf15FunctionContextE',
'', '', '', 'ALWAYS_NOT_NULLABLE'],
'', '', 'vec', 'ALWAYS_NOT_NULLABLE'],

# Json functions
[['get_json_int'], 'INT', ['VARCHAR', 'VARCHAR'],
Expand Down