Skip to content

Commit

Permalink
Add doc example to test framework (#3426)
Browse files Browse the repository at this point in the history
  • Loading branch information
acquamarin committed May 1, 2024
1 parent 978e7c5 commit 6bd19bd
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/function/function_collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "function/table/call_functions.h"
#include "function/timestamp/vector_timestamp_functions.h"
#include "function/union/vector_union_functions.h"
#include "function/utility/scalar_utility_functions.h"
#include "function/utility/vector_utility_functions.h"
#include "function/uuid/vector_uuid_functions.h"
#include "processor/operator/persistent/reader/csv/parallel_csv_reader.h"
#include "processor/operator/persistent/reader/csv/serial_csv_reader.h"
Expand Down
4 changes: 3 additions & 1 deletion src/function/utility/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
add_library(kuzu_utility_function
OBJECT
coalesce.cpp)
coalesce.cpp
md5.cpp
sha256.cpp)

set(ALL_OBJECT_FILES
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:kuzu_utility_function>
Expand Down
2 changes: 1 addition & 1 deletion src/function/utility/coalesce.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "binder/expression/expression_util.h"
#include "common/exception/binder.h"
#include "function/scalar_function.h"
#include "function/utility/scalar_utility_functions.h"
#include "function/utility/vector_utility_functions.h"

using namespace kuzu::common;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "common/md5.h"
#include "common/vector/value_vector.h"

#include "function/hash/vector_hash_functions.h"
#include "function/scalar_function.h"

using namespace kuzu::common;

Expand All @@ -16,5 +16,13 @@ struct MD5Operator {
}
};

function_set MD5Function::getFunctionSet() {
function_set functionSet;
functionSet.push_back(std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::STRING}, LogicalTypeID::STRING,
ScalarFunction::UnaryStringExecFunction<ku_string_t, ku_string_t, MD5Operator>));
return functionSet;
}

} // namespace function
} // namespace kuzu
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "common/sha256.h"
#include "common/vector/value_vector.h"

#include "function/hash/vector_hash_functions.h"
#include "function/scalar_function.h"

using namespace kuzu::common;

Expand All @@ -17,5 +17,13 @@ struct SHA256Operator {
}
};

function_set SHA256Function::getFunctionSet() {
function_set functionSet;
functionSet.push_back(std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::STRING}, LogicalTypeID::STRING,
ScalarFunction::UnaryStringExecFunction<ku_string_t, ku_string_t, SHA256Operator>));
return functionSet;
}

} // namespace function
} // namespace kuzu
18 changes: 0 additions & 18 deletions src/function/vector_hash_functions.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "function/hash/vector_hash_functions.h"

#include "function/binary_function_executor.h"
#include "function/hash/functions/md5_function.h"
#include "function/hash/functions/sha256_function.h"
#include "function/hash/hash_functions.h"
#include "function/scalar_function.h"

Expand Down Expand Up @@ -200,22 +198,6 @@ void VectorHashFunction::combineHash(ValueVector* left, ValueVector* right, Valu
BinaryFunctionExecutor::execute<hash_t, hash_t, hash_t, CombineHash>(*left, *right, *result);
}

function_set MD5Function::getFunctionSet() {
function_set functionSet;
functionSet.push_back(std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::STRING}, LogicalTypeID::STRING,
ScalarFunction::UnaryStringExecFunction<ku_string_t, ku_string_t, MD5Operator>));
return functionSet;
}

function_set SHA256Function::getFunctionSet() {
function_set functionSet;
functionSet.push_back(std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::STRING}, LogicalTypeID::STRING,
ScalarFunction::UnaryStringExecFunction<ku_string_t, ku_string_t, SHA256Operator>));
return functionSet;
}

static void HashExecFunc(const std::vector<std::shared_ptr<common::ValueVector>>& params,
common::ValueVector& result, void* /*dataPtr*/ = nullptr) {
KU_ASSERT(params.size() == 1);
Expand Down
15 changes: 15 additions & 0 deletions test/test_files/function/hash/hash.test
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,18 @@
-STATEMENT RETURN hash(list_creation(1,2,3,4,5,56,2));
---- 1
5340394995802248375

-LOG MD5Example
-STATEMENT RETURN md5('kuzu')
---- 1
caca2358cada60d679fc0310d440f8ca

-LOG SHA256Example
-STATEMENT RETURN sha256('kuzu')
---- 1
e129f5000a4b71ccc3a0e6353a86cc57989106e670793db98efa34b7527aefa5

-LOG Murmurhash64Example
-STATEMENT RETURN hash('kuzu')
---- 1
-144620710730482887
8 changes: 8 additions & 0 deletions test/test_files/function/utility/coalesce.test
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,11 @@ Binder exception: Expression t.c has data type STRING but expected INT32. Implic
-STATEMENT MATCH (t:tbl) WHERE NOT ifnull(NULL, t.bool) RETURN t.id;
---- 1
2

-LOG Example
-STATEMENT RETURN coalesce(NULL, 'a', NULL);
---- 1
a
-STATEMENT RETURN ifnull(NULL, 'a')
---- 1
a

0 comments on commit 6bd19bd

Please sign in to comment.