forked from risingwavelabs/risingwave
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(catalog): support DBeaver constraints view (risingwavelabs#15227)
- Loading branch information
Showing
14 changed files
with
578 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
statement ok | ||
create table t(a int, b int, c varchar, primary key(a,b)); | ||
|
||
query TTTT | ||
select conname, contype, conkey from pg_constraint where conname='t_pkey'; | ||
---- | ||
t_pkey p {1,2} | ||
|
||
statement ok | ||
drop table t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/frontend/planner_test/tests/testdata/input/dbeaver.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
- sql: | | ||
SELECT DISTINCT dep.deptype, dep.classid, dep.objid, cl.relkind, attr.attname,pg_get_expr(ad.adbin, ad.adrelid) adefval, | ||
CASE WHEN cl.relkind IS NOT NULL THEN cl.relkind::text || COALESCE(dep.objsubid::text, '')::text | ||
WHEN tg.oid IS NOT NULL THEN 'T'::text | ||
WHEN ty.oid IS NOT NULL THEN 'y'::text | ||
WHEN ns.oid IS NOT NULL THEN 'n'::text | ||
WHEN pr.oid IS NOT NULL THEN 'p'::text | ||
WHEN la.oid IS NOT NULL THEN 'l'::text | ||
WHEN rw.oid IS NOT NULL THEN 'R'::text | ||
WHEN co.oid IS NOT NULL THEN 'C'::text || contype::text | ||
WHEN ad.oid IS NOT NULL THEN 'A'::text | ||
ELSE '' | ||
END AS type, | ||
COALESCE(coc.relname, clrw.relname, tgr.relname) AS ownertable, | ||
CASE WHEN cl.relname IS NOT NULL AND att.attname IS NOT NULL THEN cl.relname || '.' || att.attname | ||
ELSE COALESCE(cl.relname, co.conname, pr.proname, tg.tgname, ty.typname, la.lanname, rw.rulename, ns.nspname) | ||
END AS refname, | ||
COALESCE(nsc.nspname, nso.nspname, nsp.nspname, nst.nspname, nsrw.nspname, tgrn.nspname) AS nspname | ||
FROM pg_depend dep | ||
LEFT JOIN pg_class cl ON dep.objid=cl.oid | ||
LEFT JOIN pg_attribute att ON dep.objid=att.attrelid AND dep.objsubid=att.attnum | ||
LEFT JOIN pg_namespace nsc ON cl.relnamespace=nsc.oid | ||
LEFT JOIN pg_proc pr ON dep.objid=pr.oid | ||
LEFT JOIN pg_namespace nsp ON pr.pronamespace=nsp.oid | ||
LEFT JOIN pg_trigger tg ON dep.objid=tg.oid | ||
LEFT JOIN pg_class tgr ON tg.tgrelid=tgr.oid | ||
LEFT JOIN pg_namespace tgrn ON tgr.relnamespace=tgrn.oid | ||
LEFT JOIN pg_type ty ON dep.objid=ty.oid | ||
LEFT JOIN pg_namespace nst ON ty.typnamespace=nst.oid | ||
LEFT JOIN pg_constraint co ON dep.objid=co.oid | ||
LEFT JOIN pg_class coc ON co.conrelid=coc.oid | ||
LEFT JOIN pg_namespace nso ON co.connamespace=nso.oid | ||
LEFT JOIN pg_rewrite rw ON dep.objid=rw.oid | ||
LEFT JOIN pg_class clrw ON clrw.oid=rw.ev_class | ||
LEFT JOIN pg_namespace nsrw ON clrw.relnamespace=nsrw.oid | ||
LEFT JOIN pg_language la ON dep.objid=la.oid | ||
LEFT JOIN pg_namespace ns ON dep.objid=ns.oid | ||
LEFT JOIN pg_attrdef ad ON ad.oid=dep.objid | ||
LEFT JOIN pg_attribute attr ON attr.attrelid=ad.adrelid and attr.attnum=ad.adnum | ||
WHERE dep.refobjid=$1 | ||
ORDER BY type | ||
expected_outputs: | ||
- batch_plan |
171 changes: 171 additions & 0 deletions
171
src/frontend/planner_test/tests/testdata/output/dbeaver.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/frontend/src/catalog/system_catalog/pg_catalog/pg_language.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2024 RisingWave Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use risingwave_common::types::Fields; | ||
use risingwave_frontend_macro::system_catalog; | ||
|
||
/// The catalog `pg_language` registers languages in which you can write functions or stored procedures. | ||
/// Ref: [`https://www.postgresql.org/docs/current/catalog-pg-language.html`] | ||
/// This is introduced only for pg compatibility and is not used in our system. | ||
#[system_catalog(view, "pg_catalog.pg_language")] | ||
#[derive(Fields)] | ||
struct PgLanguage { | ||
#[primary_key] | ||
oid: i32, | ||
lanname: String, | ||
lanowner: i32, | ||
lanispl: bool, | ||
lanpltrusted: bool, | ||
lanplcallfoid: i32, | ||
laninline: i32, | ||
lanvalidator: i32, | ||
lanacl: Vec<String>, | ||
} |
33 changes: 33 additions & 0 deletions
33
src/frontend/src/catalog/system_catalog/pg_catalog/pg_rewrite.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2024 RisingWave Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use risingwave_common::types::Fields; | ||
use risingwave_frontend_macro::system_catalog; | ||
|
||
/// The catalog `pg_rewrite` stores rewrite rules for tables and views. | ||
/// Ref: [`https://www.postgresql.org/docs/current/catalog-pg-rewrite.html`] | ||
/// This is introduced only for pg compatibility and is not used in our system. | ||
#[system_catalog(view, "pg_catalog.pg_rewrite")] | ||
#[derive(Fields)] | ||
struct PgRewrite { | ||
#[primary_key] | ||
oid: i32, | ||
rulename: String, | ||
ev_class: i32, | ||
ev_type: String, | ||
ev_enabled: String, | ||
is_instead: bool, | ||
ev_qual: String, | ||
ev_action: String, | ||
} |
44 changes: 44 additions & 0 deletions
44
src/frontend/src/catalog/system_catalog/pg_catalog/pg_trigger.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2024 RisingWave Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use risingwave_common::types::Fields; | ||
use risingwave_frontend_macro::system_catalog; | ||
|
||
/// The catalog `pg_trigger` stores triggers on tables and views. | ||
/// Ref: [`https://www.postgresql.org/docs/current/catalog-pg-trigger.html`] | ||
/// This is introduced only for pg compatibility and is not used in our system. | ||
#[system_catalog(view, "pg_catalog.pg_trigger")] | ||
#[derive(Fields)] | ||
struct PgTrigger { | ||
#[primary_key] | ||
oid: i32, | ||
tgrelid: i32, | ||
tgparentid: i32, | ||
tgname: String, | ||
tgfoid: i32, | ||
tgtype: i16, | ||
tgenabled: String, | ||
tgisinternal: bool, | ||
tgconstrrelid: i32, | ||
tgconstrindid: i32, | ||
tgconstraint: i32, | ||
tgdeferrable: bool, | ||
tginitdeferred: bool, | ||
tgnargs: i16, | ||
tgattr: Vec<i16>, | ||
tgargs: Vec<u8>, | ||
tgqual: Option<String>, | ||
tgoldtable: Option<String>, | ||
tgnewtable: Option<String>, | ||
} |
Oops, something went wrong.