Skip to content
Open
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
5 changes: 3 additions & 2 deletions be/src/exprs/function/cast/function_cast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,9 @@ class FunctionBuilderCast : public FunctionBuilderImpl {
}

bool skip_return_type_check() const override { return true; }
DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override {
return nullptr;
DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& /*arguments*/) const override {
throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR,
"get_return_type is not implemented for {}", get_name());
}

bool use_default_implementation_for_nulls() const override { return false; }
Expand Down
5 changes: 4 additions & 1 deletion be/src/exprs/function/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ DataTypePtr FunctionBuilderImpl::get_return_type(const ColumnsWithTypeAndName& a
auto return_type = get_return_type_impl(
ColumnsWithTypeAndName(nested_block.begin(), nested_block.end()));
if (!return_type) {
return nullptr;
throw Exception(ErrorCode::INTERNAL_ERROR,
"function return type is nullptr, function_name={}, "
"input_arguments={}",
get_name(), get_types_string(arguments));
}
return make_nullable(return_type);
}
Expand Down
1 change: 0 additions & 1 deletion be/src/exprs/function/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ class FunctionBuilderImpl : public IFunctionBuilder {
virtual DataTypePtr get_return_type_impl(const DataTypes& /*arguments*/) const {
throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR,
"get_return_type is not implemented for {}", get_name());
return nullptr;
}

/** If use_default_implementation_for_nulls() is true, than change arguments for get_return_type() and build_impl():
Expand Down
3 changes: 1 addition & 2 deletions be/src/exprs/function/function_struct_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ class FunctionStructElement : public IFunction {
size_t index;
auto st = get_element_index(*struct_type, index_column, index_type, &index);
if (!st.ok()) {
// will handle nullptr outside
return nullptr;
throw doris::Exception(st);
}
// The struct_element is marked as AlwaysNullable in fe.
return make_nullable(struct_type->get_elements()[index]);
Expand Down
21 changes: 20 additions & 1 deletion be/test/exprs/function/function_struct_element_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,25 @@ TEST(FunctionStructElementTest, test_return_type) {
std::cout << "Return type: " << return_type->get_name() << std::endl;
}

TEST(FunctionStructElementTest, test_return_type_invalid_field) {
auto index_type = std::make_shared<DataTypeString>();
auto index_column = ColumnHelper::create_column<DataTypeString>({"key4"});

DataTypes struct_types = {std::make_shared<DataTypeString>(), std::make_shared<DataTypeInt32>(),
std::make_shared<DataTypeFloat64>()};
Strings names = {"key1", "key2", "key3"};
auto type_struct = std::make_shared<DataTypeStruct>(struct_types, names);

auto argument_template = ColumnsWithTypeAndName {{nullptr, type_struct, "struct"},
{index_column, index_type, "index"}};

EXPECT_THROW(SimpleFunctionFactory::instance().get_function(
"struct_element", argument_template,
std::make_shared<DataTypeNullable>(std::make_shared<DataTypeInt32>()),
{true}, BeExecVersionManager::get_newest_version()),
doris::Exception);
}

TEST(FunctionStructElementTest, test_return_column) {
auto index_type = std::make_shared<DataTypeString>();

Expand Down Expand Up @@ -114,4 +133,4 @@ TEST(FunctionStructElementTest, test_return_column) {
EXPECT_TRUE(block.get_by_position(2).column->is_nullable());
}

} // namespace doris
} // namespace doris
6 changes: 4 additions & 2 deletions be/test/exprs/function/simple_function_factory_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class FunctionBeTestMock : public IFunction {

size_t get_number_of_arguments() const override { return 0; }

DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { return nullptr; }
DataTypePtr get_return_type_impl(const DataTypes& /*arguments*/) const override {
throw doris::Exception(ErrorCode::INTERNAL_ERROR, "BEUT TEST: nullptr return type");
}

Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
uint32_t result, size_t input_rows_count) const override {
Expand Down Expand Up @@ -95,4 +97,4 @@ TEST_F(SimpleFunctionFactoryTest, test_return_all) {
}
}

} // namespace doris
} // namespace doris
Loading