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

source keyword no longer leads to syntax error #99

Merged
4 changes: 2 additions & 2 deletions duckpgq/src/duckpgq_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 Exception(ExceptionType::BINDER, "Registered state not found");
throw;
}

auto duckpgq_state = (DuckPGQState *)lookup->second.get();
Expand All @@ -107,7 +107,7 @@ BoundStatement duckpgq_bind(ClientContext &context, Binder &binder,
if (duckpgq_parse_data) {
return duckpgq_binder->Bind(*(duckpgq_parse_data->statement));
}
throw Exception(ExceptionType::BINDER, "Unable to find DuckPGQ Parse Data");
throw;
}

void duckpgq_find_match_function(TableRef *table_ref,
Expand Down
16 changes: 16 additions & 0 deletions test/sql/duckdb_columns.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# name: test/sql/sqlpgq/snb.test
# group: [duckpgq]

require duckpgq

statement ok
from duckdb_columns;

statement ok
from duckdb_constraints();

statement ok
select * from information_schema.columns;

statement ok
select * from information_schema.tables;
53 changes: 53 additions & 0 deletions test/sql/non_existing_table.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# https://github.com/cwida/duckpgq-extension/issues/95
# name: test/sql/sqlpgq/non_existing_table.test
# group: [sqlpgq]

require duckpgq

# https://github.com/cwida/duckpgq-extension/issues/96
statement error
select * from table_that_does_not_exist;
----
Catalog Error: Table with name table_that_does_not_exist does not exist!

statement ok
CREATE TABLE test (a INTEGER);

statement error
SELECT b from test;
----
Binder Error: Referenced column "b" not found in FROM clause!

statement ok
import database 'duckdb-pgq/data/SNB0.003';

statement ok
-CREATE PROPERTY GRAPH snb
VERTEX TABLES (
Person,
Organisation IN typemask(company, university)
)
EDGE TABLES (
Person_knows_person SOURCE KEY (Person1Id) REFERENCES Person (id)
DESTINATION KEY (Person2Id) REFERENCES Person (id)
LABEL Knows,
person_workAt_Organisation SOURCE KEY (PersonId) REFERENCES Person (id)
DESTINATION KEY (OrganisationId) REFERENCES Organisation (id)
LABEL workAt_Organisation
);

statement error
-FROM GRAPH_TABLE (snb
MATCH (a:Kind)
COLUMNS (*)
);
----
Binder Error: The label kind is not registered in property graph snb

statement error
-FROM GRAPH_TABLE (abc
MATCH (a:Kind)
COLUMNS (*)
);
----
Binder Error: Property graph abc does not exist
65 changes: 65 additions & 0 deletions test/sql/source_keyword.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# name: test/sql/sqlpgq/snb.test
# group: [duckpgq]

require duckpgq

#statement ok
#select 1 source;

statement ok
FROM duckdb_constraints()

statement ok
SELECT
*,
regexp_extract(constraint_text, 'FOREIGN KEY \\(([a-zA-Z_0-9]+)\\) REFERENCES ([a-zA-Z_0-9]+)\\(([a-zA-Z_0-9]+)\\)', ['source', 'target', 'target_column']) AS name_extract
FROM duckdb_constraints()
WHERE constraint_type = 'FOREIGN KEY'

statement ok
SELECT
*,
name_extract['source'] AS source,
name_extract['target'] AS target,
name_extract['target_column'] AS target_column
FROM (
SELECT
*,
regexp_extract(constraint_text, 'FOREIGN KEY \\(([a-zA-Z_0-9]+)\\) REFERENCES ([a-zA-Z_0-9]+)\\(([a-zA-Z_0-9]+)\\)', ['source', 'target', 'target_column']) AS name_extract
FROM duckdb_constraints()
WHERE constraint_type = 'FOREIGN KEY'
);


statement ok
SELECT
f.database_name AS constraint_catalog,
f.schema_name AS constraint_schema,
CONCAT(f.source, '_', f.target, '_', f.target_column, '_fkey') AS constraint_name,
current_database() AS unique_constraint_catalog,
c.schema_name AS unique_constraint_schema,
CONCAT(c.table_name, '_', f.target_column, '_',
CASE WHEN c.constraint_type = 'UNIQUE' THEN 'key' ELSE 'pkey' END) AS unique_constraint_name,
'NONE' AS match_option,
'NO ACTION' AS update_rule,
'NO ACTION' AS delete_rule
FROM duckdb_constraints() c
JOIN (
SELECT
*,
name_extract['source'] AS source,
name_extract['target'] AS target,
name_extract['target_column'] AS target_column
FROM (
SELECT
*,
regexp_extract(constraint_text, 'FOREIGN KEY \\(([a-zA-Z_0-9]+)\\) REFERENCES ([a-zA-Z_0-9]+)\\(([a-zA-Z_0-9]+)\\)', ['source', 'target', 'target_column']) AS name_extract
FROM duckdb_constraints()
WHERE constraint_type = 'FOREIGN KEY'
)
) f ON name_extract['target'] = c.table_name
AND (c.constraint_type = 'UNIQUE' OR c.constraint_type = 'PRIMARY KEY');


statement ok
FROM information_schema.tables;
Loading