-
-
Notifications
You must be signed in to change notification settings - Fork 256
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
Composite Type Support #592
Conversation
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
@eeeebbbbrrrr I'd appreciate you giving this a lookie-loo if you can. :) |
|
||
Demonstrates how to create a `IntegerAvgState` aggregate. | ||
|
||
This example also demonstrates the use of `PgVarlena<T>` and how to use `#[pgvarlena_inoutfuncs]` with `#[derive(PostgresType)]`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should probably do an aggregate test...
Signed-off-by: Ana Hobden <[email protected]>
pgx-utils/src/lib.rs
Outdated
@@ -517,7 +517,8 @@ pub fn anonymonize_lifetimes(value: &mut syn::Type) { | |||
match arg { | |||
// rename lifetimes to the anonymous lifetime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment no longer matches the code below. Why are we now using 'static
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks!
We need anything using a lifetime to use the same lifetime so that the TypeId
s match (&'a Foo
and &'b Foo
have different TypeId
s)
@@ -331,23 +331,6 @@ impl<T: FromDatum> FromDatum for Vec<T> { | |||
} | |||
} | |||
|
|||
impl<T: FromDatum> FromDatum for Vec<Option<T>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this go away? This is for supporting postgres ARRAY[]
s that might contain NULL
elements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is now a conflicting implementation which covers the same type and works the same:
error[E0119]: conflicting implementations of trait `datum::from::FromDatum` for type `std::vec::Vec<std::option::Option<_>>`
--> pgx/src/datum/array.rs:334:1
|
317 | impl<T: FromDatum> FromDatum for Vec<T> {
| --------------------------------------- first implementation here
...
334 | impl<T: FromDatum> FromDatum for Vec<Option<T>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `std::vec::Vec<std::option::Option<_>>`
For more information about this error, try `rustc --explain E0119`.
error: could not compile `pgx` due to previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `pgx` due to previous error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I re-add this and remove that conflicting implementation I get a lot of type failures, eg
Compiling pgx v0.5.0-beta.0 (/home/ana/git/tcdi/pgx/pgx)
error[E0277]: the trait bound `std::option::Option<heap_tuple::PgHeapTuple<'static, pgbox::AllocatedByRust>>: datum::PostgresType` is not satisfied
--> pgx/src/lib.rs:263:26
|
263 | TypeId::of::<Array<Option<PgHeapTuple<'static, AllocatedByRust>>>>(),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `datum::PostgresType` is not implemented for `std::option::Option<heap_tuple::PgHeapTuple<'static, pgbox::AllocatedByRust>>`
|
note: required because of the requirements on the impl of `from::FromDatum` for `std::option::Option<heap_tuple::PgHeapTuple<'static, pgbox::AllocatedByRust>>`
--> pgx/src/datum/varlena.rs:344:14
|
344 | impl<'de, T> FromDatum for T
| ^^^^^^^^^ ^
note: required by a bound in `datum::array::Array`
--> pgx/src/datum/array.rs:16:25
|
16 | pub struct Array<'a, T: FromDatum> {
| ^^^^^^^^^ required by this bound in `datum::array::Array`
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
@zombodb I added many changes around aggregate support, did you want to take another review pass or shall I merge once I'm comfortable with it? I need to do a self review still. |
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Signed-off-by: Ana Hobden <[email protected]>
Addresses #499, #203, #326. Helps along #451.
Adds "Composite Type" support to PGX.
What's changed
pgx::composite_type!("name")
macro now exists. It can be used in most PGX related macros where one would use an argument. It expands to create aPgHeapTuple
, but the PGX related macros are able to derive additional metadata from this macro for SQL generation.PgHeapTuple
now implementsFromDatum
.PgHeapTuple
acquired anew_composite_type
constructor which allows users to create a heap tuple shaped for a given composite type string. EggHeapTuple::new_composite_type("dog")
.PgHeapTuple
now has ainto_trigger_datum
function which will result in the correctDatum
for returning from a#[pg_trigger]
function. Since this was done as part of macro expanded code, no user changes should be required.IntoDatum
implementation ofPgHeapTuple
changed to better work with composite types. Specialized trigger related functions exist and should work transparently for users.PgTupleDesc
now has afor_composite_type
function which allows users to construct one for a given composite type by name.Breaking Changes
Option<default!(i32, 1)>
in your#[pg_externs]
. Change it todefault!(Option<i32>, 1)
.pgx::utils::sql_entity_graph
were updated to include fields for composite types.MaybeNamedVariadicTypeList
was removed, a newUsedType
was added, and various internals around macro-expansion-time type resolution were tinkered with.pgx::pg_module_magic!();
(orpgx::pg_sql_graph_magic!();
) in your extension, they now expand to expose apub extern "C" fn __pgx_sql_mappings() -> ::pgx::utils::sql_entity_graph::RustToSqlMapping
instead of their prior. This was done to both reduce the number of exported symbols extensions you, as well as support composite types.