Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path finding operator #135

Open
wants to merge 254 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
254 commits
Select commit Hold shift + click to select a range
18019af
Compiles
Dtenwolde Dec 19, 2023
407b465
Remove comment
Dtenwolde Jan 10, 2024
79bdc24
Merge branch 'main' into pathfindingoperator
Dtenwolde Feb 15, 2024
5799601
Format
Dtenwolde Feb 15, 2024
58db9d6
Builds
Dtenwolde Feb 15, 2024
97d6545
Change to range join type
Dtenwolde Feb 15, 2024
d016338
Removed returning PhysicaLPathFinding in planning comparison join
Dtenwolde Feb 15, 2024
a71a0d8
Removed returning PhysicaLPathFinding in planning comparison join
Dtenwolde Feb 15, 2024
43e2423
Remove some commented code
Dtenwolde Feb 15, 2024
38c3475
Remove unused include
Dtenwolde Feb 15, 2024
f98cf9b
Create between expression with tasks and csr
Dtenwolde Feb 15, 2024
e7060a0
Changed SubqueryRef to SubqueryExpression
Dtenwolde Feb 15, 2024
2bd008b
Merge branch 'main' into pathfindingoperator
Dtenwolde Feb 26, 2024
239cefe
Adding test
Dtenwolde Feb 26, 2024
00e9873
Fix
Dtenwolde Feb 26, 2024
9fcd2d4
Make subquery type any
Dtenwolde Feb 26, 2024
bde9097
Add compare equal
Dtenwolde Feb 26, 2024
26cadf1
Changing any type to scalar
Dtenwolde Feb 26, 2024
e4df300
Add optimizerextension
Dtenwolde Feb 26, 2024
ab12a42
Add function to find between expression
Dtenwolde Feb 26, 2024
d94ab61
Changing test slightly
Dtenwolde Feb 26, 2024
a46ff6e
Create plan
Dtenwolde Feb 26, 2024
9f68f3d
Make naming consistent
Dtenwolde Feb 27, 2024
e2349ee
Add import
Dtenwolde Feb 27, 2024
3856f22
Rename import
Dtenwolde Feb 27, 2024
ff27909
Remove explain
Dtenwolde Feb 27, 2024
ebb651d
Make names consistent
Dtenwolde Feb 27, 2024
6d7382c
Rename
Dtenwolde Feb 27, 2024
ad0b8fd
Fix test
Dtenwolde Feb 27, 2024
f9e078d
Format fix
Dtenwolde Feb 27, 2024
b1630b0
Format fix
Dtenwolde Feb 27, 2024
2d51385
Change constructro
Dtenwolde Feb 27, 2024
e0715e1
Now changing the logical operator to path finding operator
Dtenwolde Feb 27, 2024
184b917
Throw not implemented
Dtenwolde Feb 27, 2024
042abd9
Rename method
Dtenwolde Feb 27, 2024
2eaa6e8
Try column binding method
Dtenwolde Feb 27, 2024
be18b0c
Implement ResolveTypes
Dtenwolde Feb 27, 2024
13a31ae
Change config option debug print
Dtenwolde Feb 27, 2024
99819b0
Comment
Dtenwolde Feb 27, 2024
a4d85cb
Remove commented code
Dtenwolde Feb 27, 2024
92536ff
Add expressionexecutor
Dtenwolde Feb 27, 2024
2dd2996
Changed base class to PhysicalComparisonJoin so two children are allowed
Dtenwolde Feb 27, 2024
fcb9d57
Adding csr to operator
Dtenwolde Feb 28, 2024
8fc8618
Adding csr to operator
Dtenwolde Feb 28, 2024
a9520c4
Adding a local csr state
Dtenwolde Feb 28, 2024
72b9c08
Allow non-const first argument for create_csr_edge
Dtenwolde Mar 6, 2024
4792314
Optimizer rule to find csr creation and insert pathfinding operator
Dtenwolde Mar 6, 2024
6f737e8
Add ParamsToString method and add the expressions to logical operator
Dtenwolde Mar 6, 2024
ab1d6bc
Change order of execution children, add local and global csr to physi…
Dtenwolde Mar 6, 2024
2458325
Slightly change how csr is created, add more tuples to test
Dtenwolde Mar 6, 2024
11b0d10
bump
Dtenwolde Mar 6, 2024
8326114
Add initializeVertex method
Dtenwolde Mar 7, 2024
149bab3
Getting correct v_size now
Dtenwolde Mar 7, 2024
e87dd81
Adding print for debug
Dtenwolde Mar 7, 2024
97a21c4
Add w
Dtenwolde Mar 7, 2024
82fed52
Initialze e array
Dtenwolde Mar 7, 2024
9ea70a8
Create CSR
Dtenwolde Mar 7, 2024
8f15a41
Remove unused keys
Dtenwolde Mar 7, 2024
08179bb
Add IterativeLength functions
Dtenwolde Mar 7, 2024
d41fc4d
Change tests to be rowid
Dtenwolde Mar 7, 2024
fcc6a75
Fix incorrect index
Dtenwolde Mar 7, 2024
6833842
Use correct types
Dtenwolde Mar 7, 2024
737db39
Change type of pf result, move lstate to gstate
Dtenwolde Mar 12, 2024
d6c801b
Merge branch 'refs/heads/main' into pathfindingoperator
Dtenwolde Mar 20, 2024
54f4e42
Changed to ColumnDataCollection
Dtenwolde Mar 20, 2024
a50334c
Changed to ColumnDataCollection
Dtenwolde Mar 20, 2024
df01f0e
sequential algorithm runable
SiberiaWolfP Apr 1, 2024
e31b833
clean code
SiberiaWolfP Apr 2, 2024
8642326
make bfs support parallel
SiberiaWolfP Apr 4, 2024
8720721
update .gitignore
SiberiaWolfP Apr 4, 2024
8e34267
update
SiberiaWolfP Apr 5, 2024
7950d55
Adding new files
SiberiaWolfP Apr 5, 2024
9c0f90d
stupid parallel
SiberiaWolfP Apr 9, 2024
e62a5cf
lock and barrier sync
SiberiaWolfP Apr 14, 2024
5be7d82
Bottom-up BFS, but not applied
SiberiaWolfP Apr 16, 2024
5ab5e9a
work stealing
SiberiaWolfP Apr 16, 2024
c99f289
fix parallel bug
SiberiaWolfP Apr 18, 2024
1cc6f79
disable debug info
SiberiaWolfP Apr 18, 2024
52afb35
update csr creation
SiberiaWolfP Apr 22, 2024
056fc3d
Add test with iterativelength as extra column
Dtenwolde Apr 23, 2024
b6671db
Change iterativelength udf to also work with two columns
Dtenwolde Apr 23, 2024
ba56b4e
Change the BoundFunctionExpression of iterativlength to a BoundColumnRef
Dtenwolde Apr 23, 2024
59ed8d0
Add the extra ColumnBinding to the logical operator
Dtenwolde Apr 23, 2024
3693543
Format fix
Dtenwolde Apr 23, 2024
0048c4b
Remove comment
Dtenwolde Apr 23, 2024
fe66b50
parallel edge creation
SiberiaWolfP Apr 23, 2024
2f29872
code clear
SiberiaWolfP Apr 23, 2024
141cb10
add sequential algorithm back
SiberiaWolfP Apr 23, 2024
3c15e2d
code clear
SiberiaWolfP Apr 24, 2024
140820a
sequential CAS
SiberiaWolfP Apr 24, 2024
3f75658
reduce task creation cost
SiberiaWolfP Apr 24, 2024
d43b082
atomic v -> pod v
SiberiaWolfP Apr 25, 2024
64f9687
pod v -> atomic v
SiberiaWolfP Apr 25, 2024
bdbdd96
memory order relaxed
SiberiaWolfP Apr 25, 2024
b5e7b04
atomic bitset
SiberiaWolfP Apr 25, 2024
b5fd1dc
add timer
SiberiaWolfP Apr 26, 2024
0ef2a69
add timer to serial algorithm
SiberiaWolfP Apr 26, 2024
b41169b
return to serial next and visit
SiberiaWolfP Apr 27, 2024
e333ba2
delete barrier
SiberiaWolfP Apr 27, 2024
7f56ffe
don't split every iteration
SiberiaWolfP Apr 27, 2024
c6dbdfb
new spin lock
SiberiaWolfP Apr 27, 2024
6dd612a
Updating test with path length
Dtenwolde Apr 29, 2024
2471f70
Merge remote-tracking branch 'origin/pathfindingoperator' into pathfi…
Dtenwolde Apr 29, 2024
e51d40b
parallel path finding
SiberiaWolfP Apr 29, 2024
b5b7ce0
Merge
Dtenwolde Apr 29, 2024
fe6d4a0
Fix print
Dtenwolde Apr 29, 2024
8245e9e
Add shortestpath udf with only two parameters
Dtenwolde Apr 29, 2024
7b839e8
Update the test results
Dtenwolde Apr 29, 2024
7a5df92
In optimizer check for both iterativelength and shortestpath udfs
Dtenwolde Apr 29, 2024
608c872
Push either bigint or list(bigint) as types
Dtenwolde Apr 29, 2024
0ccb1d8
Add mode to physical path finding operator and return correct column …
Dtenwolde Apr 29, 2024
9e64319
add spin barrier and cas
SiberiaWolfP Apr 30, 2024
231bf63
bug found when pairs = 1
SiberiaWolfP May 2, 2024
3089c5e
solve bug when there are too many results
SiberiaWolfP May 2, 2024
bd82eb7
Merge branch 'refs/heads/main' into pathfindingoperator
Dtenwolde May 4, 2024
c55e035
Merge remote-tracking branch 'origin/pathfindingoperator' into pathfi…
Dtenwolde May 4, 2024
8e5d0cc
Add rule to disable path finding operator
Dtenwolde May 6, 2024
8fafd03
Add check if csr exists to prevent seg faults
Dtenwolde May 6, 2024
60f1c1e
Make tests pass and set option get the correct value
Dtenwolde May 6, 2024
74f54ca
Add table to scan argument to udf and tests
Dtenwolde May 7, 2024
8230603
Update the optimizer rule to also work with 1 pair
Dtenwolde May 7, 2024
52468d2
Fix function being set to incorrect column
Dtenwolde May 7, 2024
923ba69
dynamic tasks splitting
SiberiaWolfP May 17, 2024
1e7ec36
top-down and bottom-up cost
SiberiaWolfP May 28, 2024
b051999
code clean
SiberiaWolfP Jun 9, 2024
0fa68fc
no direction switch
SiberiaWolfP Jun 10, 2024
edc725c
no bottom up
SiberiaWolfP Jun 13, 2024
84d9cdb
fix option
SiberiaWolfP Jun 13, 2024
6bc4e88
no sync
SiberiaWolfP Jun 17, 2024
33cbcbd
add active count
SiberiaWolfP Jun 25, 2024
9bcbf37
time record
SiberiaWolfP Jun 26, 2024
0ebb0d5
fix time record bug
SiberiaWolfP Jun 26, 2024
67b30c2
reduce init time
SiberiaWolfP Jun 27, 2024
48d5080
add bottom-up again
SiberiaWolfP Jun 27, 2024
11f292a
fix seen set bug
SiberiaWolfP Jun 28, 2024
df4ff18
fix path record sync bug
SiberiaWolfP Jun 28, 2024
a7447d2
solve locks low performance
SiberiaWolfP Jun 28, 2024
863f28b
atomic path record
SiberiaWolfP Jun 28, 2024
5e97871
lock-free path record
SiberiaWolfP Jun 29, 2024
1f4149a
remove useless code
SiberiaWolfP Jun 29, 2024
c6c5241
final version
SiberiaWolfP Jul 9, 2024
4e64b0e
Merge remote-tracking branch 'origin/main' into pathfindingoperator
SiberiaWolfP Jul 9, 2024
07bd55a
fix compile bug
SiberiaWolfP Jul 10, 2024
285a285
Remove dependency of atomic library and point extension-ci-tools
Dtenwolde Jul 10, 2024
b7cc712
Update to latest extension-ci-tools
Dtenwolde Jul 12, 2024
726c116
disabling the requirement of the csr id as first argument. Tests now …
Dtenwolde Jul 12, 2024
57e7b83
Merge branch 'refs/heads/main' into pathfindingoperator
Dtenwolde Aug 12, 2024
8a8e1ac
Merge with latest main branch
Dtenwolde Aug 12, 2024
0914e9d
Add separate file for options
Dtenwolde Aug 12, 2024
3a862a8
Add options
Dtenwolde Aug 12, 2024
39731e6
Remove unused import
Dtenwolde Aug 12, 2024
67c821d
Adding optimizer rule
Dtenwolde Aug 12, 2024
f75bcf5
Adding coreoptimizer struct
Dtenwolde Aug 12, 2024
bb1f54d
Adding optimizer rule
Dtenwolde Aug 12, 2024
df89b62
Format fix
Dtenwolde Aug 12, 2024
e3d0eef
Remove commented out code
Dtenwolde Aug 12, 2024
b9c209e
Remove unused optimizer file
Dtenwolde Aug 12, 2024
720972f
Various fixes
Dtenwolde Aug 12, 2024
aaafc37
Add function to get option value
Dtenwolde Aug 12, 2024
d0a9038
Fix build errors
Dtenwolde Aug 12, 2024
7fa2095
Set default experimental path finding option to false
Dtenwolde Aug 14, 2024
13a0cf6
Get the option from the dbconfig
Dtenwolde Aug 14, 2024
02f4a5a
Getting the option now works correctly
Dtenwolde Aug 14, 2024
dc7d66f
Register shortest path and iterativelength functions correctly
Dtenwolde Aug 14, 2024
59fd63e
Add function to get csr id or throw error
Dtenwolde Aug 14, 2024
57ceaf4
Fix path in comment
Dtenwolde Aug 14, 2024
d5847ce
Add separate UDF for shortest path operator to keep logic separate
Dtenwolde Aug 14, 2024
57f4892
Register function
Dtenwolde Aug 14, 2024
587d2a7
Throw not implemented for the UDF itsefl
Dtenwolde Aug 14, 2024
85f15c7
Implement copy and equals and bind
Dtenwolde Aug 14, 2024
0bde3d9
Remove imports
Dtenwolde Aug 14, 2024
7d62c6a
Move csr function data to separate file for consistency
Dtenwolde Aug 14, 2024
751262e
Create separate csr operator function data
Dtenwolde Aug 14, 2024
30b3e54
Fix import
Dtenwolde Aug 14, 2024
1ee8ad0
Create separate logic for csr creation for operator
Dtenwolde Aug 14, 2024
10e6e51
Explicit
Dtenwolde Aug 14, 2024
7f77936
Format fix
Dtenwolde Aug 14, 2024
d2982ff
Update optimizer rule
Dtenwolde Aug 14, 2024
e00af17
Fix constructor and add import
Dtenwolde Aug 14, 2024
6716a08
Fix wrong function name
Dtenwolde Aug 14, 2024
2faf882
Adjust the tests to the correct function names
Dtenwolde Aug 14, 2024
6c5750a
Remove todo
Dtenwolde Aug 14, 2024
6776629
Adding iterativelength operator as well. All tests pass
Dtenwolde Aug 14, 2024
6265999
Make filename consistent
Dtenwolde Aug 15, 2024
3297856
Remove todo
Dtenwolde Aug 15, 2024
7a09530
Now getting the columnBinding not hardcoded
Dtenwolde Aug 15, 2024
3b1f192
Add tests
Dtenwolde Aug 15, 2024
181ddef
Merge branch 'refs/heads/main' into pathfindingoperator
Dtenwolde Aug 19, 2024
117da8a
Update header of test
Dtenwolde Aug 19, 2024
1cab561
Adding error handling
Dtenwolde Aug 19, 2024
d6eb5e7
Rename left and right child
Dtenwolde Aug 19, 2024
6533404
Get task value size properly
Dtenwolde Aug 19, 2024
c27b73a
Update path
Dtenwolde Aug 20, 2024
bd73dc4
Move barrier to separate file
Dtenwolde Aug 20, 2024
1bf7590
Move ve struct for path reconstruction to separate file
Dtenwolde Aug 20, 2024
51f8809
Remove extra qualification
Dtenwolde Aug 20, 2024
bbf8faa
Move shortet path event to separate file
Dtenwolde Aug 20, 2024
b350b23
Move task to separate file
Dtenwolde Aug 20, 2024
027a864
Move task to separate file
Dtenwolde Aug 20, 2024
5b81cb5
Remove override
Dtenwolde Aug 20, 2024
5836a80
Remove second constructor for globalbfsstate
Dtenwolde Aug 20, 2024
0bf5bc7
Move iterative length event and tasks to separate files
Dtenwolde Aug 20, 2024
5f77749
Remove overrides
Dtenwolde Aug 20, 2024
338cdbb
Mode csr edge creation task and event to separate files
Dtenwolde Aug 20, 2024
03e696e
Fix incorrect initialization of parents_ve
Dtenwolde Aug 20, 2024
c69b157
Adding a new test
Dtenwolde Aug 21, 2024
b3dd0dc
Initialize boundaries
Dtenwolde Aug 27, 2024
b786377
Rework task creation, instead have a single global queue of tasks
Dtenwolde Aug 27, 2024
0f155e2
Fetch task now fetches from global queue
Dtenwolde Aug 27, 2024
5020657
Use index to keep track of task queue
Dtenwolde Aug 27, 2024
12a2ff8
Set the task range in a method
Dtenwolde Aug 27, 2024
42ebe4e
Add possibility to reset counter inside barrier
Dtenwolde Aug 28, 2024
75f94e0
Set the number of threads to schedule to min of tasks and number of t…
Dtenwolde Aug 28, 2024
f5e2479
Make barrier unique ptr
Dtenwolde Aug 28, 2024
71d95be
Fix barrier being a pointer now
Dtenwolde Aug 28, 2024
0ef6b20
Fetch task and set range now work properly
Dtenwolde Aug 28, 2024
9a74c05
Add more elaborate test case with search where src == dst. Now also s…
Dtenwolde Aug 28, 2024
520d9d2
Update the test cases
Dtenwolde Aug 28, 2024
7a06c6b
Remove print and unused var
Dtenwolde Aug 28, 2024
1f7af77
remove print
Dtenwolde Aug 28, 2024
93832f6
Iterative length test now passing
Dtenwolde Aug 28, 2024
a77b9df
Setting change to false and adding correct test result
Dtenwolde Aug 29, 2024
e323d12
Adding basic cardinality estimation and paramsToString method
Dtenwolde Aug 29, 2024
15a8372
Move the getPathFindingOption method to the option file
Dtenwolde Aug 29, 2024
b10eeb1
Adding test case with slightly more complex pattern
Dtenwolde Aug 30, 2024
3332a06
Add ToString method for PGQMatchType
Dtenwolde Aug 30, 2024
55e27fa
Passing clientContext to methods to get the PathFindingOption
Dtenwolde Aug 30, 2024
04f8624
Merge branch 'main' into pathfindingoperator
Dtenwolde Sep 4, 2024
e1e9a2a
Register the new operators, got lost in merge
Dtenwolde Sep 4, 2024
092ef27
Fix csr index
Dtenwolde Sep 4, 2024
451297a
Adding test with PGQ syntax
Dtenwolde Sep 5, 2024
8ee8970
Select and from clauses
Dtenwolde Sep 5, 2024
790de5d
Fixed shortest path function expression
Dtenwolde Sep 5, 2024
447978d
Starting on pairs cte
Dtenwolde Sep 5, 2024
1b157f1
Finished pairs cte statement
Dtenwolde Sep 5, 2024
3921baa
Starting on csr operator subquery
Dtenwolde Sep 5, 2024
f996231
remove unused method
Dtenwolde Sep 5, 2024
990936d
Only missing group by for csr operator subquery
Dtenwolde Sep 5, 2024
4a39ec3
Add missing argument
Dtenwolde Sep 5, 2024
c2aa5c3
Remove left ofter utils folder
Dtenwolde Sep 5, 2024
7802fc4
Completed csr operator subquery
Dtenwolde Sep 5, 2024
1c5a57e
Fix incorrect subqueryRef
Dtenwolde Sep 5, 2024
5fdf509
Add check for where_clause
Dtenwolde Sep 5, 2024
a576e60
Remove print and add src and dst column to test
Dtenwolde Sep 5, 2024
287ae40
Add slightly more complex pattern
Dtenwolde Sep 5, 2024
18d6b66
Fix case insensitive issue
Dtenwolde Sep 5, 2024
3f6ae18
Include functional
Dtenwolde Sep 5, 2024
8bcad5e
Include condition_variables and atomic
Dtenwolde Sep 5, 2024
41484d5
Adding debug print
Dtenwolde Sep 9, 2024
de3bd84
Add more debug print
Dtenwolde Sep 9, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ duckdb_unittest_tempdir/
testext
test/python/__pycache__/
.Rhistory
.vscode
.venv
3 changes: 3 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
add_subdirectory(functions)
add_subdirectory(operator)
add_subdirectory(option)
add_subdirectory(optimizer)
add_subdirectory(parser)
add_subdirectory(utils)


