Skip to content

Commit

Permalink
Merge pull request #3100 from kuzudb/list-functions-refactor
Browse files Browse the repository at this point in the history
Refactor list functions
  • Loading branch information
manh9203 committed Mar 22, 2024
2 parents 7817cc9 + 68c2856 commit 96d9a91
Show file tree
Hide file tree
Showing 10 changed files with 568 additions and 541 deletions.
70 changes: 0 additions & 70 deletions src/function/built_in_function_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ void BuiltInFunctionsUtils::registerScalarFunctions(CatalogSet* catalogSet) {
registerTimestampFunctions(catalogSet);
registerIntervalFunctions(catalogSet);
registerCastFunctions(catalogSet);
registerListFunctions(catalogSet);
registerStructFunctions(catalogSet);
registerMapFunctions(catalogSet);
registerUnionFunctions(catalogSet);
Expand Down Expand Up @@ -669,75 +668,6 @@ void BuiltInFunctionsUtils::registerCastFunctions(CatalogSet* catalogSet) {
CAST_FUNC_NAME, CastAnyFunction::getFunctionSet()));
}

void BuiltInFunctionsUtils::registerListFunctions(CatalogSet* catalogSet) {
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
LIST_CREATION_FUNC_NAME, ListCreationFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
LIST_RANGE_FUNC_NAME, ListRangeFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
SIZE_FUNC_NAME, SizeFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
LIST_EXTRACT_FUNC_NAME, ListExtractFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
LIST_ELEMENT_FUNC_NAME, ListExtractFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
LIST_CONCAT_FUNC_NAME, ListConcatFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
LIST_CAT_FUNC_NAME, ListConcatFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
ARRAY_CONCAT_FUNC_NAME, ListConcatFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
ARRAY_CAT_FUNC_NAME, ListConcatFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
LIST_APPEND_FUNC_NAME, ListAppendFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
ARRAY_APPEND_FUNC_NAME, ListAppendFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
ARRAY_PUSH_BACK_FUNC_NAME, ListAppendFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
LIST_PREPEND_FUNC_NAME, ListPrependFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
ARRAY_PREPEND_FUNC_NAME, ListPrependFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
ARRAY_PUSH_FRONT_FUNC_NAME, ListPrependFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
LIST_POSITION_FUNC_NAME, ListPositionFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
ARRAY_POSITION_FUNC_NAME, ListPositionFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
LIST_INDEXOF_FUNC_NAME, ListPositionFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
ARRAY_INDEXOF_FUNC_NAME, ListPositionFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
LIST_CONTAINS_FUNC_NAME, ListContainsFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
LIST_HAS_FUNC_NAME, ListContainsFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
ARRAY_CONTAINS_FUNC_NAME, ListContainsFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
ARRAY_HAS_FUNC_NAME, ListContainsFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
LIST_SLICE_FUNC_NAME, ListSliceFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
ARRAY_SLICE_FUNC_NAME, ListSliceFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
LIST_SORT_FUNC_NAME, ListSortFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
LIST_REVERSE_SORT_FUNC_NAME, ListReverseSortFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
LIST_SUM_FUNC_NAME, ListSumFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
LIST_PRODUCT_FUNC_NAME, ListProductFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
LIST_DISTINCT_FUNC_NAME, ListDistinctFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
LIST_UNIQUE_FUNC_NAME, ListUniqueFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
LIST_ANY_VALUE_FUNC_NAME, ListAnyValueFunction::getFunctionSet()));
catalogSet->createEntry(std::make_unique<catalog::ScalarFunctionCatalogEntry>(
LIST_REVERSE_FUNC_NAME, ListReverseFunction::getFunctionSet()));
}

