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
19 changes: 9 additions & 10 deletions villagesql/types/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ void ClearAlterCustomFields(THD *thd) {
}

bool ValidateAndConvertVDFArguments(THD *thd, const char *func_name,
const LEX_STRING &extension_name,
std::string_view extension_name,
uint arg_count, Item **args,
const vef_signature_t *signature,
TypeParameters *out_return_params) {
Expand All @@ -1277,7 +1277,6 @@ bool ValidateAndConvertVDFArguments(THD *thd, const char *func_name,
uint arg_index;
};
std::map<std::string, KnownEntry> known_params;
const std::string ext_name(extension_name.str, extension_name.length);

for (uint i = 0; i < arg_count; i++) {
const vef_type_t &expected_type = signature->params[i];
Expand All @@ -1286,7 +1285,7 @@ bool ValidateAndConvertVDFArguments(THD *thd, const char *func_name,

assert(expected_type.custom_type != nullptr);
const std::string expected_qbn =
make_qualified_base_name(ext_name, expected_type.custom_type);
make_qualified_base_name(extension_name, expected_type.custom_type);

auto *tc = args[i]->get_type_context();
if (tc == nullptr) continue; // String constants handled in pass 2
Expand Down Expand Up @@ -1329,7 +1328,7 @@ bool ValidateAndConvertVDFArguments(THD *thd, const char *func_name,

assert(expected_type.custom_type != nullptr);
const std::string expected_qbn =
make_qualified_base_name(ext_name, expected_type.custom_type);
make_qualified_base_name(extension_name, expected_type.custom_type);

auto *tc = args[i]->get_type_context();

Expand All @@ -1343,7 +1342,7 @@ bool ValidateAndConvertVDFArguments(THD *thd, const char *func_name,
auto it = known_params.find(expected_qbn);
if (it != known_params.end()) {
const TypeContext *resolved_tc = nullptr;
if (ResolveTypeToContext(ext_name, expected_type.custom_type,
if (ResolveTypeToContext(extension_name, expected_type.custom_type,
*it->second.params, *thd->mem_root,
resolved_tc)) {
return true;
Expand Down Expand Up @@ -1374,7 +1373,7 @@ bool ValidateAndConvertVDFArguments(THD *thd, const char *func_name,
}

const TypeContext *type_ctx = nullptr;
if (ResolveTypeToContext(ext_name, expected_type.custom_type,
if (ResolveTypeToContext(extension_name, expected_type.custom_type,
resolved_params, *thd->mem_root, type_ctx)) {
return true;
}
Expand Down Expand Up @@ -1416,8 +1415,8 @@ bool ValidateAndConvertVDFArguments(THD *thd, const char *func_name,
if (out_return_params != nullptr &&
signature->return_type.id == VEF_TYPE_CUSTOM &&
signature->return_type.custom_type != nullptr) {
const std::string return_qbn =
make_qualified_base_name(ext_name, signature->return_type.custom_type);
const std::string return_qbn = make_qualified_base_name(
extension_name, signature->return_type.custom_type);
auto it = known_params.find(return_qbn);
if (it != known_params.end()) {
*out_return_params = *it->second.params;
Expand All @@ -1427,7 +1426,7 @@ bool ValidateAndConvertVDFArguments(THD *thd, const char *func_name,
return false;
}

void SetVDFReturnTypeContext(THD *thd, const LEX_STRING &extension_name,
void SetVDFReturnTypeContext(THD *thd, std::string_view extension_name,
const vef_signature_t *signature,
Item *result_item,
const TypeParameters *return_params) {
Expand All @@ -1437,7 +1436,7 @@ void SetVDFReturnTypeContext(THD *thd, const LEX_STRING &extension_name,
}

const TypeContext *return_type_ctx = nullptr;
if (!ResolveTypeToContext(to_string_view(extension_name), return_type_name,
if (!ResolveTypeToContext(extension_name, return_type_name,
return_params ? *return_params : TypeParameters{},
*thd->mem_root, return_type_ctx) &&
return_type_ctx != nullptr) {
Expand Down
4 changes: 2 additions & 2 deletions villagesql/types/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,14 @@ extern bool CheckCustomTypeUsage(Item *item, THD *thd);
// the same as those matching arguements of the same abstract type). Returns
// false on success, true on error.
extern bool ValidateAndConvertVDFArguments(THD *thd, const char *func_name,
const LEX_STRING &extension_name,
std::string_view extension_name,
uint arg_count, Item **args,
const vef_signature_t *signature,
TypeParameters *out_return_params);

// Set the return type_context on a VDF result Item if it returns a custom type.
// If return_params is non-null, uses those params instead of empty ones.
extern void SetVDFReturnTypeContext(THD *thd, const LEX_STRING &extension_name,
extern void SetVDFReturnTypeContext(THD *thd, std::string_view extension_name,
const vef_signature_t *signature,
Item *result_item,
const TypeParameters *return_params);
Expand Down
10 changes: 6 additions & 4 deletions villagesql/vdf/vdf_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <type_traits>

#include "lex_string.h"
#include "my_sys.h"
#include "mysql/strings/m_ctype.h"
#include "sql/current_thd.h"
Expand Down Expand Up @@ -98,8 +99,8 @@ bool vdf_handler::fix_fields(THD *thd [[maybe_unused]],
villagesql::TypeParameters return_params;
if (signature != nullptr &&
villagesql::ValidateAndConvertVDFArguments(
thd, m_udf->name.str, m_udf->extension_name, arg_count, m_args,
signature, &return_params)) {
thd, m_udf->name.str, to_string_view(m_udf->extension_name),
arg_count, m_args, signature, &return_params)) {
return true;
}

Expand Down Expand Up @@ -171,8 +172,9 @@ bool vdf_handler::fix_fields(THD *thd [[maybe_unused]],
// return_params inferred from args via the call to
// ValidateAndConvertVDFArguments.
if (signature != nullptr && signature->return_type.id == VEF_TYPE_CUSTOM) {
villagesql::SetVDFReturnTypeContext(thd, m_udf->extension_name, signature,
func, &return_params);
villagesql::SetVDFReturnTypeContext(thd,
to_string_view(m_udf->extension_name),
signature, func, &return_params);
m_return_type_context = func->get_type_context();
}

Expand Down
Loading