Skip to content

Commit

Permalink
Fix the failed smoke tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunset3000 committed Sep 26, 2023
1 parent ba91d4f commit 127eed0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
18 changes: 9 additions & 9 deletions src/AggregateFunctions/AggregateFunctionJavaScriptAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,30 +234,30 @@ void JavaScriptAggrFunctionState::reinitCache()
}

AggregateFunctionJavaScriptAdapter::AggregateFunctionJavaScriptAdapter(
const JavaScriptUserDefinedFunctionConfiguration & config_, const DataTypes & types, const Array & params_, size_t max_v8_heap_size_in_bytes_)
const JavaScriptUserDefinedFunctionConfigurationPtr config_, const DataTypes & types, const Array & params_, size_t max_v8_heap_size_in_bytes_)
: IAggregateFunctionHelper<AggregateFunctionJavaScriptAdapter>(types, params_)
, config(config_)
, num_arguments(types.size())
, max_v8_heap_size_in_bytes(max_v8_heap_size_in_bytes_)
, blueprint(config.name, config.source)
, blueprint(config->name, config->source)
{
}

String AggregateFunctionJavaScriptAdapter::getName() const
{
return config.name;
return config->name;
}

DataTypePtr AggregateFunctionJavaScriptAdapter::getReturnType() const
{
return config.result_type;
return config->result_type;
}

/// create instance of UDF via function_builder
void AggregateFunctionJavaScriptAdapter::create(AggregateDataPtr __restrict place) const
{
V8::checkHeapLimit(blueprint.isolate.get(), max_v8_heap_size_in_bytes);
new (place) Data(blueprint, config.arguments);
new (place) Data(blueprint, config->arguments);
}

/// destroy instance of UDF
Expand Down Expand Up @@ -372,17 +372,17 @@ size_t AggregateFunctionJavaScriptAdapter::flush(AggregateDataPtr __restrict pla
v8::Local<v8::Function> local_func = v8::Local<v8::Function>::New(isolate_, data.process_func);

/// Second, convert the input column into the corresponding object used by UDF
auto argv = V8::prepareArguments(isolate_, config.arguments, data.columns);
auto argv = V8::prepareArguments(isolate_, config->arguments, data.columns);

/// Third, execute the UDF and get aggregate state (only support the final state now, intermediate state is not supported
v8::Local<v8::Value> res;
if (!local_func->Call(ctx, local_obj, static_cast<int>(config.arguments.size()), argv.data()).ToLocal(&res))
if (!local_func->Call(ctx, local_obj, static_cast<int>(config->arguments.size()), argv.data()).ToLocal(&res))
V8::throwException(
isolate_,
try_catch,
ErrorCodes::AGGREGATE_FUNCTION_THROW,
"Failed to invoke JavaScript user defined aggregation function : {}",
config.name);
config->name);

/// Forth, check if the UDA should emit only it has emit strategy
if (blueprint.has_user_defined_emit_strategy && !res->IsUndefined())
Expand Down Expand Up @@ -497,7 +497,7 @@ void AggregateFunctionJavaScriptAdapter::insertResultInto(AggregateDataPtr __res
num_of_results);
}

V8::insertResult(isolate_, to, config.result_type, res, hasUserDefinedEmit());
V8::insertResult(isolate_, to, config->result_type, res, hasUserDefinedEmit());
};

V8::run(blueprint.isolate.get(), blueprint.global_context, std::move(finalize_func));
Expand Down
4 changes: 2 additions & 2 deletions src/AggregateFunctions/AggregateFunctionJavaScriptAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ class AggregateFunctionJavaScriptAdapter final : public IAggregateFunctionHelper
static Data & data(AggregateDataPtr __restrict place) { return *reinterpret_cast<Data *>(place); }
static const Data & data(ConstAggregateDataPtr __restrict place) { return *reinterpret_cast<const Data *>(place); }

const JavaScriptUserDefinedFunctionConfiguration & config;
const JavaScriptUserDefinedFunctionConfigurationPtr config;
size_t num_arguments;
size_t max_v8_heap_size_in_bytes;
JavaScriptBlueprint blueprint;

public:
AggregateFunctionJavaScriptAdapter(
const JavaScriptUserDefinedFunctionConfiguration & config_,
const JavaScriptUserDefinedFunctionConfigurationPtr config_,
const DataTypes & types,
const Array & params_,
size_t max_v8_heap_size_in_bytes_);
Expand Down
18 changes: 9 additions & 9 deletions src/AggregateFunctions/tests/gtest_uda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ v8::Local<v8::Value> createV8Array(v8::Isolate * isolate, bool is_empty_array)
return scope.Escape(result);
}

JavaScriptUserDefinedFunctionConfiguration
JavaScriptUserDefinedFunctionConfigurationPtr
createUDFConfig(const String & name, const String & arg_str, const String & return_type, const String & source)
{
DataTypePtr result_type = DataTypeFactory::instance().get(return_type);
Expand All @@ -172,13 +172,13 @@ createUDFConfig(const String & name, const String & arg_str, const String & retu
}
}

JavaScriptUserDefinedFunctionConfiguration function_configuration;
function_configuration.source = source;
function_configuration.is_aggregation = true;
function_configuration.name = name;
function_configuration.result_type = std::move(result_type);
function_configuration.type = UserDefinedFunctionConfiguration::FuncType::JAVASCRIPT;
function_configuration.arguments = std::move(arguments);
auto function_configuration = std::make_shared<JavaScriptUserDefinedFunctionConfiguration>();
function_configuration->source = source;
function_configuration->is_aggregation = true;
function_configuration->name = name;
function_configuration->result_type = std::move(result_type);
function_configuration->type = UserDefinedFunctionConfiguration::FuncType::JAVASCRIPT;
function_configuration->arguments = std::move(arguments);

return function_configuration;
};
Expand Down Expand Up @@ -542,7 +542,7 @@ void checkPrepareArguments(String type, CREATE_DATA_FUNC create_fn, CHECK_V8_DAT

MutableColumns columns;
columns.emplace_back(std::move(col_ptr));
auto argv = V8::prepareArguments(isolate, config.arguments, columns);
auto argv = V8::prepareArguments(isolate, config->arguments, columns);

ASSERT_EQ(argv.size(), 1);
v8::Local<v8::Array> v8_arr = argv[0].As<v8::Array>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,5 @@ struct JavaScriptUserDefinedFunctionConfiguration : public UserDefinedFunctionCo
};

using UserDefinedFunctionConfigurationPtr = std::shared_ptr<UserDefinedFunctionConfiguration>;
using JavaScriptUserDefinedFunctionConfigurationPtr = std::shared_ptr<JavaScriptUserDefinedFunctionConfiguration>;
}
4 changes: 2 additions & 2 deletions src/Functions/UserDefined/UserDefinedFunctionFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ AggregateFunctionPtr UserDefinedFunctionFactory::getAggregateFunction(
if (load_result.object)
{
auto executable_function = std::static_pointer_cast<const UserDefinedExecutableFunction>(load_result.object);
const auto * config = executable_function->getConfiguration()->as<JavaScriptUserDefinedFunctionConfiguration>();
const auto config = std::dynamic_pointer_cast<JavaScriptUserDefinedFunctionConfiguration>(executable_function->getConfiguration());

if (!config || !config->is_aggregation)
return nullptr;
Expand Down Expand Up @@ -109,7 +109,7 @@ AggregateFunctionPtr UserDefinedFunctionFactory::getAggregateFunction(
}

return std::make_shared<AggregateFunctionJavaScriptAdapter>(
*config, types, parameters, query_context->getSettingsRef().javascript_max_memory_bytes);
config, types, parameters, query_context->getSettingsRef().javascript_max_memory_bytes);
}

return nullptr;
Expand Down

0 comments on commit 127eed0

Please sign in to comment.