Skip to content

Commit

Permalink
Rename length() to size()
Browse files Browse the repository at this point in the history
  • Loading branch information
acquamarin committed Oct 16, 2023
1 parent c604332 commit d52b57a
Show file tree
Hide file tree
Showing 17 changed files with 137 additions and 137 deletions.
5 changes: 2 additions & 3 deletions src/function/built_in_vector_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ void BuiltInVectorFunctions::registerStringFunctions() {
vectorFunctions.insert({ENDS_WITH_FUNC_NAME, EndsWithVectorFunction::getDefinitions()});
vectorFunctions.insert({LCASE_FUNC_NAME, LowerVectorFunction::getDefinitions()});
vectorFunctions.insert({LEFT_FUNC_NAME, LeftVectorFunction::getDefinitions()});
vectorFunctions.insert({LENGTH_FUNC_NAME, LengthVectorFunction::getDefinitions()});
vectorFunctions.insert({LOWER_FUNC_NAME, LowerVectorFunction::getDefinitions()});
vectorFunctions.insert({LPAD_FUNC_NAME, LpadVectorFunction::getDefinitions()});
vectorFunctions.insert({LTRIM_FUNC_NAME, LtrimVectorFunction::getDefinitions()});
Expand Down Expand Up @@ -512,7 +511,7 @@ void BuiltInVectorFunctions::registerCastFunctions() {
void BuiltInVectorFunctions::registerListFunctions() {
vectorFunctions.insert({LIST_CREATION_FUNC_NAME, ListCreationVectorFunction::getDefinitions()});
vectorFunctions.insert({LIST_RANGE_FUNC_NAME, ListRangeVectorFunction::getDefinitions()});
vectorFunctions.insert({LIST_LEN_FUNC_NAME, ListLenVectorFunction::getDefinitions()});
vectorFunctions.insert({SIZE_FUNC_NAME, SizeVectorFunction::getDefinitions()});
vectorFunctions.insert({LIST_EXTRACT_FUNC_NAME, ListExtractVectorFunction::getDefinitions()});
vectorFunctions.insert({LIST_ELEMENT_FUNC_NAME, ListExtractVectorFunction::getDefinitions()});
vectorFunctions.insert({LIST_CONCAT_FUNC_NAME, ListConcatVectorFunction::getDefinitions()});
Expand Down Expand Up @@ -559,7 +558,7 @@ void BuiltInVectorFunctions::registerMapFunctions() {
vectorFunctions.insert({MAP_CREATION_FUNC_NAME, MapCreationVectorFunctions::getDefinitions()});
vectorFunctions.insert({MAP_EXTRACT_FUNC_NAME, MapExtractVectorFunctions::getDefinitions()});
vectorFunctions.insert({ELEMENT_AT_FUNC_NAME, MapExtractVectorFunctions::getDefinitions()});
vectorFunctions.insert({CARDINALITY_FUNC_NAME, ListLenVectorFunction::getDefinitions()});
vectorFunctions.insert({CARDINALITY_FUNC_NAME, SizeVectorFunction::getDefinitions()});
vectorFunctions.insert({MAP_KEYS_FUNC_NAME, MapKeysVectorFunctions::getDefinitions()});
vectorFunctions.insert({MAP_VALUES_FUNC_NAME, MapValuesVectorFunctions::getDefinitions()});
}
Expand Down
16 changes: 9 additions & 7 deletions src/function/vector_list_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,17 @@ vector_function_definitions ListRangeVectorFunction::getDefinitions() {
return result;
}

vector_function_definitions ListLenVectorFunction::getDefinitions() {
vector_function_definitions SizeVectorFunction::getDefinitions() {
vector_function_definitions result;
auto execFunc = UnaryExecFunction<list_entry_t, int64_t, ListLen>;
result.push_back(std::make_unique<VectorFunctionDefinition>(LIST_LEN_FUNC_NAME,
std::vector<LogicalTypeID>{LogicalTypeID::VAR_LIST}, LogicalTypeID::INT64, execFunc,
true /* isVarlength*/));
result.push_back(std::make_unique<VectorFunctionDefinition>(SIZE_FUNC_NAME,
std::vector<LogicalTypeID>{LogicalTypeID::VAR_LIST}, LogicalTypeID::INT64,
UnaryExecFunction<list_entry_t, int64_t, ListLen>, true /* isVarlength*/));
result.push_back(std::make_unique<VectorFunctionDefinition>(CARDINALITY_FUNC_NAME,
std::vector<LogicalTypeID>{LogicalTypeID::MAP}, LogicalTypeID::INT64, execFunc,
true /* isVarlength*/));
std::vector<LogicalTypeID>{LogicalTypeID::MAP}, LogicalTypeID::INT64,
UnaryExecFunction<list_entry_t, int64_t, ListLen>, true /* isVarlength*/));
result.push_back(std::make_unique<VectorFunctionDefinition>(SIZE_FUNC_NAME,
std::vector<LogicalTypeID>{LogicalTypeID::STRING}, LogicalTypeID::INT64,
UnaryExecFunction<ku_string_t, int64_t, ListLen>, true /* isVarlength*/));
return result;
}

Expand Down
9 changes: 0 additions & 9 deletions src/function/vector_string_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "function/string/functions/contains_function.h"
#include "function/string/functions/ends_with_function.h"
#include "function/string/functions/left_operation.h"
#include "function/string/functions/length_function.h"
#include "function/string/functions/lpad_function.h"
#include "function/string/functions/regexp_extract_all_function.h"
#include "function/string/functions/regexp_extract_function.h"
Expand Down Expand Up @@ -168,14 +167,6 @@ vector_function_definitions LeftVectorFunction::getDefinitions() {
return definitions;
}

vector_function_definitions LengthVectorFunction::getDefinitions() {
vector_function_definitions definitions;
definitions.emplace_back(make_unique<VectorFunctionDefinition>(LENGTH_FUNC_NAME,
std::vector<LogicalTypeID>{LogicalTypeID::STRING}, LogicalTypeID::INT64,
UnaryExecFunction<ku_string_t, int64_t, Length>, false /* isVarLength */));
return definitions;
}

vector_function_definitions LpadVectorFunction::getDefinitions() {
vector_function_definitions definitions;
definitions.emplace_back(make_unique<VectorFunctionDefinition>(LPAD_FUNC_NAME,
Expand Down
2 changes: 1 addition & 1 deletion src/include/common/expression_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const std::string LIST_CREATION_FUNC_NAME = "LIST_CREATION";
const std::string LIST_RANGE_FUNC_NAME = "RANGE";
const std::string LIST_EXTRACT_FUNC_NAME = "LIST_EXTRACT";
const std::string LIST_ELEMENT_FUNC_NAME = "LIST_ELEMENT";
const std::string LIST_LEN_FUNC_NAME = "LEN";
const std::string LIST_CONCAT_FUNC_NAME = "LIST_CONCAT";
const std::string LIST_CAT_FUNC_NAME = "LIST_CAT";
const std::string ARRAY_CONCAT_FUNC_NAME = "ARRAY_CONCAT";
Expand Down Expand Up @@ -174,6 +173,7 @@ const std::string REGEXP_MATCHES_FUNC_NAME = "REGEXP_MATCHES";
const std::string REGEXP_REPLACE_FUNC_NAME = "REGEXP_REPLACE";
const std::string REGEXP_EXTRACT_FUNC_NAME = "REGEXP_EXTRACT";
const std::string REGEXP_EXTRACT_ALL_FUNC_NAME = "REGEXP_EXTRACT_ALL";
const std::string SIZE_FUNC_NAME = "SIZE";

// Date functions.
const std::string DATE_PART_FUNC_NAME = "DATE_PART";
Expand Down
25 changes: 24 additions & 1 deletion src/include/function/list/functions/list_len_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,39 @@
#include <cstring>

#include "common/types/ku_list.h"
#include "utf8proc.h"

namespace kuzu {
namespace function {

struct ListLen {
public:
static inline void operation(common::list_entry_t& input, int64_t& result) {
template<typename T>
static inline void operation(T& input, int64_t& result) {
result = input.size;
}
};

template<>
inline void ListLen::operation(common::ku_string_t& input, int64_t& result) {
auto totalByteLength = input.len;
auto inputString = input.getAsString();
for (auto i = 0; i < totalByteLength; i++) {
if (inputString[i] & 0x80) {
int64_t length = 0;
// Use grapheme iterator to identify bytes of utf8 char and increment once for each
// char.
utf8proc::utf8proc_grapheme_callback(
inputString.c_str(), totalByteLength, [&](size_t start, size_t end) {
length++;
return true;
});
result = length;
return;
}
}
result = totalByteLength;
}

} // namespace function
} // namespace kuzu
2 changes: 1 addition & 1 deletion src/include/function/list/vector_list_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ struct ListRangeVectorFunction : public VectorListFunction {
const binder::expression_vector& arguments, FunctionDefinition* definition);
};

struct ListLenVectorFunction : public VectorListFunction {
struct SizeVectorFunction : public VectorListFunction {
static vector_function_definitions getDefinitions();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cstring>

#include "common/types/ku_string.h"
#include "length_function.h"
#include "function/list/functions/list_len_function.h"
#include "substr_function.h"

namespace kuzu {
Expand All @@ -19,7 +19,7 @@ struct ArrayExtract {
}
auto stringVal = str.getAsString();
int64_t strLen;
Length::operation(str, strLen);
ListLen::operation(str, strLen);
auto idxPos = idx > 0 ? std::min(idx, strLen) : std::max(strLen + idx, (int64_t)0) + 1;
auto startPos = idxPos - 1;
auto endPos = startPos + 1;
Expand Down
4 changes: 2 additions & 2 deletions src/include/function/string/functions/left_operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cstring>

#include "common/types/ku_string.h"
#include "length_function.h"
#include "function/list/functions/list_len_function.h"
#include "substr_function.h"

namespace kuzu {
Expand All @@ -15,7 +15,7 @@ struct Left {
static inline void operation(common::ku_string_t& left, int64_t& right,
common::ku_string_t& result, common::ValueVector& resultValueVector) {
int64_t leftLen;
Length::operation(left, leftLen);
ListLen::operation(left, leftLen);
int64_t len =
(right > -1) ? std::min(leftLen, right) : std::max(leftLen + right, (int64_t)0);
SubStr::operation(left, 1, len, result, resultValueVector);
Expand Down
35 changes: 0 additions & 35 deletions src/include/function/string/functions/length_function.h

This file was deleted.

4 changes: 2 additions & 2 deletions src/include/function/string/functions/right_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cstring>

#include "common/types/ku_string.h"
#include "length_function.h"
#include "function/list/functions/list_len_function.h"
#include "substr_function.h"

namespace kuzu {
Expand All @@ -15,7 +15,7 @@ struct Right {
static inline void operation(common::ku_string_t& left, int64_t& right,
common::ku_string_t& result, common::ValueVector& resultValueVector) {
int64_t leftLen;
Length::operation(left, leftLen);
ListLen::operation(left, leftLen);
int64_t len =
(right > -1) ? std::min(leftLen, right) : std::max(leftLen + right, (int64_t)0);
SubStr::operation(left, leftLen - len + 1, len, result, resultValueVector);
Expand Down
4 changes: 0 additions & 4 deletions src/include/function/string/vector_string_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ struct LeftVectorFunction : public VectorStringFunction {
static vector_function_definitions getDefinitions();
};

struct LengthVectorFunction : public VectorStringFunction {
static vector_function_definitions getDefinitions();
};

struct LowerVectorFunction : public VectorStringFunction {
static inline vector_function_definitions getDefinitions() {
return getUnaryStrFunctionDefintion<Lower>(common::LOWER_FUNC_NAME);
Expand Down
2 changes: 1 addition & 1 deletion test/test_files/tinysnb/exception/list.test
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ Binder exception: Cannot bind LIST_CONCAT with parameter type INT64[] and STRING
Binder exception: Cannot bind LIST_CREATION with parameter type INT64 and STRING.

-CASE ListPrepareError
-STATEMENT MATCH (a:person) RETURN len($1)
-STATEMENT MATCH (a:person) RETURN size($1)
---- error
Binder exception: Cannot resolve recursive data type for expression $1.
2 changes: 1 addition & 1 deletion test/test_files/tinysnb/function/case.test
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Hubert Blaine Wolfeschlegelsteinhausenbergerdorff
7.100000

-LOG CaseListTest
-STATEMENT MATCH (a:person) WHERE a.ID > 6 RETURN CASE WHEN len(a.workedHours) = 1 THEN a.courseScoresPerTerm END
-STATEMENT MATCH (a:person) WHERE a.ID > 6 RETURN CASE WHEN size(a.workedHours) = 1 THEN a.courseScoresPerTerm END
---- 4


Expand Down
Loading

0 comments on commit d52b57a

Please sign in to comment.