diff --git a/duckpgq/src/duckpgq/functions/scalar/csr_creation.cpp b/duckpgq/src/duckpgq/functions/scalar/csr_creation.cpp index 14f954ef..c9c5180a 100644 --- a/duckpgq/src/duckpgq/functions/scalar/csr_creation.cpp +++ b/duckpgq/src/duckpgq/functions/scalar/csr_creation.cpp @@ -36,7 +36,8 @@ static void CsrInitializeVertex(DuckPGQState &context, int32_t id, csr->initialized_v = true; context.csr_list[id] = std::move(csr); } catch (std::bad_alloc const &) { - throw Exception(ExceptionType::INTERNAL, "Unable to initialize vector of size for csr vertex table " + throw Exception(ExceptionType::INTERNAL, + "Unable to initialize vector of size for csr vertex table " "representation"); } @@ -55,7 +56,8 @@ static void CsrInitializeEdge(DuckPGQState &context, int32_t id, int64_t v_size, csr_entry->second->e.resize(e_size, 0); csr_entry->second->edge_ids.resize(e_size, 0); } catch (std::bad_alloc const &) { - throw Exception(ExceptionType::INTERNAL, "Unable to initialize vector of size for csr edge table " + throw Exception(ExceptionType::INTERNAL, + "Unable to initialize vector of size for csr edge table " "representation"); } for (auto i = 1; i < v_size + 2; i++) { @@ -82,7 +84,8 @@ static void CsrInitializeWeight(DuckPGQState &context, int32_t id, throw NotImplementedException("Unrecognized weight type detected."); } } catch (std::bad_alloc const &) { - throw Exception(ExceptionType::INTERNAL, "Unable to initialize vector of size for csr weight table " + throw Exception(ExceptionType::INTERNAL, + "Unable to initialize vector of size for csr weight table " "representation"); } diff --git a/duckpgq/src/duckpgq/functions/scalar/iterativelength.cpp b/duckpgq/src/duckpgq/functions/scalar/iterativelength.cpp index 10ab0113..a86e836d 100644 --- a/duckpgq/src/duckpgq/functions/scalar/iterativelength.cpp +++ b/duckpgq/src/duckpgq/functions/scalar/iterativelength.cpp @@ -113,9 +113,12 @@ static void IterativeLengthFunction(DataChunk &args, ExpressionState &state, while (started_searches < args.size()) { int64_t search_num = started_searches++; int64_t src_pos = vdata_src.sel->get_index(search_num); + int64_t dst_pos = vdata_dst.sel->get_index(search_num); if (!vdata_src.validity.RowIsValid(src_pos)) { result_validity.SetInvalid(search_num); result_data[search_num] = (int64_t)-1; /* no path */ + } else if (src_data[src_pos] == dst_data[dst_pos]) { + result_data[search_num] = (int64_t)0; /* source == destination, length is 0 */ } else { result_data[search_num] = (int64_t)-1; /* initialize to no path */ visit1[src_data[src_pos]][lane] = true; diff --git a/duckpgq/src/duckpgq/functions/scalar/iterativelength_lowerbound.cpp b/duckpgq/src/duckpgq/functions/scalar/iterativelength_lowerbound.cpp index 8c8c5f89..f23dfeb7 100644 --- a/duckpgq/src/duckpgq/functions/scalar/iterativelength_lowerbound.cpp +++ b/duckpgq/src/duckpgq/functions/scalar/iterativelength_lowerbound.cpp @@ -8,10 +8,9 @@ namespace duckdb { static bool IterativeLengthLowerBound(int64_t v_size, int64_t *v, vector &e, - // vector>> &parents_v, - vector> &seen, - vector> &visit, - vector> &next) { + vector> &seen, + vector> &visit, + vector> &next) { bool change = false; for (auto i = 0; i < v_size; i++) { next[i] = 0; @@ -23,11 +22,6 @@ static bool IterativeLengthLowerBound(int64_t v_size, int64_t *v, vector> seen(v_size); vector> visit1(v_size); vector> visit2(v_size); - vector>> parents_v(v_size, std::vector>(LANE_LIMIT)); + vector>> parents_v( + v_size, std::vector>(LANE_LIMIT)); // maps lane to search number short lane_to_num[LANE_LIMIT]; @@ -129,7 +125,7 @@ static void IterativeLengthLowerBoundFunction(DataChunk &args, ExpressionState & while (started_searches < args.size()) { int64_t search_num = started_searches++; int64_t src_pos = vdata_src.sel->get_index(search_num); - if (!vdata_src.validity.RowIsValid(src_pos)) { + if (!vdata_src.validity.RowIsValid(src_pos)) { // NULL value result_validity.SetInvalid(search_num); result_data[search_num] = (int64_t)-1; /* no path */ } else { @@ -144,8 +140,9 @@ static void IterativeLengthLowerBoundFunction(DataChunk &args, ExpressionState & // make passes while a lane is still active for (int64_t iter = 1; active && iter <= upper_bound; iter++) { - if (!IterativeLengthLowerBound(v_size, v, e, seen, (iter & 1) ? visit1 : visit2, - (iter & 1) ? visit2 : visit1)) { + if (!IterativeLengthLowerBound(v_size, v, e, seen, + (iter & 1) ? visit1 : visit2, + (iter & 1) ? visit2 : visit1)) { break; } // detect lanes that finished @@ -153,7 +150,7 @@ static void IterativeLengthLowerBoundFunction(DataChunk &args, ExpressionState & int64_t search_num = lane_to_num[lane]; if (search_num >= 0) { // active lane int64_t dst_pos = vdata_dst.sel->get_index(search_num); - if (seen[dst_data[dst_pos]][lane]){ + if (seen[dst_data[dst_pos]][lane]) { // check if the path length is within bounds // bound vector is either a constant or a flat vector @@ -170,7 +167,6 @@ static void IterativeLengthLowerBoundFunction(DataChunk &args, ExpressionState & lane_to_num[lane] = -1; // mark inactive active--; } - } } } @@ -189,13 +185,14 @@ static void IterativeLengthLowerBoundFunction(DataChunk &args, ExpressionState & duckpgq_state->csr_to_delete.insert(info.csr_id); } -CreateScalarFunctionInfo DuckPGQFunctions::GetIterativeLengthLowerBoundFunction() { - auto fun = ScalarFunction("iterativelength_lowerbound", - {LogicalType::INTEGER, LogicalType::BIGINT, - LogicalType::BIGINT, LogicalType::BIGINT, - LogicalType::BIGINT, LogicalType::BIGINT}, - LogicalType::BIGINT, IterativeLengthLowerBoundFunction, - IterativeLengthFunctionData::IterativeLengthBind); +CreateScalarFunctionInfo +DuckPGQFunctions::GetIterativeLengthLowerBoundFunction() { + auto fun = ScalarFunction( + "iterativelength_lowerbound", + {LogicalType::INTEGER, LogicalType::BIGINT, LogicalType::BIGINT, + LogicalType::BIGINT, LogicalType::BIGINT, LogicalType::BIGINT}, + LogicalType::BIGINT, IterativeLengthLowerBoundFunction, + IterativeLengthFunctionData::IterativeLengthBind); return CreateScalarFunctionInfo(fun); } diff --git a/duckpgq/src/duckpgq/functions/scalar/reachability.cpp b/duckpgq/src/duckpgq/functions/scalar/reachability.cpp index 5c6443fb..1408bd60 100644 --- a/duckpgq/src/duckpgq/functions/scalar/reachability.cpp +++ b/duckpgq/src/duckpgq/functions/scalar/reachability.cpp @@ -245,7 +245,8 @@ static void ReachabilityFunction(DataChunk &args, ExpressionState &state, break; } default: - throw Exception(ExceptionType::INTERNAL, "Unknown reachability mode encountered"); + throw Exception(ExceptionType::INTERNAL, + "Unknown reachability mode encountered"); } } else { exit_early = BfsWithoutArray(exit_early, csr, input_size, seen, visit, diff --git a/duckpgq/src/duckpgq/functions/scalar/shortest_path.cpp b/duckpgq/src/duckpgq/functions/scalar/shortest_path.cpp index 7f857204..19a43ec5 100644 --- a/duckpgq/src/duckpgq/functions/scalar/shortest_path.cpp +++ b/duckpgq/src/duckpgq/functions/scalar/shortest_path.cpp @@ -236,13 +236,12 @@ static void ShortestPathFunction(DataChunk &args, ExpressionState &state, } CreateScalarFunctionInfo DuckPGQFunctions::GetShortestPathFunction() { - auto fun = ScalarFunction("shortestpath", - {LogicalType::INTEGER, LogicalType::BIGINT, - LogicalType::BIGINT, LogicalType::BIGINT, - LogicalType::BIGINT, LogicalType::BIGINT}, - LogicalType::LIST(LogicalType::BIGINT), - ShortestPathFunction, - IterativeLengthFunctionData::IterativeLengthBind); + auto fun = ScalarFunction( + "shortestpath", + {LogicalType::INTEGER, LogicalType::BIGINT, LogicalType::BIGINT, + LogicalType::BIGINT, LogicalType::BIGINT, LogicalType::BIGINT}, + LogicalType::LIST(LogicalType::BIGINT), ShortestPathFunction, + IterativeLengthFunctionData::IterativeLengthBind); return CreateScalarFunctionInfo(fun); } diff --git a/duckpgq/src/duckpgq/functions/scalar/shortest_path_lowerbound.cpp b/duckpgq/src/duckpgq/functions/scalar/shortest_path_lowerbound.cpp index c1af6859..03d87e41 100644 --- a/duckpgq/src/duckpgq/functions/scalar/shortest_path_lowerbound.cpp +++ b/duckpgq/src/duckpgq/functions/scalar/shortest_path_lowerbound.cpp @@ -12,13 +12,12 @@ namespace duckdb { static bool IterativeLengthLowerBound(int64_t v_size, int64_t *V, vector &E, - vector &edge_ids, - // vector>> &parents_v, - vector>> &paths_v, - vector>> &paths_e, - vector> &seen, - vector> &visit, - vector> &next) { + vector &edge_ids, + vector>> &paths_v, + vector>> &paths_e, + vector> &seen, + vector> &visit, + vector> &next) { bool change = false; // map, unordered_set> parents_v_cache; map, vector> paths_v_cache; @@ -36,7 +35,8 @@ static bool IterativeLengthLowerBound(int64_t v_size, int64_t *V, vector> visit1(v_size); vector> visit2(v_size); - // vector>> parents_v(v_size, std::vector>(LANE_LIMIT)); - vector>> paths_v(v_size, std::vector>(LANE_LIMIT)); - vector>> paths_e(v_size, std::vector>(LANE_LIMIT)); - + vector>> paths_v( + v_size, std::vector>(LANE_LIMIT)); + vector>> paths_e( + v_size, std::vector>(LANE_LIMIT)); // maps lane to search number int16_t lane_to_num[LANE_LIMIT]; @@ -171,9 +169,9 @@ static void ShortestPathLowerBoundFunction(DataChunk &args, ExpressionState &sta //! make passes while a lane is still active for (int64_t iter = 1; active && iter <= upper_bound; iter++) { //! Perform one step of bfs exploration - if (!IterativeLengthLowerBound(v_size, v, e, edge_ids, paths_v, paths_e, seen, - (iter & 1) ? visit1 : visit2, - (iter & 1) ? visit2 : visit1)) { + if (!IterativeLengthLowerBound( + v_size, v, e, edge_ids, paths_v, paths_e, seen, + (iter & 1) ? visit1 : visit2, (iter & 1) ? visit2 : visit1)) { break; } // detect lanes that finished @@ -192,7 +190,7 @@ static void ShortestPathLowerBoundFunction(DataChunk &args, ExpressionState &sta auto it_v = paths_v[dst_data[dst_pos]][lane].begin(), end_v = paths_v[dst_data[dst_pos]][lane].end(); auto it_e = paths_e[dst_data[dst_pos]][lane].begin(), - end_e = paths_e[dst_data[dst_pos]][lane].end(); + end_e = paths_e[dst_data[dst_pos]][lane].end(); while (it_v != end_v && it_e != end_e) { output_vector.push_back(*it_v); output_vector.push_back(*it_e); @@ -200,7 +198,8 @@ static void ShortestPathLowerBoundFunction(DataChunk &args, ExpressionState &sta it_e++; } output_vector.push_back(dst_data[dst_pos]); - auto output = make_uniq(LogicalType::LIST(LogicalType::BIGINT)); + auto output = + make_uniq(LogicalType::LIST(LogicalType::BIGINT)); for (auto val : output_vector) { Value value_to_insert = val; ListVector::PushBack(*output, value_to_insert); @@ -208,7 +207,7 @@ static void ShortestPathLowerBoundFunction(DataChunk &args, ExpressionState &sta result_data[search_num].length = ListVector::GetListSize(*output); result_data[search_num].offset = total_len; ListVector::Append(result, ListVector::GetEntry(*output), - ListVector::GetListSize(*output)); + ListVector::GetListSize(*output)); total_len += result_data[search_num].length; lane_to_num[lane] = -1; // mark inactive } @@ -222,7 +221,7 @@ static void ShortestPathLowerBoundFunction(DataChunk &args, ExpressionState &sta int64_t search_num = lane_to_num[lane]; if (search_num >= 0) { // active lane result_validity.SetInvalid(search_num); - lane_to_num[lane] = -1; // mark inactive + lane_to_num[lane] = -1; // mark inactive } } } @@ -230,13 +229,12 @@ static void ShortestPathLowerBoundFunction(DataChunk &args, ExpressionState &sta } // CreateScalarFunctionInfo DuckPGQFunctions::GetShortestPathLowerBoundFunction() { -// auto fun = ScalarFunction("shortestpath_lowerbound", -// {LogicalType::INTEGER, LogicalType::BIGINT, -// LogicalType::BIGINT, LogicalType::BIGINT, -// LogicalType::BIGINT, LogicalType::BIGINT}, -// LogicalType::LIST(LogicalType::BIGINT), -// ShortestPathLowerBoundFunction, -// IterativeLengthFunctionData::IterativeLengthBind); +// auto fun = ScalarFunction( +// "shortestpath_lowerbound", +// {LogicalType::INTEGER, LogicalType::BIGINT, LogicalType::BIGINT, +// LogicalType::BIGINT, LogicalType::BIGINT, LogicalType::BIGINT}, +// LogicalType::LIST(LogicalType::BIGINT), ShortestPathLowerBoundFunction, +// IterativeLengthFunctionData::IterativeLengthBind); // return CreateScalarFunctionInfo(fun); // } diff --git a/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp b/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp index c8ce874e..58db4769 100644 --- a/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp +++ b/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp @@ -7,15 +7,17 @@ void CreatePropertyGraphFunction::CheckPropertyGraphTableLabels( const shared_ptr &pg_table, TableCatalogEntry &table) { if (!pg_table->discriminator.empty()) { if (!table.ColumnExists(pg_table->discriminator)) { - throw Exception(ExceptionType::INVALID, "Column " + pg_table->discriminator + - " not found in table " + pg_table->table_name); + throw Exception(ExceptionType::INVALID, + "Column " + pg_table->discriminator + + " not found in table " + pg_table->table_name); } auto &column = table.GetColumn(pg_table->discriminator); if (!(column.GetType() == LogicalType::BIGINT || column.GetType() == LogicalType::INTEGER)) { - throw Exception(ExceptionType::INVALID, "The discriminator column " + - pg_table->discriminator + " of table " + - pg_table->table_name + " should be of type BIGINT or INTEGER"); + throw Exception(ExceptionType::INVALID, + "The discriminator column " + pg_table->discriminator + + " of table " + pg_table->table_name + + " should be of type BIGINT or INTEGER"); } } } @@ -29,8 +31,9 @@ void CreatePropertyGraphFunction::CheckPropertyGraphTableColumns( if (pg_table->all_columns) { for (auto &except_column : pg_table->except_columns) { if (!table.ColumnExists(except_column)) { - throw Exception(ExceptionType::INVALID, "Except column " + except_column + - " not found in table " + pg_table->table_name); + throw Exception(ExceptionType::INVALID, + "Except column " + except_column + + " not found in table " + pg_table->table_name); } } @@ -50,13 +53,13 @@ void CreatePropertyGraphFunction::CheckPropertyGraphTableColumns( for (auto &column : pg_table->column_names) { if (!table.ColumnExists(column)) { throw Exception(ExceptionType::INVALID, "Column " + column + - " not found in table " + pg_table->table_name); + " not found in table " + + pg_table->table_name); } } } -unique_ptr -CreatePropertyGraphFunction::CreatePropertyGraphBind( +unique_ptr CreatePropertyGraphFunction::CreatePropertyGraphBind( ClientContext &context, TableFunctionBindInput &input, vector &return_types, vector &names) { names.emplace_back("Success"); @@ -80,7 +83,9 @@ CreatePropertyGraphFunction::CreatePropertyGraphBind( duckpgq_state->registered_property_graphs.find(info->property_graph_name); if (pg_table != duckpgq_state->registered_property_graphs.end()) { - throw Exception(ExceptionType::INVALID, "Property graph table with name " + info->property_graph_name + " already exists"); + throw Exception(ExceptionType::INVALID, "Property graph table with name " + + info->property_graph_name + + " already exists"); } auto &catalog = Catalog::GetCatalog(context, info->catalog); @@ -107,20 +112,26 @@ CreatePropertyGraphFunction::CreatePropertyGraphBind( if (v_table_names.find(edge_table->source_reference) == v_table_names.end()) { - throw Exception(ExceptionType::INVALID, "Referenced vertex table " + edge_table->source_reference + " does not exist."); + throw Exception(ExceptionType::INVALID, "Referenced vertex table " + + edge_table->source_reference + + " does not exist."); } auto &pk_source_table = catalog.GetEntry( context, info->schema, edge_table->source_reference); for (auto &pk : edge_table->source_pk) { if (!pk_source_table.ColumnExists(pk)) { - throw Exception(ExceptionType::INVALID, "Primary key " + pk + " does not exist in table " + edge_table->source_reference); + throw Exception(ExceptionType::INVALID, + "Primary key " + pk + " does not exist in table " + + edge_table->source_reference); } } if (v_table_names.find(edge_table->source_reference) == v_table_names.end()) { - throw Exception(ExceptionType::INVALID, "Referenced vertex table " + edge_table->source_reference + " does not exist"); + throw Exception(ExceptionType::INVALID, "Referenced vertex table " + + edge_table->source_reference + + " does not exist"); } auto &pk_destination_table = catalog.GetEntry( @@ -128,19 +139,25 @@ CreatePropertyGraphFunction::CreatePropertyGraphBind( for (auto &pk : edge_table->destination_pk) { if (!pk_destination_table.ColumnExists(pk)) { - throw Exception(ExceptionType::INVALID,"Primary key " + pk + " does not exist in table " + edge_table->destination_reference); + throw Exception(ExceptionType::INVALID, + "Primary key " + pk + " does not exist in table " + + edge_table->destination_reference); } } for (auto &fk : edge_table->source_fk) { if (!table.ColumnExists(fk)) { - throw Exception(ExceptionType::INVALID,"Foreign key " + fk + " does not exist in table " + edge_table->table_name); + throw Exception(ExceptionType::INVALID, + "Foreign key " + fk + " does not exist in table " + + edge_table->table_name); } } for (auto &fk : edge_table->destination_fk) { if (!table.ColumnExists(fk)) { - throw Exception(ExceptionType::INVALID,"Foreign key " + fk + " does not exist in table " + edge_table->table_name); + throw Exception(ExceptionType::INVALID, + "Foreign key " + fk + " does not exist in table " + + edge_table->table_name); } } } @@ -160,7 +177,8 @@ void CreatePropertyGraphFunction::CreatePropertyGraphFunc( auto pg_info = bind_data.create_pg_info; auto lookup = context.registered_state.find("duckpgq"); if (lookup == context.registered_state.end()) { - throw Exception(ExceptionType::INVALID,"Registered DuckPGQ state not found"); + throw Exception(ExceptionType::INVALID, + "Registered DuckPGQ state not found"); } auto duckpgq_state = (DuckPGQState *)lookup->second.get(); auto pg_lookup = duckpgq_state->registered_property_graphs.find( @@ -169,7 +187,9 @@ void CreatePropertyGraphFunction::CreatePropertyGraphFunc( duckpgq_state->registered_property_graphs[pg_info->property_graph_name] = pg_info->Copy(); } else { - throw Exception(ExceptionType::INVALID,"A property graph with name " + pg_info->property_graph_name + " already exists."); + throw Exception(ExceptionType::INVALID, "A property graph with name " + + pg_info->property_graph_name + + " already exists."); } } }; // namespace duckdb diff --git a/duckpgq/src/duckpgq/functions/tablefunctions/match.cpp b/duckpgq/src/duckpgq/functions/tablefunctions/match.cpp index f098e330..c167e8e6 100644 --- a/duckpgq/src/duckpgq/functions/tablefunctions/match.cpp +++ b/duckpgq/src/duckpgq/functions/tablefunctions/match.cpp @@ -31,8 +31,10 @@ PGQMatchFunction::FindGraphTable(const string &label, CreatePropertyGraphInfo &pg_table) { const auto graph_table_entry = pg_table.label_map.find(label); if (graph_table_entry == pg_table.label_map.end()) { - throw Exception(ExceptionType::BINDER, "The label " + label + - " is not registered in property graph " + pg_table.property_graph_name); + throw Exception(ExceptionType::BINDER, + "The label " + label + + " is not registered in property graph " + + pg_table.property_graph_name); } return graph_table_entry->second; @@ -535,13 +537,14 @@ unique_ptr PGQMatchFunction::CreatePathFindingFunction( edge_table, previous_vertex_element->variable_binding))); pathfinding_children.push_back(std::move(src_row_id)); pathfinding_children.push_back(std::move(dst_row_id)); - pathfinding_children.push_back( - make_uniq(Value::INTEGER(static_cast(edge_subpath->lower)))); - pathfinding_children.push_back( - make_uniq(Value::INTEGER(static_cast(edge_subpath->upper)))); + pathfinding_children.push_back(make_uniq( + Value::INTEGER(static_cast(edge_subpath->lower)))); + pathfinding_children.push_back(make_uniq( + Value::INTEGER(static_cast(edge_subpath->upper)))); auto shortest_path_function = make_uniq( - edge_subpath->lower > 1 ? "shortestpath_lowerbound": "shortestpath", + edge_subpath->lower > 0 ? "shortestpath_lowerbound" + : "shortestpath", std::move(pathfinding_children)); if (!final_list) { @@ -674,13 +677,13 @@ void PGQMatchFunction::AddPathFinding( std::move(GetCountTable(edge_table, prev_binding))); pathfinding_children.push_back(std::move(src_row_id)); pathfinding_children.push_back(std::move(dst_row_id)); - pathfinding_children.push_back( - make_uniq(Value::INTEGER(static_cast(subpath->lower)))); - pathfinding_children.push_back( - make_uniq(Value::INTEGER(static_cast(subpath->upper)))); + pathfinding_children.push_back(make_uniq( + Value::INTEGER(static_cast(subpath->lower)))); + pathfinding_children.push_back(make_uniq( + Value::INTEGER(static_cast(subpath->upper)))); auto reachability_function = make_uniq( - subpath->lower > 1 ? "iterativelength_lowerbound": "iterativelength", + subpath->lower > 0 ? "iterativelength_lowerbound" : "iterativelength", std::move(pathfinding_children)); auto cte_col_ref = make_uniq("temp", "__x"); @@ -695,7 +698,7 @@ void PGQMatchFunction::AddPathFinding( //! END //! WHERE __x.temp + iterativelength(, (SELECT count(s.id) - //! from src s, a.rowid, b.rowid, lower, upper) + //! from src s, a.rowid, b.rowid, lower, upper) } void PGQMatchFunction::CheckNamedSubpath( diff --git a/duckpgq/src/duckpgq_extension.cpp b/duckpgq/src/duckpgq_extension.cpp index 6637cd9e..37e8fc47 100644 --- a/duckpgq/src/duckpgq_extension.cpp +++ b/duckpgq/src/duckpgq_extension.cpp @@ -86,7 +86,7 @@ ParserExtensionParseResult duckpgq_parse(ParserExtensionInfo *info, : query); if (parser.statements.size() != 1) { throw Exception(ExceptionType::PARSER, - "More than 1 statement detected, please only give one."); + "More than 1 statement detected, please only give one."); } return {make_uniq_base( std::move(parser.statements[0]))}; @@ -181,7 +181,8 @@ duckpgq_handle_statement(SQLStatement *statement, DuckPGQState &duckpgq_state) { // Preferably throw NotImplementedExpection here, but only BinderExceptions // are caught properly on MacOS right now throw Exception(ExceptionType::NOT_IMPLEMENTED, - StatementTypeToString(statement->type) + "has not been implemented yet for DuckPGQ queries"); + StatementTypeToString(statement->type) + + "has not been implemented yet for DuckPGQ queries"); } ParserExtensionPlanResult diff --git a/test/sql/path-finding/complex_matching.test b/test/sql/path-finding/complex_matching.test index e67934e2..411f8479 100644 --- a/test/sql/path-finding/complex_matching.test +++ b/test/sql/path-finding/complex_matching.test @@ -55,6 +55,11 @@ query IIIIIII COLUMNS (p3.id, element_id(o), path_length(o), vertices(o), edges(o), p4.id, p.id) ) tmp; ---- +26388279066641 [0, 0, 13, 42, 29] 2 [0, 13, 29] [0, 42] 14 10995116277782 +26388279066658 [0, 0, 13, 43, 31] 2 [0, 13, 31] [0, 43] 14 10995116277782 +28587302322180 [0, 0, 13, 44, 33] 2 [0, 13, 33] [0, 44] 14 10995116277782 +28587302322204 [0, 0, 13, 45, 36] 2 [0, 13, 36] [0, 45] 14 10995116277782 +35184372088856 [0, 0, 13, 46, 46] 2 [0, 13, 46] [0, 46] 14 10995116277782 28587302322180 [0, 0, 13, 42, 29, 68, 33] 3 [0, 13, 29, 33] [0, 42, 68] 14 10995116277782 28587302322204 [0, 0, 13, 42, 29, 69, 36] 3 [0, 13, 29, 36] [0, 42, 69] 14 10995116277782 28587302322196 [0, 0, 13, 43, 31, 71, 35] 3 [0, 13, 31, 35] [0, 43, 71] 14 10995116277782 @@ -66,6 +71,12 @@ query IIIIIII 30786325577731 [0, 0, 13, 44, 33, 79, 39] 3 [0, 13, 33, 39] [0, 44, 79] 14 10995116277782 32985348833329 [0, 0, 13, 44, 33, 80, 43] 3 [0, 13, 33, 43] [0, 44, 80] 14 10995116277782 35184372088850 [0, 0, 13, 45, 36, 82, 45] 3 [0, 13, 36, 45] [0, 45, 82] 14 10995116277782 +24189255811109 [0, 1, 26, 61, 27] 2 [0, 26, 27] [1, 61] 14 24189255811081 +26388279066658 [0, 1, 26, 62, 31] 2 [0, 26, 31] [1, 62] 14 24189255811081 +26388279066668 [0, 1, 26, 63, 32] 2 [0, 26, 32] [1, 63] 14 24189255811081 +28587302322180 [0, 1, 26, 64, 33] 2 [0, 26, 33] [1, 64] 14 24189255811081 +28587302322196 [0, 1, 26, 65, 35] 2 [0, 26, 35] [1, 65] 14 24189255811081 +35184372088834 [0, 1, 26, 66, 44] 2 [0, 26, 44] [1, 66] 14 24189255811081 28587302322196 [0, 1, 26, 62, 31, 71, 35] 3 [0, 26, 31, 35] [1, 62, 71] 14 24189255811081 30786325577740 [0, 1, 26, 62, 31, 72, 40] 3 [0, 26, 31, 40] [1, 62, 72] 14 24189255811081 35184372088850 [0, 1, 26, 62, 31, 73, 45] 3 [0, 26, 31, 45] [1, 62, 73] 14 24189255811081 @@ -76,7 +87,9 @@ query IIIIIII 28587302322223 [0, 1, 26, 64, 33, 78, 38] 3 [0, 26, 33, 38] [1, 64, 78] 14 24189255811081 30786325577731 [0, 1, 26, 64, 33, 79, 39] 3 [0, 26, 33, 39] [1, 64, 79] 14 24189255811081 32985348833329 [0, 1, 26, 64, 33, 80, 43] 3 [0, 26, 33, 43] [1, 64, 80] 14 24189255811081 -35184372088850 [0, 1, 26, 63, 32, 76, 36, 82, 45] 4 [0, 26, 32, 36, 45] [1, 63, 76, 82] 14 24189255811081 +35184372088850 [0, 1, 26, 64, 33, 77, 36, 82, 45] 4 [0, 26, 33, 36, 45] [1, 64, 77, 82] 14 24189255811081 +28587302322180 [0, 2, 32, 75, 33] 2 [0, 32, 33] [2, 75] 14 26388279066668 +28587302322204 [0, 2, 32, 76, 36] 2 [0, 32, 36] [2, 76] 14 26388279066668 28587302322204 [0, 2, 32, 75, 33, 77, 36] 3 [0, 32, 33, 36] [2, 75, 77] 14 26388279066668 28587302322223 [0, 2, 32, 75, 33, 78, 38] 3 [0, 32, 33, 38] [2, 75, 78] 14 26388279066668 30786325577731 [0, 2, 32, 75, 33, 79, 39] 3 [0, 32, 33, 39] [2, 75, 79] 14 26388279066668 @@ -112,16 +125,16 @@ query III ORDER BY p_id, p2_id limit 10; ---- -14 10995116277782 598 -14 10995116277782 805 -14 10995116277782 1174 -14 10995116277782 1183 -14 10995116277782 1527 -14 10995116277782 1676 -14 10995116277782 1998 -14 10995116277782 798 -14 10995116277782 1031 -14 10995116277782 1986 +14 14 290 +14 14 584 +14 14 783 +14 14 804 +14 14 1621 +14 14 2038 +14 14 2045 +14 14 779 +14 14 1031 +14 14 1763 query IIIII WITH CTE1 AS (SELECT CREATE_CSR_EDGE( @@ -218,6 +231,71 @@ query IIII ) tmp ORDER BY b_id, t_id ---- +Bryn 33 28587302322180 139 +Bryn 33 28587302322180 294 +Bryn 33 28587302322180 458 +Bryn 33 28587302322180 572 +Bryn 33 28587302322180 590 +Bryn 33 28587302322180 788 +Bryn 33 28587302322180 974 +Bryn 33 28587302322180 1184 +Bryn 33 28587302322180 1401 +Bryn 33 28587302322180 1680 +Bryn 33 28587302322180 1984 +Bryn 33 28587302322180 1985 +Bryn 33 28587302322180 1991 +Bryn 33 28587302322180 1992 +Bryn 33 28587302322180 1994 +Bryn 33 28587302322180 2006 +Bryn 33 28587302322180 2017 +Bryn 33 28587302322180 2023 +Bryn 33 28587302322180 2052 +Bryn 33 28587302322180 2056 +Bryn 33 28587302322180 2058 +Bryn 33 28587302322180 2078 +Bryn 33 28587302322180 2777 +Bryn 33 28587302322180 2783 +Bryn 33 28587302322180 2788 +Bryn 33 28587302322180 2796 +Bryn 33 28587302322180 2797 +Bryn 33 28587302322180 2812 +Bryn 33 28587302322180 2827 +Bryn 33 28587302322180 2836 +Bryn 33 28587302322180 2845 +Bryn 33 28587302322180 2859 +Bryn 33 28587302322180 2872 +Bryn 33 28587302322180 2880 +Bryn 33 28587302322180 2929 +Bryn 33 28587302322180 2943 +Bryn 33 28587302322180 2976 +Bryn 33 28587302322180 3011 +Bryn 33 28587302322180 3022 +Bryn 33 28587302322180 3064 +Bryn 33 28587302322180 3087 +Bryn 33 28587302322180 5163 +Bryn 33 28587302322180 5170 +Bryn 33 28587302322180 5193 +Bryn 33 28587302322180 5699 +Bryn 33 28587302322180 6405 +Bryn 33 28587302322180 6993 +Bryn 33 28587302322180 6999 +Bryn 33 28587302322180 7001 +Bryn 33 28587302322180 7010 +Bryn 33 28587302322180 7522 +Bryn 33 28587302322180 7526 +Bryn 33 28587302322180 7564 +Bryn 33 28587302322180 7570 +Bryn 33 28587302322180 9479 +Bryn 33 28587302322180 9496 +Bryn 33 28587302322180 9760 +Bryn 33 28587302322180 9939 +Bryn 33 28587302322180 10080 +Bryn 33 28587302322180 10322 +Bryn 33 28587302322180 10991 +Bryn 33 28587302322180 11408 +Bryn 33 28587302322180 11557 +Bryn 33 28587302322180 11609 +Bryn 33 28587302322180 12273 Bryn 36 28587302322204 6 Bryn 36 28587302322204 588 Bryn 36 28587302322204 1021 @@ -272,6 +350,71 @@ query IIII ) tmp ORDER BY b_id, t_id ---- +Bryn 33 28587302322180 139 +Bryn 33 28587302322180 294 +Bryn 33 28587302322180 458 +Bryn 33 28587302322180 572 +Bryn 33 28587302322180 590 +Bryn 33 28587302322180 788 +Bryn 33 28587302322180 974 +Bryn 33 28587302322180 1184 +Bryn 33 28587302322180 1401 +Bryn 33 28587302322180 1680 +Bryn 33 28587302322180 1984 +Bryn 33 28587302322180 1985 +Bryn 33 28587302322180 1991 +Bryn 33 28587302322180 1992 +Bryn 33 28587302322180 1994 +Bryn 33 28587302322180 2006 +Bryn 33 28587302322180 2017 +Bryn 33 28587302322180 2023 +Bryn 33 28587302322180 2052 +Bryn 33 28587302322180 2056 +Bryn 33 28587302322180 2058 +Bryn 33 28587302322180 2078 +Bryn 33 28587302322180 2777 +Bryn 33 28587302322180 2783 +Bryn 33 28587302322180 2788 +Bryn 33 28587302322180 2796 +Bryn 33 28587302322180 2797 +Bryn 33 28587302322180 2812 +Bryn 33 28587302322180 2827 +Bryn 33 28587302322180 2836 +Bryn 33 28587302322180 2845 +Bryn 33 28587302322180 2859 +Bryn 33 28587302322180 2872 +Bryn 33 28587302322180 2880 +Bryn 33 28587302322180 2929 +Bryn 33 28587302322180 2943 +Bryn 33 28587302322180 2976 +Bryn 33 28587302322180 3011 +Bryn 33 28587302322180 3022 +Bryn 33 28587302322180 3064 +Bryn 33 28587302322180 3087 +Bryn 33 28587302322180 5163 +Bryn 33 28587302322180 5170 +Bryn 33 28587302322180 5193 +Bryn 33 28587302322180 5699 +Bryn 33 28587302322180 6405 +Bryn 33 28587302322180 6993 +Bryn 33 28587302322180 6999 +Bryn 33 28587302322180 7001 +Bryn 33 28587302322180 7010 +Bryn 33 28587302322180 7522 +Bryn 33 28587302322180 7526 +Bryn 33 28587302322180 7564 +Bryn 33 28587302322180 7570 +Bryn 33 28587302322180 9479 +Bryn 33 28587302322180 9496 +Bryn 33 28587302322180 9760 +Bryn 33 28587302322180 9939 +Bryn 33 28587302322180 10080 +Bryn 33 28587302322180 10322 +Bryn 33 28587302322180 10991 +Bryn 33 28587302322180 11408 +Bryn 33 28587302322180 11557 +Bryn 33 28587302322180 11609 +Bryn 33 28587302322180 12273 Bryn 36 28587302322204 6 Bryn 36 28587302322204 588 Bryn 36 28587302322204 1021 @@ -336,35 +479,37 @@ statement error ---- Parser Error: syntax error at or near "{" -query III +query IIII -FROM GRAPH_TABLE (snb MATCH p = (a:Person where a.id = 16)-[k:knows]->{1,3}(b:Person) - COLUMNS (element_id(p), a.id, b.id) + COLUMNS (element_id(p), a.id, b.id, path_length(p)) ) tmp; ---- -[1, 3, 5] 16 2199023255594 -[1, 3, 5, 16, 10] 16 8796093022244 -[1, 3, 5, 17, 12] 16 10995116277761 -[1, 3, 5, 18, 16] 16 13194139533342 -[1, 3, 5, 19, 17] 16 13194139533352 -[1, 3, 5, 16, 10, 32, 18] 16 13194139533355 -[1, 3, 5, 20, 19] 16 15393162788877 -[1, 3, 5, 17, 12, 39, 20] 16 17592186044443 -[1, 3, 5, 21, 21] 16 17592186044461 -[1, 3, 5, 19, 17, 48, 23] 16 19791209299987 -[1, 3, 5, 22, 26] 16 24189255811081 -[1, 3, 5, 22, 26, 61, 27] 16 24189255811109 -[1, 3, 5, 19, 17, 49, 29] 16 26388279066641 -[1, 4, 30] 16 26388279066655 -[1, 3, 5, 23, 31] 16 26388279066658 -[1, 3, 5, 24, 32] 16 26388279066668 -[1, 5, 33] 16 28587302322180 -[1, 3, 5, 26, 35] 16 28587302322196 -[1, 6, 36] 16 28587302322204 -[1, 5, 33, 78, 38] 16 28587302322223 -[1, 5, 33, 79, 39] 16 30786325577731 -[1, 3, 5, 27, 40] 16 30786325577740 -[1, 5, 33, 80, 43] 16 32985348833329 -[1, 3, 5, 22, 26, 66, 44] 16 35184372088834 -[1, 3, 5, 28, 45] 16 35184372088850 -[1, 3, 5, 23, 31, 74, 46] 16 35184372088856 +NULL 16 16 NULL +[1, 3, 5] 16 2199023255594 1 +[1, 3, 5, 16, 10] 16 8796093022244 2 +[1, 3, 5, 17, 12] 16 10995116277761 2 +[1, 3, 5, 18, 16] 16 13194139533342 2 +[1, 3, 5, 19, 17] 16 13194139533352 2 +[1, 3, 5, 16, 10, 32, 18] 16 13194139533355 3 +[1, 3, 5, 20, 19] 16 15393162788877 2 +[1, 3, 5, 17, 12, 39, 20] 16 17592186044443 3 +[1, 3, 5, 21, 21] 16 17592186044461 2 +[1, 3, 5, 19, 17, 48, 23] 16 19791209299987 3 +[1, 3, 5, 22, 26] 16 24189255811081 2 +[1, 3, 5, 22, 26, 61, 27] 16 24189255811109 3 +[1, 3, 5, 19, 17, 49, 29] 16 26388279066641 3 +[1, 4, 30] 16 26388279066655 1 +[1, 3, 5, 23, 31] 16 26388279066658 2 +[1, 3, 5, 24, 32] 16 26388279066668 2 +[1, 5, 33] 16 28587302322180 1 +[1, 3, 5, 26, 35] 16 28587302322196 2 +[1, 6, 36] 16 28587302322204 1 +[1, 5, 33, 78, 38] 16 28587302322223 2 +[1, 5, 33, 79, 39] 16 30786325577731 2 +[1, 3, 5, 27, 40] 16 30786325577740 2 +[1, 5, 33, 80, 43] 16 32985348833329 2 +[1, 3, 5, 22, 26, 66, 44] 16 35184372088834 3 +[1, 6, 36, 82, 45] 16 35184372088850 2 +[1, 3, 5, 23, 31, 74, 46] 16 35184372088856 3 + diff --git a/test/sql/path-finding/shortest_path_bound.test b/test/sql/path-finding/shortest_path_bound.test index 9d32f589..3d57a5c0 100644 --- a/test/sql/path-finding/shortest_path_bound.test +++ b/test/sql/path-finding/shortest_path_bound.test @@ -276,7 +276,7 @@ query III # Description: Test shortest paths in a graph with cycles. # Graph Structure: -# (0) <-> (2) <-> (3) -> (1) +# (0) <-> (2) <-> (3) -> (1) (selfloop) # ↑ | # └----------------------┘ @@ -284,7 +284,7 @@ statement ok CREATE TABLE Point6(id BIGINT); INSERT INTO Point6 VALUES (0), (1), (2), (3); statement ok -CREATE TABLE know6(src BIGINT, dst BIGINT); INSERT INTO know6 VALUES (0, 2), (2, 0), (2, 3), (3, 2), (3, 1), (1, 0); +CREATE TABLE know6(src BIGINT, dst BIGINT); INSERT INTO know6 VALUES (0, 2), (2, 0), (2, 3), (3, 2), (3, 1), (1, 0), (1, 1); statement ok -CREATE PROPERTY GRAPH pg6 @@ -323,3 +323,22 @@ query III 3 3 [3, 3, 2, 2, 3] +query IIII +-FROM GRAPH_TABLE (pg6 + MATCH + p = ANY SHORTEST (a:Point6 where a.id = 0)-[k:know6]->{1,3}(b:Point6 where b.id = 0) + COLUMNS (a.id as id1, b.id as id2, vertices(p), path_length(p)) + ) tmp + order by tmp.id1, tmp.id2; +---- +0 0 [0, 2, 0] 2 + +query IIII +-FROM GRAPH_TABLE (pg6 + MATCH + p = ANY SHORTEST (a:Point6 where a.id = 1)-[k:know6]->{1,3}(b:Point6 where b.id = 1) + COLUMNS (a.id as id1, b.id as id2, vertices(p), path_length(p)) + ) tmp + order by tmp.id1, tmp.id2; +---- +1 1 [1, 1] 1 \ No newline at end of file