Skip to content

Commit 2452450

Browse files
authored
Fixes for aggregates (#408)
* Fix source type mapping in aggregates Source type mapping (as used with pg_sys::TimestampTz) requires an exact match between the source type map, and the interpreted source type for a given type. The stringify!() macro adds unwanted whitespace in qualified types (e.g. "pg_sys::TimestampTz" becomes "pg_sys :: TimestampTz") which breaks type mapping. * Fix generated type for moving state in aggregates
1 parent f3c1c25 commit 2452450

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

pgx-utils/src/sql_entity_graph/pg_aggregate/aggregate_type.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ impl AggregateType {
6565

6666
pub(crate) fn entity_tokens(&self) -> Expr {
6767
let ty = &self.ty;
68+
let ty_string = ty.to_token_stream().to_string().replace(" ", "");
6869
parse_quote! {
6970
pgx::datum::sql_entity_graph::aggregate::AggregateType {
70-
ty_source: stringify!(#ty),
71+
ty_source: #ty_string,
7172
ty_id: core::any::TypeId::of::<#ty>(),
7273
full_path: core::any::type_name::<#ty>(),
7374
name: None,

pgx-utils/src/sql_entity_graph/pg_aggregate/maybe_variadic_type.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,13 @@ impl MaybeNamedVariadicType {
9090

9191
fn entity_tokens(&self) -> Expr {
9292
let ty = self.variadic_ty.as_ref().unwrap_or(&self.ty);
93+
let ty_string = ty.to_token_stream().to_string().replace(" ", "");
9394
let variadic = self.variadic_ty.is_some();
9495
let name = self.name.iter();
9596
parse_quote! {
9697
pgx::datum::sql_entity_graph::aggregate::MaybeVariadicAggregateType {
9798
agg_ty: pgx::datum::sql_entity_graph::aggregate::AggregateType {
98-
ty_source: stringify!(#ty),
99+
ty_source: #ty_string,
99100
ty_id: core::any::TypeId::of::<#ty>(),
100101
full_path: core::any::type_name::<#ty>(),
101102
name: None#( .unwrap_or(Some(#name)) )*,

pgx-utils/src/sql_entity_graph/pg_aggregate/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ impl PgAggregate {
517517
let type_args_iter = &self.type_args.entity_tokens();
518518
let type_order_by_iter = self.type_order_by.iter().map(|x| x.entity_tokens());
519519
let type_moving_state_iter = self.type_moving_state.iter();
520+
let type_moving_state_string = self.type_moving_state.as_ref().map(|t| { t.to_token_stream().to_string().replace(" ", "") });
520521
let type_stype = self.type_stype.entity_tokens();
521522
let const_parallel_iter = self.const_parallel.iter();
522523
let const_finalize_modify_iter = self.const_finalize_modify.iter();
@@ -557,9 +558,10 @@ impl PgAggregate {
557558
msfunc: None#( .unwrap_or(Some(stringify!(#fn_moving_state_iter))) )*,
558559
minvfunc: None#( .unwrap_or(Some(stringify!(#fn_moving_state_inverse_iter))) )*,
559560
mstype: None#( .unwrap_or(Some(pgx::datum::sql_entity_graph::aggregate::AggregateType {
560-
ty_source: stringify!(#type_moving_state_iter),
561+
ty_source: #type_moving_state_string,
561562
ty_id: core::any::TypeId::of::<#type_moving_state_iter>(),
562563
full_path: core::any::type_name::<#type_moving_state_iter>(),
564+
name: None
563565
})) )*,
564566
mfinalfunc: None#( .unwrap_or(Some(stringify!(#fn_moving_finalize_iter))) )*,
565567
mfinalfunc_modify: None#( .unwrap_or(#const_moving_finalize_modify_iter) )*,

0 commit comments

Comments
 (0)