Skip to content
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

Update v1.1.0 #301

Merged
merged 2 commits into from
Apr 25, 2023
Merged

Update v1.1.0 #301

merged 2 commits into from
Apr 25, 2023

Conversation

eeeebbbbrrrr
Copy link
Contributor

@eeeebbbbrrrr eeeebbbbrrrr commented Apr 25, 2023

Welcome to PL/Rust v1.1.0. It is primarily a bugfix release in response to issues created and noticed immediately after v1.0.0.

New Features

Zero Copy Arrays by @eeeebbbbrrrr in #298

When a LANGUAGE plrust function has an ARRAY argument, it is now treated as a pgrx::Array, which is a zero-copy wrapper over the underlying Postgres ArrayType.

The primary change here is that v1.0.0 used a Vec<T>, so it provided random access into the array at the expense of deconstructing the whole thing ahead of time. pgrx::Array is essentially a lazy Iterator with some convenience methods like .len(). If you need random access into the array, you'll need to collect into a Vec<Option<T>> first:

CREATE OR REPLACE FUNCTION array_nth(a int[], i int) 
          RETURNS int 
          IMMUTABLE
          STRICT 
          LANGUAGE plrust AS 
$$
   let a = a.into_iter().collect::<Vec<_>>();
   Ok(a[i as usize])
$$;

SELECT array_nth(ARRAY[1,2,3,4,5,6,7,8,9,10], 5);
 array_nth 
-----------
         6

Existing functions based on PL/Rust v1.0.0 will continue to compile unchanged during a pg_dump/pg_reload cycle, but users should consider updating their function code and re-creating them with CREATE OR REPLACE FUNCTION.

Bug Fixes

Purposely fail to create on databases that aren't UTF8 by @eeeebbbbrrrr in #281

PL/Rust can only support databases that are UTF8 encoded and going forward PL/Rust will fail during CREATE EXTENSION if this is isn't the case.

It is possible in the future we can lift or greatly lessen this restriction

Incorrect type mappings by @eeeebbbbrrrr in #299

A few SQL types were incorrectly mapped to Rust types at either the argument or return type positions. The changes are:

  • BYTEA is now returned as a Vec<u8>
  • CSTRING is now a &CStr at the argument position and a CString at the return type position
  • TID is now a pg_sys::ItemPointerData in both argument and return positions

General Project Cleanup

Add Dockerfile for quick trial use by @BradyBonnette in #287

See the documentation to quickly try PL/Rust within a Docker container!

While not at all a production-worth Dockerfile, our hope is that it'll be easy for newcomers to interactively try PL/Rust.

AnyNumeric now supports the std::iter::Sum trait pgcentralfoundation/pgrx#1117

Functions that use NUMERIC can now easily sum an array/iterator of them:

 CREATE FUNCTION sum_array(a NUMERIC[]) RETURNS NUMERIC
          IMMUTABLE 
          STRICT
          LANGUAGE PLRUST AS
$$
   Ok(Some(a.into_iter().map(|v| v.unwrap_or_default()).sum()))
$$;

SELECT sum_array(ARRAY[1, 2.0, 3.5]);
 sum_array 
-----------
       6.5

Other Minor Changes

Documentation

New Contributors

Full Changelog: v1.0.0...v1.1.0

@eeeebbbbrrrr eeeebbbbrrrr changed the base branch from main to develop April 25, 2023 18:52
@eeeebbbbrrrr eeeebbbbrrrr merged commit 8346ff8 into develop Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant