Skip to content

Commit

Permalink
[Bug](udtf) fix udtf core dump use as normal function
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangstar333 committed May 22, 2024
1 parent 7e2bcb5 commit 08c8184
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 24 deletions.
4 changes: 3 additions & 1 deletion be/src/vec/exprs/vectorized_fn_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ Status VectorizedFnCall::prepare(RuntimeState* state, const RowDescriptor& desc,
if (config::enable_java_support) {
if (_fn.is_udtf_function) {
// fake function. it's no use and can't execute.
_function = FunctionFake<UDTFImpl>::create();
auto builder =
std::make_shared<DefaultFunctionBuilder>(FunctionFake<UDTFImpl>::create());
_function = builder->build(argument_template, std::make_shared<DataTypeUInt8>());
} else {
_function = JavaFunctionCall::create(_fn, argument_template, _data_type);
}
Expand Down
10 changes: 6 additions & 4 deletions be/src/vec/functions/function_fake.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "vec/core/column_numbers.h"
#include "vec/core/types.h"
#include "vec/data_types/data_type.h"
#include "vec/data_types/data_type_number.h"
#include "vec/functions/function.h"

namespace doris {
Expand Down Expand Up @@ -53,7 +54,7 @@ class FunctionFake : public IFunction {
return Impl::get_return_type_impl(arguments);
}

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

bool use_default_implementation_for_constants() const override { return false; }

Expand All @@ -65,10 +66,11 @@ class FunctionFake : public IFunction {

struct UDTFImpl {
static DataTypePtr get_return_type_impl(const DataTypes& arguments) {
DCHECK(false) << "get_return_type_impl not supported, shouldn't into here.";
return nullptr;
return std::make_shared<DataTypeUInt8>(); //just fake return uint8
}
static std::string get_error_msg() {
return "UDTF function do not support this, it's should execute with lateral view.";
}
static std::string get_error_msg() { return "Fake function do not support execute"; }
};

} // namespace doris::vectorized
24 changes: 24 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.doris.catalog;

import org.apache.doris.analysis.FunctionName;
import org.apache.doris.catalog.TableIf.TableType;
import org.apache.doris.cluster.ClusterNamespace;
import org.apache.doris.common.AnalysisException;
Expand Down Expand Up @@ -755,6 +756,29 @@ public synchronized void replayAddFunction(Function function) {
}

public synchronized void dropFunction(FunctionSearchDesc function, boolean ifExists) throws UserException {
Function udfFunction = null;
if (ifExists) {
try {
// here we must first getFunction, as dropFunctionImpl will remove it
udfFunction = getFunction(function);
} catch (AnalysisException e) {
// ignore it, as drop it if exist, so can't sure it must exist
}
}
dropFunctionImpl(function, ifExists);
if (udfFunction != null && udfFunction.isUDTFunction()) {
// all of the table function in doris will have two function
// one is the normal, and another is outer, the different of them is deal with
// empty: whether need to insert NULL result value
FunctionName name = new FunctionName(function.getName().getDb(),
function.getName().getFunction() + "_outer");
FunctionSearchDesc functionOuter = new FunctionSearchDesc(name, function.getArgTypes(),
function.isVariadic());
dropFunctionImpl(functionOuter, ifExists);
}
}

public synchronized void dropFunctionImpl(FunctionSearchDesc function, boolean ifExists) throws UserException {
if (FunctionUtil.dropFunctionImpl(function, ifExists, name2Function)) {
Env.getCurrentEnv().getEditLog().logDropFunction(function);
FunctionUtil.dropFromNereids(this.getFullName(), function);
Expand Down
19 changes: 1 addition & 18 deletions regression-test/suites/javaudf_p0/test_javaudtf_all_types.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -196,23 +196,6 @@ suite("test_javaudtf_all_types") {
qt_select_string_col_outer """select int_col, string_col,e1 from ${tableName} lateral view udtf_string_outer(string_col, "") tmp1 as e1 order by int_col,2,3;"""
qt_select_array_col_outer """select int_col, array_col,e1 from ${tableName} lateral view udtf_list_outer(array_col, int_col) tmp1 as e1 order by int_col,3;"""
qt_select_map_col_outer """select int_col, map_col,e1 from ${tableName} lateral view udtf_map_outer(map_col, int_col) tmp1 as e1 order by int_col,3;"""
// qt_java_udf_all_types """select
// int_col,
// udtf_boolean(boolean_col),
// udtf_tinyint(tinyint_col),
// udtf_short(smallint_col),
// udtf_int(int_col),
// udtf_long(bigint_col),
// udtf_largeint(largeint_col),
// udtf_decimal(decimal_col),
// udtf_float(float_col),
// udtf_double(double_col),
// udtf_date(date_col),
// udtf_datetime(datetime_col),
// udtf_string(string_col),
// udtf_list(array_col),
// udtf_map(map_col)
// from ${tableName} order by int_col;"""
} finally {
try_sql """DROP FUNCTION IF EXISTS udtf_boolean_outer(boolean, int);"""
try_sql """DROP FUNCTION IF EXISTS udtf_tinyint_outer(tinyint, int);"""
Expand All @@ -228,6 +211,6 @@ suite("test_javaudtf_all_types") {
try_sql """DROP FUNCTION IF EXISTS udtf_string_outer(string, string);"""
try_sql """DROP FUNCTION IF EXISTS udtf_list_outer(array<string>, int);"""
try_sql """DROP FUNCTION IF EXISTS udtf_map_outer(map<string,string>, int);"""
// try_sql("""DROP TABLE IF EXISTS ${tableName};""")
try_sql """DROP TABLE IF EXISTS ${tableName};"""
}
}
5 changes: 4 additions & 1 deletion regression-test/suites/javaudf_p0/test_javaudtf_int.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ suite("test_javaudtf_int") {
throw new IllegalStateException("""${jarPath} doesn't exist! """)
}

sql """DROP FUNCTION IF EXISTS udtf_int_outer(int);"""
sql """ CREATE TABLES FUNCTION udtf_int(int) RETURNS array<int> PROPERTIES (
"file"="file://${jarPath}",
"symbol"="org.apache.doris.udf.UDTFIntTest",
Expand All @@ -67,6 +66,10 @@ suite("test_javaudtf_int") {

qt_select1 """ SELECT user_id, varchar_col, e1 FROM ${tableName} lateral view udtf_int(user_id) temp as e1 order by user_id; """

test {
sql """ select /*+SET_VAR(enable_fallback_to_original_planner=true)*/ udtf_int(1); """
exception "UDTF function do not support this"
}
} finally {
try_sql("DROP FUNCTION IF EXISTS udtf_int(int);")
try_sql("DROP TABLE IF EXISTS ${tableName}")
Expand Down

0 comments on commit 08c8184

Please sign in to comment.