set(EXTENSION_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/module.cpp
${EXTENSION_SOURCES}
Expand Down
3 changes: 3 additions & 0 deletions src/core/functions/function_data/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
set(EXTENSION_SOURCES
${EXTENSION_SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/cheapest_path_length_function_data.cpp
${CMAKE_CURRENT_SOURCE_DIR}/csr_function_data.cpp
${CMAKE_CURRENT_SOURCE_DIR}/csr_operator_function_data.cpp
${CMAKE_CURRENT_SOURCE_DIR}/iterative_length_function_data.cpp
${CMAKE_CURRENT_SOURCE_DIR}/local_clustering_coefficient_function_data.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pagerank_function_data.cpp
${CMAKE_CURRENT_SOURCE_DIR}/weakly_connected_component_function_data.cpp
${CMAKE_CURRENT_SOURCE_DIR}/shortest_path_operator_function_data.cpp

PARENT_SCOPE
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "duckpgq/core/functions/function_data/cheapest_path_length_function_data.hpp"
#include "duckpgq/core/utils/duckpgq_utils.hpp"
#include "duckdb/execution/expression_executor.hpp"

namespace duckpgq {

Expand All @@ -10,14 +9,8 @@ unique_ptr<FunctionData> CheapestPathLengthFunctionData::CheapestPathLengthBind(
ClientContext &context, ScalarFunction &bound_function,
vector<unique_ptr<Expression>> &arguments) {

if (!arguments[0]->IsFoldable()) {
throw InvalidInputException("Id must be constant.");
}

auto csr_id = GetCSRId(arguments[0], context);
auto duckpgq_state = GetDuckPGQState(context);

int32_t csr_id = ExpressionExecutor::EvaluateScalar(context, *arguments[0])
.GetValue<int32_t>();
CSR *csr = duckpgq_state->GetCSR(csr_id);

if (!(csr->initialized_v && csr->initialized_e && csr->initialized_w)) {
Expand Down
56 changes: 56 additions & 0 deletions src/core/functions/function_data/csr_function_data.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include "duckpgq/core/functions/function_data/csr_function_data.hpp"
#include <duckpgq/core/utils/compressed_sparse_row.hpp>

namespace duckpgq {

namespace core {

CSRFunctionData::CSRFunctionData(ClientContext &context, int32_t id,
LogicalType weight_type)
: context(context), id(id), weight_type(std::move(weight_type)) {}

unique_ptr<FunctionData> CSRFunctionData::Copy() const {
return make_uniq<CSRFunctionData>(context, id, weight_type);
}

bool CSRFunctionData::Equals(const FunctionData &other_p) const {
auto &other = (const CSRFunctionData &)other_p;
return id == other.id && weight_type == other.weight_type;
}


unique_ptr<FunctionData>
CSRFunctionData::CSRVertexBind(ClientContext &context,
ScalarFunction &bound_function,
vector<unique_ptr<Expression>> &arguments) {
auto csr_id = GetCSRId(arguments[0], context);
if (arguments.size() == 4) {
auto logical_type = LogicalType::SQLNULL;
return make_uniq<CSRFunctionData>(context, csr_id, logical_type);
}
return make_uniq<CSRFunctionData>(context, csr_id, arguments[3]->return_type);
}

unique_ptr<FunctionData>
CSRFunctionData::CSREdgeBind(ClientContext &context,
ScalarFunction &bound_function,
vector<unique_ptr<Expression>> &arguments) {
auto csr_id = GetCSRId(arguments[0], context);
if (arguments.size() == 8) {
return make_uniq<CSRFunctionData>(context, csr_id,
arguments[7]->return_type);
}
auto logical_type = LogicalType::SQLNULL;
return make_uniq<CSRFunctionData>(context, csr_id, logical_type);
}

unique_ptr<FunctionData>
CSRFunctionData::CSRBind(ClientContext &context, ScalarFunction &bound_function,
vector<unique_ptr<Expression>> &arguments) {
auto csr_id = GetCSRId(arguments[0], context);
return make_uniq<CSRFunctionData>(context, csr_id, LogicalType::BOOLEAN);
}

} // namespace core

} // namespace duckpgq
28 changes: 28 additions & 0 deletions src/core/functions/function_data/csr_operator_function_data.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "duckpgq/core/functions/function_data/csr_operator_function_data.hpp"

namespace duckpgq {

namespace core {

CSROperatorFunctionData::CSROperatorFunctionData(ClientContext &context)
: context(context) {}

unique_ptr<FunctionData> CSROperatorFunctionData::Copy() const {
return make_uniq<CSROperatorFunctionData>(context);
}

unique_ptr<FunctionData>
CSROperatorFunctionData::CSRBind(ClientContext &context,
ScalarFunction &bound_function,
vector<unique_ptr<Expression>> &arguments) {
return make_uniq<CSROperatorFunctionData>(context);
}

bool CSROperatorFunctionData::Equals(const FunctionData &other_p) const {
// TODO implement me
// auto &other = (const CSROperatorFunctionData &)other_p;
return true;
}
} // namespace core

} // namespace duckpgq
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include "duckpgq/core/functions/function_data/iterative_length_function_data.hpp"
#include "duckdb/execution/expression_executor.hpp"
#include "duckpgq/common.hpp"

#include <duckpgq/core/utils/compressed_sparse_row.hpp>

namespace duckpgq {

namespace core {

unique_ptr<FunctionData> IterativeLengthFunctionData::Copy() const {
return make_uniq<IterativeLengthFunctionData>(context, csr_id);
return make_uniq<IterativeLengthFunctionData>(context, table_to_scan, csr_id);
}

bool IterativeLengthFunctionData::Equals(const FunctionData &other_p) const {
Expand All @@ -19,14 +20,13 @@ bool IterativeLengthFunctionData::Equals(const FunctionData &other_p) const {
unique_ptr<FunctionData> IterativeLengthFunctionData::IterativeLengthBind(
ClientContext &context, ScalarFunction &bound_function,
vector<unique_ptr<Expression>> &arguments) {
if (!arguments[0]->IsFoldable()) {
throw InvalidInputException("Id must be constant.");
if (arguments.size() == 3) {
string table_to_scan = ExpressionExecutor::EvaluateScalar(context, *arguments[2]).GetValue<string>();
return make_uniq<IterativeLengthFunctionData>(context, table_to_scan, 0);
}
auto csr_id = GetCSRId(arguments[0], context);

int32_t csr_id = ExpressionExecutor::EvaluateScalar(context, *arguments[0])
.GetValue<int32_t>();

return make_uniq<IterativeLengthFunctionData>(context, csr_id);
return make_uniq<IterativeLengthFunctionData>(context, "", csr_id);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "duckpgq/core/functions/function_data/local_clustering_coefficient_function_data.hpp"
#include "duckdb/execution/expression_executor.hpp"
#include <duckpgq/core/utils/compressed_sparse_row.hpp>

namespace duckpgq {

Expand All @@ -15,12 +15,7 @@ unique_ptr<FunctionData>
LocalClusteringCoefficientFunctionData::LocalClusteringCoefficientBind(
ClientContext &context, ScalarFunction &bound_function,
vector<unique_ptr<Expression>> &arguments) {
if (!arguments[0]->IsFoldable()) {
throw InvalidInputException("Id must be constant.");
}

int32_t csr_id = ExpressionExecutor::EvaluateScalar(context, *arguments[0])
.GetValue<int32_t>();
auto csr_id = GetCSRId(arguments[0], context);

return make_uniq<LocalClusteringCoefficientFunctionData>(context, csr_id);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "duckpgq/core/functions/function_data/shortest_path_operator_function_data.hpp"
#include <duckpgq/core/utils/compressed_sparse_row.hpp>

namespace duckpgq {

namespace core {

unique_ptr<FunctionData>
ShortestPathOperatorData::ShortestPathOperatorBind(
ClientContext &context, ScalarFunction &bound_function,
vector<unique_ptr<Expression>> &arguments) {
string table_to_scan = ExpressionExecutor::EvaluateScalar(context, *arguments[2]).GetValue<string>();
return make_uniq<ShortestPathOperatorData>(context, table_to_scan);
}
unique_ptr<FunctionData> ShortestPathOperatorData::Copy() const {
return make_uniq<ShortestPathOperatorData>(context, table_to_scan);
}

bool ShortestPathOperatorData::Equals(const FunctionData &other_p) const {
auto &other = (const ShortestPathOperatorData &)other_p;
return other.table_to_scan == table_to_scan;
}

} // namespace core

} // namespace duckpgq
3 changes: 3 additions & 0 deletions src/core/functions/scalar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ set(EXTENSION_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/csr_creation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/csr_deletion.cpp
${CMAKE_CURRENT_SOURCE_DIR}/csr_get_w_type.cpp
${CMAKE_CURRENT_SOURCE_DIR}/csr_operator_creation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/iterativelength.cpp
${CMAKE_CURRENT_SOURCE_DIR}/iterativelength2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/iterativelength_bidirectional.cpp
${CMAKE_CURRENT_SOURCE_DIR}/iterativelength_operator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pagerank.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reachability.cpp
${CMAKE_CURRENT_SOURCE_DIR}/shortest_path.cpp
${CMAKE_CURRENT_SOURCE_DIR}/shortest_path_operator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/csr_creation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/local_clustering_coefficient.cpp
${CMAKE_CURRENT_SOURCE_DIR}/weakly_connected_component.cpp
Expand Down
20 changes: 17 additions & 3 deletions src/core/functions/scalar/csr_creation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
#include "duckpgq/common.hpp"
#include "duckpgq/core/utils/compressed_sparse_row.hpp"
#include <cmath>
#include <duckpgq/core/functions/function_data/csr_function_data.hpp>
#include <duckpgq/core/functions/scalar.hpp>
#include <duckpgq/core/utils/duckpgq_utils.hpp>
#include <duckpgq_extension.hpp>
#include <mutex>

namespace duckpgq {

Expand Down Expand Up @@ -49,6 +48,9 @@ static void CsrInitializeEdge(DuckPGQState &context, int32_t id, int64_t v_size,
const lock_guard<mutex> csr_init_lock(context.csr_lock);

auto csr_entry = context.csr_list.find(id);
if (csr_entry == context.csr_list.end()) {
throw InvalidInputException("CSR has not been initialized properly");
}
if (csr_entry->second->initialized_e) {
return;
}
Expand All @@ -70,7 +72,9 @@ static void CsrInitializeWeight(DuckPGQState &context, int32_t id,
int64_t e_size, PhysicalType weight_type) {
const lock_guard<mutex> csr_init_lock(context.csr_lock);
auto csr_entry = context.csr_list.find(id);

if (csr_entry == context.csr_list.end()) {
throw InvalidInputException("CSR has not been initialized properly");
}
if (csr_entry->second->initialized_w) {
return;
}
Expand Down Expand Up @@ -143,6 +147,9 @@ static void CreateCsrEdgeFunction(DataChunk &args, ExpressionState &state,
}

auto csr_entry = duckpgq_state->csr_list.find(info.id);
if (csr_entry == duckpgq_state->csr_list.end()) {
throw InvalidInputException("CSR has not been initialized properly");
}
if (!csr_entry->second->initialized_e) {
CsrInitializeEdge(*duckpgq_state, info.id, vertex_size, edge_size);
}
Expand Down Expand Up @@ -211,6 +218,13 @@ ScalarFunctionSet GetCSREdgeFunction() {
* 7. <optional> edge weight (INT OR DOUBLE)
*/


set.AddFunction(ScalarFunction({LogicalType::BIGINT, LogicalType::BIGINT,
LogicalType::BIGINT, LogicalType::BIGINT,
LogicalType::BIGINT, LogicalType::BIGINT},
LogicalType::INTEGER, CreateCsrEdgeFunction,
CSRFunctionData::CSREdgeBind));

//! No edge weight
set.AddFunction(ScalarFunction({LogicalType::INTEGER, LogicalType::BIGINT,
LogicalType::BIGINT, LogicalType::BIGINT, LogicalType::BIGINT,
Expand Down
2 changes: 1 addition & 1 deletion src/core/functions/scalar/csr_deletion.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "duckdb/main/client_data.hpp"
#include "duckdb/planner/expression/bound_function_expression.hpp"
#include "duckpgq/common.hpp"
#include <duckpgq/core/functions/function_data/csr_function_data.hpp>
#include <duckpgq/core/functions/scalar.hpp>
#include <duckpgq/core/utils/duckpgq_utils.hpp>
#include <duckpgq_extension.hpp>

namespace duckpgq {

Expand Down
1 change: 1 addition & 0 deletions src/core/functions/scalar/csr_get_w_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "duckpgq/common.hpp"
#include <duckpgq_extension.hpp>

#include <duckpgq/core/functions/function_data/csr_function_data.hpp>
#include <duckpgq/core/functions/scalar.hpp>
#include <duckpgq/core/utils/duckpgq_utils.hpp>

Expand Down
33 changes: 33 additions & 0 deletions src/core/functions/scalar/csr_operator_creation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "duckdb/function/scalar_function.hpp"
#include "duckpgq/common.hpp"
#include <duckpgq/core/functions/function_data/csr_operator_function_data.hpp>
#include <duckpgq/core/functions/scalar.hpp>

namespace duckpgq {

namespace core {

static void CreateCSROperatorFunction(DataChunk &args, ExpressionState &state,
Vector &result) {
throw NotImplementedException(
"CSR operator creation function not implemented, should have gone to "
"operator instead.");
}

//------------------------------------------------------------------------------
// Register functions
//------------------------------------------------------------------------------
void CoreScalarFunctions::RegisterCSROperatorCreationScalarFunctions(
DatabaseInstance &db) {
ExtensionUtil::RegisterFunction(
db, ScalarFunction("csr_operator",
{LogicalType::BIGINT, LogicalType::BIGINT,
LogicalType::BIGINT, LogicalType::BIGINT,
LogicalType::BIGINT, LogicalType::BIGINT},
LogicalType::INTEGER, CreateCSROperatorFunction,
CSROperatorFunctionData::CSRBind));
}

} // namespace core

} // namespace duckpgq
26 changes: 18 additions & 8 deletions src/core/functions/scalar/iterativelength.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,31 @@ static void IterativeLengthFunction(DataChunk &args, ExpressionState &state,
duckpgq_state->csr_to_delete.insert(info.csr_id);
}

ScalarFunctionSet GetIterativeLengthFunction() {
ScalarFunctionSet set("iterativelength");

set.AddFunction(ScalarFunction(
{LogicalType::INTEGER, LogicalType::BIGINT,
LogicalType::BIGINT, LogicalType::BIGINT},
LogicalType::BIGINT, IterativeLengthFunction,
IterativeLengthFunctionData::IterativeLengthBind));

set.AddFunction(
ScalarFunction(
{LogicalType::BIGINT, LogicalType::BIGINT, LogicalType::VARCHAR},
LogicalType::BIGINT, IterativeLengthFunction,
IterativeLengthFunctionData::IterativeLengthBind));
return set;
}

//------------------------------------------------------------------------------
// Register functions
//------------------------------------------------------------------------------
void CoreScalarFunctions::RegisterIterativeLengthScalarFunction(
DatabaseInstance &db) {
ExtensionUtil::RegisterFunction(
db,
ScalarFunction("iterativelength",
{LogicalType::INTEGER, LogicalType::BIGINT,
LogicalType::BIGINT, LogicalType::BIGINT},
LogicalType::BIGINT, IterativeLengthFunction,
IterativeLengthFunctionData::IterativeLengthBind));
ExtensionUtil::RegisterFunction(db, GetIterativeLengthFunction());
}

} // namespace core

} // namespace duckpgq

Loading
Loading