From e308c27cde631e0a81667d499c3e7ebd217c31b4 Mon Sep 17 00:00:00 2001 From: dtenwolde Date: Tue, 13 Feb 2024 18:21:57 +0100 Subject: [PATCH] Initial merge with v0.10.0 --- Makefile | 2 +- duckdb | 2 +- duckdb-pgq | 2 +- .../duckpgq/functions/scalar/csr_creation.cpp | 6 +- .../duckpgq/functions/scalar/reachability.cpp | 2 +- .../tablefunctions/create_property_graph.cpp | 56 ++++++++----------- .../functions/tablefunctions/match.cpp | 4 +- duckpgq/src/duckpgq_extension.cpp | 16 +++--- test/sql/altering_table.test | 1 + test/sql/create_pg/create_property_graph.test | 6 +- test/sql/create_pg/drop_property_graph.test | 2 + .../create_pg/optional_edge_table_clause.test | 4 +- test/sql/path-finding/complex_matching.test | 21 +++---- test/sql/path-finding/shortest_path.test | 2 + test/sql/pattern-matching/basic_match.test | 3 + test/sql/scalar/get_csr_w_type.test | 1 + 16 files changed, 67 insertions(+), 63 deletions(-) diff --git a/Makefile b/Makefile index 8531f624..b00964eb 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ EXTENSION_FLAGS=\ -DDUCKDB_EXTENSION_${EXTENSION_NAME}_TEST_PATH="$(PROJ_DIR)test/sql" #### Add more of the DuckDB in-tree extensions here that you need (also feel free to remove them when not needed) -EXTRA_EXTENSIONS_FLAG=-DBUILD_EXTENSIONS="tpch;visualizer" +EXTRA_EXTENSIONS_FLAG=-DBUILD_EXTENSIONS="tpch" BUILD_FLAGS=-DEXTENSION_STATIC_BUILD=1 $(EXTENSION_FLAGS) ${EXTRA_EXTENSIONS_FLAG} $(OSX_BUILD_FLAG) $(TOOLCHAIN_FLAGS) CLIENT_FLAGS:= diff --git a/duckdb b/duckdb index 3c695d7b..20b1486d 160000 --- a/duckdb +++ b/duckdb @@ -1 +1 @@ -Subproject commit 3c695d7ba94d95d9facee48d395f46ed0bd72b46 +Subproject commit 20b1486d1192f9fbd2328d1122b5afe5f1747fce diff --git a/duckdb-pgq b/duckdb-pgq index 41aca595..3e6d77b9 160000 --- a/duckdb-pgq +++ b/duckdb-pgq @@ -1 +1 @@ -Subproject commit 41aca595d155e9b291fb8ffe6abf23689e00ee1d +Subproject commit 3e6d77b92397f0b2ae70424a51c3c8c22c3c6123 diff --git a/duckpgq/src/duckpgq/functions/scalar/csr_creation.cpp b/duckpgq/src/duckpgq/functions/scalar/csr_creation.cpp index 47b9dfe8..14f954ef 100644 --- a/duckpgq/src/duckpgq/functions/scalar/csr_creation.cpp +++ b/duckpgq/src/duckpgq/functions/scalar/csr_creation.cpp @@ -36,7 +36,7 @@ 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("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 +55,7 @@ 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("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 +82,7 @@ static void CsrInitializeWeight(DuckPGQState &context, int32_t id, throw NotImplementedException("Unrecognized weight type detected."); } } catch (std::bad_alloc const &) { - throw Exception("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/reachability.cpp b/duckpgq/src/duckpgq/functions/scalar/reachability.cpp index f460c57e..5c6443fb 100644 --- a/duckpgq/src/duckpgq/functions/scalar/reachability.cpp +++ b/duckpgq/src/duckpgq/functions/scalar/reachability.cpp @@ -245,7 +245,7 @@ static void ReachabilityFunction(DataChunk &args, ExpressionState &state, break; } default: - throw Exception("Unknown 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/tablefunctions/create_property_graph.cpp b/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp index f0587e41..c8ce874e 100644 --- a/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp +++ b/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp @@ -7,15 +7,15 @@ void CreatePropertyGraphFunction::CheckPropertyGraphTableLabels( const shared_ptr &pg_table, TableCatalogEntry &table) { if (!pg_table->discriminator.empty()) { if (!table.ColumnExists(pg_table->discriminator)) { - throw BinderException("Column %s not found in table %s", - pg_table->discriminator, 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 BinderException("The discriminator column %s for table %s should " - "be of type BIGINT or INTEGER", - pg_table->discriminator, pg_table->table_name); + 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 +29,8 @@ void CreatePropertyGraphFunction::CheckPropertyGraphTableColumns( if (pg_table->all_columns) { for (auto &except_column : pg_table->except_columns) { if (!table.ColumnExists(except_column)) { - throw BinderException("Except column %s not found in table %s", - except_column, pg_table->table_name); + throw Exception(ExceptionType::INVALID, "Except column " + except_column + + " not found in table " + pg_table->table_name); } } @@ -49,13 +49,13 @@ void CreatePropertyGraphFunction::CheckPropertyGraphTableColumns( for (auto &column : pg_table->column_names) { if (!table.ColumnExists(column)) { - throw BinderException("Column %s not found in table %s", column, - pg_table->table_name); + throw Exception(ExceptionType::INVALID, "Column " + column + + " not found in table " + pg_table->table_name); } } } -duckdb::unique_ptr +unique_ptr CreatePropertyGraphFunction::CreatePropertyGraphBind( ClientContext &context, TableFunctionBindInput &input, vector &return_types, vector &names) { @@ -63,10 +63,11 @@ CreatePropertyGraphFunction::CreatePropertyGraphBind( return_types.emplace_back(LogicalType::BOOLEAN); auto lookup = context.registered_state.find("duckpgq"); if (lookup == context.registered_state.end()) { - throw BinderException("Registered DuckPGQ state not found"); + throw Exception(ExceptionType::INVALID, + "Registered DuckPGQ state not found"); } - auto duckpgq_state = (DuckPGQState *)lookup->second.get(); - auto duckpgq_parse_data = + const auto duckpgq_state = (DuckPGQState *)lookup->second.get(); + const auto duckpgq_parse_data = dynamic_cast(duckpgq_state->parse_data.get()); if (!duckpgq_parse_data) { @@ -79,12 +80,10 @@ CreatePropertyGraphFunction::CreatePropertyGraphBind( duckpgq_state->registered_property_graphs.find(info->property_graph_name); if (pg_table != duckpgq_state->registered_property_graphs.end()) { - throw BinderException("Property graph table with name %s already exists", - info->property_graph_name); + throw Exception(ExceptionType::INVALID, "Property graph table with name " + info->property_graph_name + " already exists"); } auto &catalog = Catalog::GetCatalog(context, info->catalog); - case_insensitive_set_t v_table_names; for (auto &vertex_table : info->vertex_tables) { auto &table = catalog.GetEntry(context, info->schema, @@ -108,23 +107,20 @@ CreatePropertyGraphFunction::CreatePropertyGraphBind( if (v_table_names.find(edge_table->source_reference) == v_table_names.end()) { - throw BinderException("Referenced vertex table %s does not exist.", - edge_table->source_reference); + 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 BinderException("Primary key %s does not exist in table %s", pk, - 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 BinderException("Referenced vertex table %s does not exist.", - edge_table->source_reference); + throw Exception(ExceptionType::INVALID, "Referenced vertex table " + edge_table->source_reference + " does not exist"); } auto &pk_destination_table = catalog.GetEntry( @@ -132,29 +128,26 @@ CreatePropertyGraphFunction::CreatePropertyGraphBind( for (auto &pk : edge_table->destination_pk) { if (!pk_destination_table.ColumnExists(pk)) { - throw BinderException("Primary key %s does not exist in table %s", pk, - 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 BinderException("Foreign key %s does not exist in table %s", fk, - 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 BinderException("Foreign key %s does not exist in table %s", fk, - edge_table->table_name); + throw Exception(ExceptionType::INVALID,"Foreign key " + fk + " does not exist in table " + edge_table->table_name); } } } return make_uniq(info); } -duckdb::unique_ptr +unique_ptr CreatePropertyGraphFunction::CreatePropertyGraphInit( ClientContext &context, TableFunctionInitInput &input) { return make_uniq(); @@ -167,7 +160,7 @@ 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 BinderException("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( @@ -176,8 +169,7 @@ void CreatePropertyGraphFunction::CreatePropertyGraphFunc( duckpgq_state->registered_property_graphs[pg_info->property_graph_name] = pg_info->Copy(); } else { - throw BinderException("A property graph with name %s already exists.", - pg_info->property_graph_name); + 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 4c7a4fdb..74059c53 100644 --- a/duckpgq/src/duckpgq/functions/tablefunctions/match.cpp +++ b/duckpgq/src/duckpgq/functions/tablefunctions/match.cpp @@ -31,8 +31,8 @@ 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 BinderException("The label %s is not registered in property graph %s", - label, 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; diff --git a/duckpgq/src/duckpgq_extension.cpp b/duckpgq/src/duckpgq_extension.cpp index ebf4da15..6637cd9e 100644 --- a/duckpgq/src/duckpgq_extension.cpp +++ b/duckpgq/src/duckpgq_extension.cpp @@ -85,7 +85,7 @@ ParserExtensionParseResult duckpgq_parse(ParserExtensionInfo *info, parser.ParseQuery((query[0] == '-') ? query.substr(1, query.length()) : query); if (parser.statements.size() != 1) { - throw ParserException( + throw Exception(ExceptionType::PARSER, "More than 1 statement detected, please only give one."); } return {make_uniq_base( @@ -97,7 +97,7 @@ BoundStatement duckpgq_bind(ClientContext &context, Binder &binder, SQLStatement &statement) { auto lookup = context.registered_state.find("duckpgq"); if (lookup == context.registered_state.end()) { - throw BinderException("Registered state not found"); + throw Exception(ExceptionType::BINDER, "Registered state not found"); } auto duckpgq_state = (DuckPGQState *)lookup->second.get(); @@ -107,7 +107,7 @@ BoundStatement duckpgq_bind(ClientContext &context, Binder &binder, if (duckpgq_parse_data) { return duckpgq_binder->Bind(*(duckpgq_parse_data->statement)); } - throw BinderException("Unable to find DuckPGQ Parse Data"); + throw Exception(ExceptionType::BINDER, "Unable to find DuckPGQ Parse Data"); } void duckpgq_find_match_function(TableRef *table_ref, @@ -135,7 +135,7 @@ duckpgq_handle_statement(SQLStatement *statement, DuckPGQState &duckpgq_state) { const auto select_node = dynamic_cast(select_statement->node.get()); duckpgq_find_match_function(select_node->from_table.get(), duckpgq_state); - throw Exception("use duckpgq_bind instead"); + throw Exception(ExceptionType::BINDER, "use duckpgq_bind instead"); } if (statement->type == StatementType::CREATE_STATEMENT) { const auto &create_statement = statement->Cast(); @@ -170,7 +170,7 @@ duckpgq_handle_statement(SQLStatement *statement, DuckPGQState &duckpgq_state) { const auto select_node = dynamic_cast(copy_statement.select_statement.get()); duckpgq_find_match_function(select_node->from_table.get(), duckpgq_state); - throw Exception("use duckpgq_bind instead"); + throw Exception(ExceptionType::BINDER, "use duckpgq_bind instead"); } if (statement->type == StatementType::INSERT_STATEMENT) { const auto &insert_statement = statement->Cast(); @@ -180,8 +180,8 @@ duckpgq_handle_statement(SQLStatement *statement, DuckPGQState &duckpgq_state) { // Preferably throw NotImplementedExpection here, but only BinderExceptions // are caught properly on MacOS right now - throw BinderException("%s has not been implemented yet for DuckPGQ queries", - StatementTypeToString(statement->type)); + throw Exception(ExceptionType::NOT_IMPLEMENTED, + StatementTypeToString(statement->type) + "has not been implemented yet for DuckPGQ queries"); } ParserExtensionPlanResult @@ -201,7 +201,7 @@ duckpgq_plan(ParserExtensionInfo *, ClientContext &context, dynamic_cast(duckpgq_state->parse_data.get()); if (!duckpgq_parse_data) { - throw BinderException("No DuckPGQ parse data found"); + throw Exception(ExceptionType::BINDER, "No DuckPGQ parse data found"); } auto statement = duckpgq_parse_data->statement.get(); diff --git a/test/sql/altering_table.test b/test/sql/altering_table.test index 9d4bf747..213cc2c8 100644 --- a/test/sql/altering_table.test +++ b/test/sql/altering_table.test @@ -64,3 +64,4 @@ statement error WHERE a.name = 'Daniel' COLUMNS (a.jd) ) study; +---- diff --git a/test/sql/create_pg/create_property_graph.test b/test/sql/create_pg/create_property_graph.test index cdf09fc6..4e13411e 100644 --- a/test/sql/create_pg/create_property_graph.test +++ b/test/sql/create_pg/create_property_graph.test @@ -47,7 +47,7 @@ EDGE TABLES ( PROPERTIES ( createDate ) LABEL Knows ) ---- -Binder Error: Property graph table with name pg already exists +Invalid Error: Property graph table with name pg already exists # Alias for the vertex table statement ok @@ -130,7 +130,7 @@ EDGE TABLES ( PROPERTIES ( createDate ) LABEL Knows ) ---- -Binder Error: Referenced vertex table Student does not exist. +Invalid Error: Referenced vertex table Student does not exist. # Should fail since the edge table references vertex tables that do not exist @@ -145,4 +145,4 @@ EDGE TABLES ( PROPERTIES ( createDate ) LABEL Knows ); ---- -Binder Error: Referenced vertex table Student does not exist. \ No newline at end of file +Invalid Error: Referenced vertex table Student does not exist. diff --git a/test/sql/create_pg/drop_property_graph.test b/test/sql/create_pg/drop_property_graph.test index ff9917b0..8123ad01 100644 --- a/test/sql/create_pg/drop_property_graph.test +++ b/test/sql/create_pg/drop_property_graph.test @@ -65,6 +65,8 @@ FROM GRAPH_TABLE (pg (a:Person) COLUMNS (a.id) ) study; +---- +Binder Error: Property graph pg does not exist statement ok -CREATE PROPERTY GRAPH pg diff --git a/test/sql/create_pg/optional_edge_table_clause.test b/test/sql/create_pg/optional_edge_table_clause.test index 8c04f13f..feb9cf98 100644 --- a/test/sql/create_pg/optional_edge_table_clause.test +++ b/test/sql/create_pg/optional_edge_table_clause.test @@ -20,4 +20,6 @@ statement error -FROM GRAPH_TABLE (snb MATCH (p:Person)-[k:Knows]->(p2:Person) COLUMNS (*) - ) tmp \ No newline at end of file + ) tmp +---- +Binder Error: The label knows is not registered in property graph snb diff --git a/test/sql/path-finding/complex_matching.test b/test/sql/path-finding/complex_matching.test index 9798916b..4f406385 100644 --- a/test/sql/path-finding/complex_matching.test +++ b/test/sql/path-finding/complex_matching.test @@ -109,18 +109,19 @@ query III MATCH o = ANY SHORTEST (p:Person)-[w:knows]-> {1,3}(p2:Person)-[i:hasInterest]->(t:Tag) COLUMNS (p.id as p_id, p2.id as p2_id, t.id) ) tmp + ORDER BY p_id, p2_id limit 10; ---- -14 32985348833329 3 -14 32985348833329 139 -14 30786325577731 196 -14 28587302322196 280 -14 28587302322180 294 -14 24189255811081 295 -14 28587302322196 448 -14 32985348833329 470 -14 28587302322196 540 -14 24189255811109 543 +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 query IIIII WITH CTE1 AS (SELECT CREATE_CSR_EDGE( diff --git a/test/sql/path-finding/shortest_path.test b/test/sql/path-finding/shortest_path.test index a82e8ec1..2491591c 100644 --- a/test/sql/path-finding/shortest_path.test +++ b/test/sql/path-finding/shortest_path.test @@ -87,6 +87,8 @@ statement error WHERE a.name = 'Daniel' COLUMNS (p, a.name as name, b.name as b_name) ) study; +---- +Binder Error: Referenced column "p" not found in FROM clause! query III diff --git a/test/sql/pattern-matching/basic_match.test b/test/sql/pattern-matching/basic_match.test index d9b6601e..5e47958a 100644 --- a/test/sql/pattern-matching/basic_match.test +++ b/test/sql/pattern-matching/basic_match.test @@ -198,6 +198,7 @@ FROM GRAPH_TABLE (pg (:Person)-[k:Knows]->(b:Person) COLUMNS (a.name as a_name, b.name as b_name) ) study; +---- statement error -SELECT study.a_name, study.b_name, study.c_name @@ -206,6 +207,7 @@ FROM GRAPH_TABLE (pg (a)-[k:Knows]->(b:Person) COLUMNS (a.ncame as a_name, b.name as b_name) ) study; +---- statement error -SELECT study.a_name, study.b_name, study.c_name @@ -214,6 +216,7 @@ FROM GRAPH_TABLE (pg ()-[k:Knows]->(b:Person) COLUMNS (a.name as a_name, b.name as b_name) ) study; +---- query II diff --git a/test/sql/scalar/get_csr_w_type.test b/test/sql/scalar/get_csr_w_type.test index 7fbc514d..2c2b7590 100644 --- a/test/sql/scalar/get_csr_w_type.test +++ b/test/sql/scalar/get_csr_w_type.test @@ -146,4 +146,5 @@ SELECT csr_get_w_type(2); statement error SELECT csr_get_w_type(3); +----