From 23ab4ae1c989fe0dea919d4fee043993e97f6223 Mon Sep 17 00:00:00 2001 From: msepga <111702535+msepga@users.noreply.github.com> Date: Tue, 26 Nov 2024 18:41:02 -0500 Subject: [PATCH] Upgrade to Postgres 17 and libpg_query 6.0.0 (#47) * Upgrade to libpg_query 17 * Update tests * Update crate and CHANGELOG --- CHANGELOG.md | 16 ++++++++++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- libpg_query | 2 +- src/node_enum.rs | 34 +++++++++++++++++++++++++++++++++- src/node_mut.rs | 34 +++++++++++++++++++++++++++++++++- src/node_ref.rs | 34 +++++++++++++++++++++++++++++++++- tests/data/plpgsql_query.json | 4 ++-- tests/data/plpgsql_simple.json | 6 +++--- tests/fingerprint_tests.rs | 2 +- tests/parse_tests.rs | 7 ++++--- 11 files changed, 128 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cd2caa..d899286 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # Changelog +## 6.0.0 2024-11-26 + +* Upgrade to libpg_query 17-6.0.0 + - Updates to the Postgres 17 parser + - Deparser improvements: + - Add support for deparsing `JSON_TABLE`, `JSON_QUERY`, `JSON_EXISTS`, `JSON_VALUE` + - Add support for deparsing `JSON`, `JSON_SCALAR`, `JSON_SERIALIZE` + - Add support for deparsing `COPY ... FORCE_NULL(*)` + - Add support for deparsing `ALTER COLUMN ... SET EXPRESSION AS` + - Add support for deparsing `SET STATISTICS DEFAULT` + - Add support for deparsing `SET ACCESS METHOD DEFAULT` + - Add support for deparsing `... AT LOCAL` + - Add support for deparsing `merge_action()` + - Add support for deparsing `MERGE ... RETURNING` + - Add support for deparsing `NOT MATCHED [ BY TARGET ]` + ## 5.1.1 2024-10-30 * Make `ParseResult` struct public and implement `Debug` diff --git a/Cargo.lock b/Cargo.lock index 9865652..9efd998 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -390,7 +390,7 @@ dependencies = [ [[package]] name = "pg_query" -version = "5.1.1" +version = "6.0.0" dependencies = [ "bindgen", "cc", diff --git a/Cargo.toml b/Cargo.toml index 7d1e606..ab8cdcc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pg_query" description = "PostgreSQL parser that uses the actual PostgreSQL server source to parse SQL queries and return the internal PostgreSQL parse tree." -version = "5.1.1" +version = "6.0.0" edition = "2021" documentation = "https://docs.rs/pg_query/" build = "build.rs" diff --git a/libpg_query b/libpg_query index 1ec3894..e1a98c3 160000 --- a/libpg_query +++ b/libpg_query @@ -1 +1 @@ -Subproject commit 1ec38940e5c6f09a4c1d17a46d839a881c4f2db7 +Subproject commit e1a98c31d90981cdfdba3c734a60e5abf9c522c2 diff --git a/src/node_enum.rs b/src/node_enum.rs index 665308c..4b4b371 100644 --- a/src/node_enum.rs +++ b/src/node_enum.rs @@ -1163,6 +1163,22 @@ impl NodeEnum { NodeEnum::JsonObjectAgg(n) => NodeRef::JsonObjectAgg(n), NodeEnum::JsonArrayAgg(n) => NodeRef::JsonArrayAgg(n), NodeEnum::RtepermissionInfo(n) => NodeRef::RtepermissionInfo(n), + NodeEnum::WindowFuncRunCondition(n) => NodeRef::WindowFuncRunCondition(n), + NodeEnum::MergeSupportFunc(n) => NodeRef::MergeSupportFunc(n), + NodeEnum::JsonBehavior(n) => NodeRef::JsonBehavior(n), + NodeEnum::JsonExpr(n) => NodeRef::JsonExpr(n), + NodeEnum::JsonTablePath(n) => NodeRef::JsonTablePath(n), + NodeEnum::JsonTablePathScan(n) => NodeRef::JsonTablePathScan(n), + NodeEnum::JsonTableSiblingJoin(n) => NodeRef::JsonTableSiblingJoin(n), + NodeEnum::SinglePartitionSpec(n) => NodeRef::SinglePartitionSpec(n), + NodeEnum::JsonArgument(n) => NodeRef::JsonArgument(n), + NodeEnum::JsonFuncExpr(n) => NodeRef::JsonFuncExpr(n), + NodeEnum::JsonTablePathSpec(n) => NodeRef::JsonTablePathSpec(n), + NodeEnum::JsonTable(n) => NodeRef::JsonTable(n), + NodeEnum::JsonTableColumn(n) => NodeRef::JsonTableColumn(n), + NodeEnum::JsonParseExpr(n) => NodeRef::JsonParseExpr(n), + NodeEnum::JsonScalarExpr(n) => NodeRef::JsonScalarExpr(n), + NodeEnum::JsonSerializeExpr(n) => NodeRef::JsonSerializeExpr(n), } } @@ -1332,7 +1348,7 @@ impl NodeEnum { NodeEnum::CreateStatsStmt(n) => NodeMut::CreateStatsStmt(n as *mut _), NodeEnum::AlterCollationStmt(n) => NodeMut::AlterCollationStmt(n as *mut _), NodeEnum::CallStmt(n) => NodeMut::CallStmt(&mut **n as *mut _), - NodeEnum::AlterStatsStmt(n) => NodeMut::AlterStatsStmt(n as *mut _), + NodeEnum::AlterStatsStmt(n) => NodeMut::AlterStatsStmt(&mut **n as *mut _), NodeEnum::AExpr(n) => NodeMut::AExpr(&mut **n as *mut _), NodeEnum::ColumnRef(n) => NodeMut::ColumnRef(n as *mut _), NodeEnum::ParamRef(n) => NodeMut::ParamRef(n as *mut _), @@ -1420,6 +1436,22 @@ impl NodeEnum { NodeEnum::JsonObjectAgg(n) => NodeMut::JsonObjectAgg(&mut **n as *mut _), NodeEnum::JsonArrayAgg(n) => NodeMut::JsonArrayAgg(&mut **n as *mut _), NodeEnum::RtepermissionInfo(n) => NodeMut::RtepermissionInfo(&mut *n as *mut _), + NodeEnum::WindowFuncRunCondition(n) => NodeMut::WindowFuncRunCondition(&mut **n as *mut _), + NodeEnum::MergeSupportFunc(n) => NodeMut::MergeSupportFunc(&mut **n as *mut _), + NodeEnum::JsonBehavior(n) => NodeMut::JsonBehavior(&mut **n as *mut _), + NodeEnum::JsonExpr(n) => NodeMut::JsonExpr(&mut **n as *mut _), + NodeEnum::JsonTablePath(n) => NodeMut::JsonTablePath(&mut *n as *mut _), + NodeEnum::JsonTablePathScan(n) => NodeMut::JsonTablePathScan(&mut **n as *mut _), + NodeEnum::JsonTableSiblingJoin(n) => NodeMut::JsonTableSiblingJoin(&mut **n as *mut _), + NodeEnum::SinglePartitionSpec(n) => NodeMut::SinglePartitionSpec(&mut *n as *mut _), + NodeEnum::JsonArgument(n) => NodeMut::JsonArgument(&mut **n as *mut _), + NodeEnum::JsonFuncExpr(n) => NodeMut::JsonFuncExpr(&mut **n as *mut _), + NodeEnum::JsonTablePathSpec(n) => NodeMut::JsonTablePathSpec(&mut **n as *mut _), + NodeEnum::JsonTable(n) => NodeMut::JsonTable(&mut **n as *mut _), + NodeEnum::JsonTableColumn(n) => NodeMut::JsonTableColumn(&mut **n as *mut _), + NodeEnum::JsonParseExpr(n) => NodeMut::JsonParseExpr(&mut **n as *mut _), + NodeEnum::JsonScalarExpr(n) => NodeMut::JsonScalarExpr(&mut **n as *mut _), + NodeEnum::JsonSerializeExpr(n) => NodeMut::JsonSerializeExpr(&mut **n as *mut _), } } } diff --git a/src/node_mut.rs b/src/node_mut.rs index 8006bd5..615cebb 100644 --- a/src/node_mut.rs +++ b/src/node_mut.rs @@ -254,6 +254,22 @@ pub enum NodeMut { JsonObjectAgg(*mut protobuf::JsonObjectAgg), JsonArrayAgg(*mut protobuf::JsonArrayAgg), RtepermissionInfo(*mut protobuf::RtePermissionInfo), + WindowFuncRunCondition(*mut protobuf::WindowFuncRunCondition), + MergeSupportFunc(*mut protobuf::MergeSupportFunc), + JsonBehavior(*mut protobuf::JsonBehavior), + JsonExpr(*mut protobuf::JsonExpr), + JsonTablePath(*mut protobuf::JsonTablePath), + JsonTablePathScan(*mut protobuf::JsonTablePathScan), + JsonTableSiblingJoin(*mut protobuf::JsonTableSiblingJoin), + SinglePartitionSpec(*mut protobuf::SinglePartitionSpec), + JsonArgument(*mut protobuf::JsonArgument), + JsonFuncExpr(*mut protobuf::JsonFuncExpr), + JsonTablePathSpec(*mut protobuf::JsonTablePathSpec), + JsonTable(*mut protobuf::JsonTable), + JsonTableColumn(*mut protobuf::JsonTableColumn), + JsonParseExpr(*mut protobuf::JsonParseExpr), + JsonScalarExpr(*mut protobuf::JsonScalarExpr), + JsonSerializeExpr(*mut protobuf::JsonSerializeExpr), } impl NodeMut { @@ -432,7 +448,7 @@ impl NodeMut { NodeMut::CreateStatsStmt(n) => Ok(NodeEnum::CreateStatsStmt(n.as_ref().ok_or(err)?.clone())), NodeMut::AlterCollationStmt(n) => Ok(NodeEnum::AlterCollationStmt(n.as_ref().ok_or(err)?.clone())), NodeMut::CallStmt(n) => Ok(NodeEnum::CallStmt(Box::new(n.as_ref().ok_or(err)?.clone()))), - NodeMut::AlterStatsStmt(n) => Ok(NodeEnum::AlterStatsStmt(n.as_ref().ok_or(err)?.clone())), + NodeMut::AlterStatsStmt(n) => Ok(NodeEnum::AlterStatsStmt(Box::new(n.as_ref().ok_or(err)?.clone()))), NodeMut::AExpr(n) => Ok(NodeEnum::AExpr(Box::new(n.as_ref().ok_or(err)?.clone()))), NodeMut::ColumnRef(n) => Ok(NodeEnum::ColumnRef(n.as_ref().ok_or(err)?.clone())), NodeMut::ParamRef(n) => Ok(NodeEnum::ParamRef(n.as_ref().ok_or(err)?.clone())), @@ -520,6 +536,22 @@ impl NodeMut { NodeMut::JsonObjectAgg(n) => Ok(NodeEnum::JsonObjectAgg(Box::new(n.as_ref().ok_or(err)?.clone()))), NodeMut::JsonArrayAgg(n) => Ok(NodeEnum::JsonArrayAgg(Box::new(n.as_ref().ok_or(err)?.clone()))), NodeMut::RtepermissionInfo(n) => Ok(NodeEnum::RtepermissionInfo(n.as_ref().ok_or(err)?.clone())), + NodeMut::WindowFuncRunCondition(n) => Ok(NodeEnum::WindowFuncRunCondition(Box::new(n.as_ref().ok_or(err)?.clone()))), + NodeMut::MergeSupportFunc(n) => Ok(NodeEnum::MergeSupportFunc(Box::new(n.as_ref().ok_or(err)?.clone()))), + NodeMut::JsonBehavior(n) => Ok(NodeEnum::JsonBehavior(Box::new(n.as_ref().ok_or(err)?.clone()))), + NodeMut::JsonExpr(n) => Ok(NodeEnum::JsonExpr(Box::new(n.as_ref().ok_or(err)?.clone()))), + NodeMut::JsonTablePath(n) => Ok(NodeEnum::JsonTablePath(n.as_ref().ok_or(err)?.clone())), + NodeMut::JsonTablePathScan(n) => Ok(NodeEnum::JsonTablePathScan(Box::new(n.as_ref().ok_or(err)?.clone()))), + NodeMut::JsonTableSiblingJoin(n) => Ok(NodeEnum::JsonTableSiblingJoin(Box::new(n.as_ref().ok_or(err)?.clone()))), + NodeMut::SinglePartitionSpec(n) => Ok(NodeEnum::SinglePartitionSpec(n.as_ref().ok_or(err)?.clone())), + NodeMut::JsonArgument(n) => Ok(NodeEnum::JsonArgument(Box::new(n.as_ref().ok_or(err)?.clone()))), + NodeMut::JsonFuncExpr(n) => Ok(NodeEnum::JsonFuncExpr(Box::new(n.as_ref().ok_or(err)?.clone()))), + NodeMut::JsonTablePathSpec(n) => Ok(NodeEnum::JsonTablePathSpec(Box::new(n.as_ref().ok_or(err)?.clone()))), + NodeMut::JsonTable(n) => Ok(NodeEnum::JsonTable(Box::new(n.as_ref().ok_or(err)?.clone()))), + NodeMut::JsonTableColumn(n) => Ok(NodeEnum::JsonTableColumn(Box::new(n.as_ref().ok_or(err)?.clone()))), + NodeMut::JsonParseExpr(n) => Ok(NodeEnum::JsonParseExpr(Box::new(n.as_ref().ok_or(err)?.clone()))), + NodeMut::JsonScalarExpr(n) => Ok(NodeEnum::JsonScalarExpr(Box::new(n.as_ref().ok_or(err)?.clone()))), + NodeMut::JsonSerializeExpr(n) => Ok(NodeEnum::JsonSerializeExpr(Box::new(n.as_ref().ok_or(err)?.clone()))), } } } diff --git a/src/node_ref.rs b/src/node_ref.rs index 41a97d6..6209544 100644 --- a/src/node_ref.rs +++ b/src/node_ref.rs @@ -254,6 +254,22 @@ pub enum NodeRef<'a> { JsonObjectAgg(&'a protobuf::JsonObjectAgg), JsonArrayAgg(&'a protobuf::JsonArrayAgg), RtepermissionInfo(&'a protobuf::RtePermissionInfo), + WindowFuncRunCondition(&'a protobuf::WindowFuncRunCondition), + MergeSupportFunc(&'a protobuf::MergeSupportFunc), + JsonBehavior(&'a protobuf::JsonBehavior), + JsonExpr(&'a protobuf::JsonExpr), + JsonTablePath(&'a protobuf::JsonTablePath), + JsonTablePathScan(&'a protobuf::JsonTablePathScan), + JsonTableSiblingJoin(&'a protobuf::JsonTableSiblingJoin), + SinglePartitionSpec(&'a protobuf::SinglePartitionSpec), + JsonArgument(&'a protobuf::JsonArgument), + JsonFuncExpr(&'a protobuf::JsonFuncExpr), + JsonTablePathSpec(&'a protobuf::JsonTablePathSpec), + JsonTable(&'a protobuf::JsonTable), + JsonTableColumn(&'a protobuf::JsonTableColumn), + JsonParseExpr(&'a protobuf::JsonParseExpr), + JsonScalarExpr(&'a protobuf::JsonScalarExpr), + JsonSerializeExpr(&'a protobuf::JsonSerializeExpr), } impl<'a> NodeRef<'a> { @@ -431,7 +447,7 @@ impl<'a> NodeRef<'a> { NodeRef::CreateStatsStmt(n) => NodeEnum::CreateStatsStmt((*n).clone()), NodeRef::AlterCollationStmt(n) => NodeEnum::AlterCollationStmt((*n).clone()), NodeRef::CallStmt(n) => NodeEnum::CallStmt(Box::new((*n).clone())), - NodeRef::AlterStatsStmt(n) => NodeEnum::AlterStatsStmt((*n).clone()), + NodeRef::AlterStatsStmt(n) => NodeEnum::AlterStatsStmt(Box::new((*n).clone())), NodeRef::AExpr(n) => NodeEnum::AExpr(Box::new((*n).clone())), NodeRef::ColumnRef(n) => NodeEnum::ColumnRef((*n).clone()), NodeRef::ParamRef(n) => NodeEnum::ParamRef((*n).clone()), @@ -519,6 +535,22 @@ impl<'a> NodeRef<'a> { NodeRef::JsonObjectAgg(n) => NodeEnum::JsonObjectAgg(Box::new((*n).clone())), NodeRef::JsonArrayAgg(n) => NodeEnum::JsonArrayAgg(Box::new((*n).clone())), NodeRef::RtepermissionInfo(n) => NodeEnum::RtepermissionInfo((*n).clone()), + NodeRef::WindowFuncRunCondition(n) => NodeEnum::WindowFuncRunCondition(Box::new((*n).clone())), + NodeRef::MergeSupportFunc(n) => NodeEnum::MergeSupportFunc(Box::new((*n).clone())), + NodeRef::JsonBehavior(n) => NodeEnum::JsonBehavior(Box::new((*n).clone())), + NodeRef::JsonExpr(n) => NodeEnum::JsonExpr(Box::new((*n).clone())), + NodeRef::JsonTablePath(n) => NodeEnum::JsonTablePath((*n).clone()), + NodeRef::JsonTablePathScan(n) => NodeEnum::JsonTablePathScan(Box::new((*n).clone())), + NodeRef::JsonTableSiblingJoin(n) => NodeEnum::JsonTableSiblingJoin(Box::new((*n).clone())), + NodeRef::SinglePartitionSpec(n) => NodeEnum::SinglePartitionSpec((*n).clone()), + NodeRef::JsonArgument(n) => NodeEnum::JsonArgument(Box::new((*n).clone())), + NodeRef::JsonFuncExpr(n) => NodeEnum::JsonFuncExpr(Box::new((*n).clone())), + NodeRef::JsonTablePathSpec(n) => NodeEnum::JsonTablePathSpec(Box::new((*n).clone())), + NodeRef::JsonTable(n) => NodeEnum::JsonTable(Box::new((*n).clone())), + NodeRef::JsonTableColumn(n) => NodeEnum::JsonTableColumn(Box::new((*n).clone())), + NodeRef::JsonParseExpr(n) => NodeEnum::JsonParseExpr(Box::new((*n).clone())), + NodeRef::JsonScalarExpr(n) => NodeEnum::JsonScalarExpr(Box::new((*n).clone())), + NodeRef::JsonSerializeExpr(n) => NodeEnum::JsonSerializeExpr(Box::new((*n).clone())), } } } diff --git a/tests/data/plpgsql_query.json b/tests/data/plpgsql_query.json index cd9dcdd..41b7110 100644 --- a/tests/data/plpgsql_query.json +++ b/tests/data/plpgsql_query.json @@ -48,7 +48,7 @@ "PLpgSQL_var": { "datatype": { "PLpgSQL_type": { - "typname": "UNKNOWN" + "typname": "pg_catalog.int4" } }, "refname": "input" @@ -58,7 +58,7 @@ "PLpgSQL_var": { "datatype": { "PLpgSQL_type": { - "typname": "UNKNOWN" + "typname": "pg_catalog.\"boolean\"" } }, "refname": "found" diff --git a/tests/data/plpgsql_simple.json b/tests/data/plpgsql_simple.json index b70cc76..0f58cc9 100644 --- a/tests/data/plpgsql_simple.json +++ b/tests/data/plpgsql_simple.json @@ -48,7 +48,7 @@ "PLpgSQL_var": { "datatype": { "PLpgSQL_type": { - "typname": "UNKNOWN" + "typname": "pg_catalog.\"varchar\"" } }, "refname": "v_name" @@ -58,7 +58,7 @@ "PLpgSQL_var": { "datatype": { "PLpgSQL_type": { - "typname": "UNKNOWN" + "typname": "pg_catalog.\"varchar\"" } }, "refname": "v_version" @@ -68,7 +68,7 @@ "PLpgSQL_var": { "datatype": { "PLpgSQL_type": { - "typname": "UNKNOWN" + "typname": "pg_catalog.\"boolean\"" } }, "refname": "found" diff --git a/tests/fingerprint_tests.rs b/tests/fingerprint_tests.rs index d552ee2..e395c58 100644 --- a/tests/fingerprint_tests.rs +++ b/tests/fingerprint_tests.rs @@ -178,7 +178,7 @@ fn it_works() { assert_eq!(result.hex, "d8a65a814fbc5f95"); let result = fingerprint("DEALLOCATE ALL").unwrap(); - assert_eq!(result.hex, "d8a65a814fbc5f95"); + assert_eq!(result.hex, "2debfb8745df64a7"); let result = fingerprint("EXPLAIN ANALYZE SELECT a").unwrap(); assert_eq!(result.hex, "82845c1b5c6102e5"); diff --git a/tests/parse_tests.rs b/tests/parse_tests.rs index 57e5284..a14c1ff 100644 --- a/tests/parse_tests.rs +++ b/tests/parse_tests.rs @@ -125,11 +125,13 @@ fn it_parses_ALTER_TABLE() { conname: "", deferrable: false, initdeferred: false, - location: 21, + skip_validation: false, + initially_valid: false, is_no_inherit: false, raw_expr: None, cooked_expr: "", generated_when: "", + inhcount: 0, nulls_not_distinct: false, keys: [ Node { @@ -159,8 +161,7 @@ fn it_parses_ALTER_TABLE() { fk_del_set_cols: [], old_conpfeqop: [], old_pktable_oid: 0, - skip_validation: false, - initially_valid: false, + location: 21, }, ), ),