Skip to content

Commit

Permalink
WIP:
Browse files Browse the repository at this point in the history
  • Loading branch information
thedodd committed Sep 3, 2024
1 parent cfa78bf commit 59a4be8
Showing 3 changed files with 27 additions and 8 deletions.
20 changes: 15 additions & 5 deletions extension/src/stats_agg.rs
Original file line number Diff line number Diff line change
@@ -1644,13 +1644,23 @@ mod tests {

let control = state.unwrap();
let buffer = stats1d_trans_serialize(Inner::from(control.clone()).internal().unwrap());
let buffer = pgrx::varlena::varlena_to_byte_slice(buffer.0.cast_mut_ptr());
let slice_for_test =
pgrx::varlena::varlena_to_byte_slice(buffer.0.cast_mut_ptr::<pg_sys::varlena>());
println!(
"debug serializer output after return:\n{:?}",
slice_for_test
);

let expected = pgrx::varlena::rust_byte_slice_to_bytea(buffer);
let new_state =
stats1d_trans_deserialize_inner(bytea(pg_sys::Datum::from(expected.as_ptr())));
// let expected = pgrx::varlena::rust_byte_slice_to_bytea(buffer);
// let new_state =
// stats1d_trans_deserialize_inner(bytea(pg_sys::Datum::from(expected.as_ptr())));
let new_state = stats1d_trans_deserialize_inner(buffer);

assert_eq!(&*new_state, &*control);
assert_eq!(
&*new_state, &*control,
"unexpected difference in bytes output, got:\n{:?}\nexpected:\n{:?}",
&*new_state, &*control
);
}
}

11 changes: 10 additions & 1 deletion extension/src/type_builder.rs
Original file line number Diff line number Diff line change
@@ -362,7 +362,11 @@ macro_rules! do_serialize {
let len = writer.position().try_into().expect("serialized size too large");
::pgrx::set_varsize(writer.get_mut().as_mut_ptr() as *mut _, len);
}
$crate::raw::bytea::from(pg_sys::Datum::from(writer.into_inner().as_mut_ptr()))

let raw_bytes = writer.into_inner();
println!("debug serializer output:\n{:?}", raw_bytes);
crate::raw::bytea::from(pg_sys::Datum::from(raw_bytes.as_mut_ptr()))
// $crate::raw::bytea::from(pg_sys::Datum::from(writer.into_inner().as_mut_ptr()))
}
};
}
@@ -373,6 +377,10 @@ macro_rules! do_deserialize {

let state: $t = unsafe {
let input: $crate::raw::bytea = $bytes;
let slice_for_test =
pgrx::varlena::varlena_to_byte_slice(input.0.cast_mut_ptr::<pg_sys::varlena>());
println!("bytes entering into decoder:\n{:?}", slice_for_test);

let input: pgrx::pg_sys::Datum = input.into();
let detoasted = pg_sys::pg_detoast_datum_packed(input.cast_mut_ptr());
let len = pgrx::varsize_any_exhdr(detoasted);
@@ -393,6 +401,7 @@ macro_rules! do_deserialize {
bytes[1]
)
}
println!("bytes just before decoding:\n{:?}", bytes);
bincode::deserialize(&bytes[2..])
.unwrap_or_else(|e| pgrx::error!("deserialization error {}", e))
};
4 changes: 2 additions & 2 deletions tools/build
Original file line number Diff line number Diff line change
@@ -104,9 +104,9 @@ while [ $# -gt 0 ]; do
$nop cargo fetch
export RUSTC_BOOTSTRAP=1
export __CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS=nightly
export RUSTFLAGS='-Z sanitizer=memory'
# export RUSTFLAGS='-Z sanitizer=memory'
rustup component add rust-src --toolchain 1.74.0-x86_64-unknown-linux-gnu
$nop cargo test -Zbuild-std --profile $profile --target --target x86_64-unknown-linux-gnu --features "$pg pg_test" --no-default-features -- stats_agg::tests
$nop cargo test -Zbuild-std --profile $profile --target --target x86_64-unknown-linux-gnu --features "$pg pg_test" --no-default-features -- --nocapture stats_agg::tests
;;

install)

0 comments on commit 59a4be8

Please sign in to comment.