void BuiltInFunctionsUtils::registerStructFunctions(CatalogSet* catalogSet) {
catalogSet->createEntry(std::make_unique<ScalarFunctionCatalogEntry>(
STRUCT_PACK_FUNC_NAME, StructPackFunctions::getFunctionSet()));
Expand Down
23 changes: 23 additions & 0 deletions src/function/function_collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "function/arithmetic/vector_arithmetic_functions.h"
#include "function/array/vector_array_functions.h"
#include "function/list/vector_list_functions.h"
#include "function/string/vector_string_functions.h"

namespace kuzu {
Expand Down Expand Up @@ -53,9 +54,31 @@ FunctionCollection* FunctionCollection::getFunctions() {
SCALAR_FUNCTION(RegexpFullMatchFunction), SCALAR_FUNCTION(RegexpMatchesFunction),
SCALAR_FUNCTION(RegexpReplaceFunction), SCALAR_FUNCTION(RegexpExtractFunction),
SCALAR_FUNCTION(RegexpExtractAllFunction), SCALAR_FUNCTION(LevenshteinFunction),

// Array Functions
SCALAR_FUNCTION(ArrayValueFunction), SCALAR_FUNCTION(ArrayCrossProductFunction),
SCALAR_FUNCTION(ArrayCosineSimilarityFunction), SCALAR_FUNCTION(ArrayDistanceFunction),
SCALAR_FUNCTION(ArrayInnerProductFunction), SCALAR_FUNCTION(ArrayDotProductFunction),

// List functions
SCALAR_FUNCTION(ListCreationFunction), SCALAR_FUNCTION(ListRangeFunction),
SCALAR_FUNCTION(ListExtractFunction), SCALAR_FUNCTION_ALIAS(ListExtractFunction),
SCALAR_FUNCTION(ListConcatFunction), SCALAR_FUNCTION_ALIAS(ListConcatFunction),
SCALAR_FUNCTION(ArrayConcatFunction), SCALAR_FUNCTION_ALIAS(ArrayConcatFunction),
SCALAR_FUNCTION(ListAppendFunction), SCALAR_FUNCTION(ArrayAppendFunction),
SCALAR_FUNCTION_ALIAS(ArrayAppendFunction), SCALAR_FUNCTION(ListPrependFunction),
SCALAR_FUNCTION(ArrayPrependFunction), SCALAR_FUNCTION_ALIAS(ArrayPrependFunction),
SCALAR_FUNCTION(ListPositionFunction), SCALAR_FUNCTION_ALIAS(ListPositionFunction),
SCALAR_FUNCTION(ArrayPositionFunction), SCALAR_FUNCTION_ALIAS(ArrayPositionFunction),
SCALAR_FUNCTION(ListContainsFunction), SCALAR_FUNCTION_ALIAS(ListContainsFunction),
SCALAR_FUNCTION(ArrayContainsFunction), SCALAR_FUNCTION_ALIAS(ArrayContainsFunction),
SCALAR_FUNCTION(ListSliceFunction), SCALAR_FUNCTION(ArraySliceFunction),
SCALAR_FUNCTION(ListSortFunction), SCALAR_FUNCTION(ListReverseSortFunction),
SCALAR_FUNCTION(ListSumFunction), SCALAR_FUNCTION(ListProductFunction),
SCALAR_FUNCTION(ListDistinctFunction), SCALAR_FUNCTION(ListUniqueFunction),
SCALAR_FUNCTION(ListAnyValueFunction), SCALAR_FUNCTION(ListReverseFunction),
SCALAR_FUNCTION(SizeFunction),

// End of array
FINAL_FUNCTION};

Expand Down
2 changes: 2 additions & 0 deletions src/function/vector_array_functions.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "function/array/vector_array_functions.h"

#include "common/exception/binder.h"
#include "function/array/functions/array_cosine_similarity.h"
#include "function/array/functions/array_cross_product.h"
#include "function/array/functions/array_distance.h"
#include "function/array/functions/array_inner_product.h"
#include "function/list/vector_list_functions.h"
#include "function/scalar_function.h"

using namespace kuzu::common;

Expand Down
Loading

0 comments on commit 96d9a91

Please sign in to comment.