Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
276 changes: 190 additions & 86 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ As for other platforms: patches welcome!

### 🔧 Tools Setup ###

Building the extension requires valid [rust](https://www.rust-lang.org/) (we build and test on 1.64), [rustfmt](https://github.com/rust-lang/rustfmt), and clang installs, along with the postgres headers for whichever version of postgres you are running, and pgx.
Building the extension requires valid [rust](https://www.rust-lang.org/) (we build and test on 1.65), [rustfmt](https://github.com/rust-lang/rustfmt), and clang installs, along with the postgres headers for whichever version of postgres you are running, and pgx.
We recommend installing rust using the [official instructions](https://www.rust-lang.org/tools/install):
```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Expand All @@ -51,7 +51,7 @@ sudo apt-get install make gcc pkg-config clang postgresql-server-dev-14 libssl-d

Next you need [cargo-pgx](https://github.com/tcdi/pgx), which can be installed with
```bash
cargo install --version '=0.6.1' --force cargo-pgx
cargo install --version '=0.7.1' --force cargo-pgx
```

You must reinstall cargo-pgx whenever you update your Rust compiler, since cargo-pgx needs to be built with the same compiler as Toolkit.
Expand Down
7 changes: 4 additions & 3 deletions extension/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ pg_test = ["approx"]
[dependencies]
# Keep synchronized with `cargo install --version N.N.N cargo-pgx` in Readme.md and docker/ci/Dockerfile
# Also `pgx-tests` down below in `dev-dependencies`.
pgx = "=0.6.1"
pgx-macros = "=0.6.1"
pgx = "=0.7.1"
pgx-macros = "=0.7.1"
pgx-sql-entity-graph = "=0.7.1"
encodings = {path="../crates/encodings"}
flat_serialize = {path="../crates/flat_serialize/flat_serialize"}
flat_serialize_macro = {path="../crates/flat_serialize/flat_serialize_macro"}
Expand Down Expand Up @@ -55,5 +56,5 @@ spfunc = "0.1.0"
statrs = "0.15.0"

[dev-dependencies]
pgx-tests = "=0.6.1"
pgx-tests = "=0.7.1"
approx = "0.4.0"
26 changes: 15 additions & 11 deletions extension/src/aggregate_builder_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,26 @@ mod tests {

#[pg_test]
fn test_anything_in_experimental_and_returns_first() {
Spi::execute(|client| {
Spi::connect(|mut client| {
let output = client
.select(
.update(
"SELECT toolkit_experimental.anything(val) \
FROM (VALUES ('foo'), ('bar'), ('baz')) as v(val)",
None,
None,
)
.unwrap()
.first()
.get_one::<String>();
.get_one::<String>()
.unwrap();
assert_eq!(output.as_deref(), Some("foo"));
})
}

#[pg_test]
fn test_anything_has_correct_fn_names_and_def() {
Spi::execute(|client| {
let spec = get_aggregate_spec(&client, "anything");
Spi::connect(|mut client| {
let spec = get_aggregate_spec(&mut client, "anything");
// output is
// fn kind (`a`), volatility, parallel-safety, num args, final fn modify (is this right?)
// transition type (`internal`)
Expand All @@ -131,8 +133,8 @@ mod tests {

#[pg_test]
fn test_cagg_anything_has_correct_fn_names_and_def() {
Spi::execute(|client| {
let spec = get_aggregate_spec(&client, "cagg_anything");
Spi::connect(|mut client| {
let spec = get_aggregate_spec(&mut client, "cagg_anything");
// output is
// fn kind (`a`), volatility, parallel-safety, num args, final fn modify (is this right?)
// transition type (`internal`)
Expand All @@ -159,8 +161,8 @@ mod tests {

#[pg_test]
fn test_parallel_anything_has_correct_fn_names_and_def() {
Spi::execute(|client| {
let spec = get_aggregate_spec(&client, "parallel_anything");
Spi::connect(|mut client| {
let spec = get_aggregate_spec(&mut client, "parallel_anything");
// output is
// fn kind (`a`), volatility, parallel-safety, num args, final fn modify (is this right?)
// transition type (`internal`)
Expand Down Expand Up @@ -188,9 +190,9 @@ mod tests {
// It gets annoying, and segfaulty to handle many arguments from the Spi.
// For simplicity, we just return a single string representing the tuple
// and use string-comparison.
fn get_aggregate_spec(client: &spi::SpiClient, aggregate_name: &str) -> String {
fn get_aggregate_spec(client: &mut spi::SpiClient, aggregate_name: &str) -> String {
client
.select(
.update(
&format!(
r#"SELECT (
prokind,
Expand All @@ -213,8 +215,10 @@ mod tests {
None,
None,
)
.unwrap()
.first()
.get_one::<String>()
.unwrap()
.expect("no aggregate found")
}
}
4 changes: 2 additions & 2 deletions extension/src/aggregate_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use pgx::pg_sys;

// TODO move to func_utils once there are enough function to warrant one
pub unsafe fn get_collation(fcinfo: pg_sys::FunctionCallInfo) -> Option<pg_sys::Oid> {
if (*fcinfo).fncollation == 0 {
if (*fcinfo).fncollation == pg_sys::Oid::INVALID {
None
} else {
Some((*fcinfo).fncollation)
Expand All @@ -13,7 +13,7 @@ pub unsafe fn get_collation(fcinfo: pg_sys::FunctionCallInfo) -> Option<pg_sys::

pub fn get_collation_or_default(fcinfo: pg_sys::FunctionCallInfo) -> Option<pg_sys::Oid> {
if fcinfo.is_null() {
Some(100) // TODO: default OID, there should be a constant for this
Some(unsafe { pg_sys::Oid::from_u32_unchecked(100) }) // TODO: default OID, there should be a constant for this
} else {
unsafe { get_collation(fcinfo) }
}
Expand Down
40 changes: 20 additions & 20 deletions extension/src/asap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ mod tests {
fn test_against_reference() {
// Test our ASAP implementation against the reference implementation at http://www.futuredata.io.s3-website-us-west-2.amazonaws.com/asap/
// The sample data is the first 100 points of the second sample data set. Note that the dates are not important for this test.
Spi::execute(|client| {
client.select("SET timezone TO 'UTC'", None, None);
let mut result = client.select(
Spi::connect(|mut client| {
client.update("SET timezone TO 'UTC'", None, None).unwrap();
let mut result = client.update(
"
SELECT value
FROM unnest(
Expand All @@ -223,46 +223,46 @@ mod tests {
) AS v(i, val)
)) s",
None,
None);
None).unwrap();

assert_relative_eq!(
result.next().unwrap()[1].value::<f64>().unwrap() as f32,
result.next().unwrap()[1].value::<f64>().unwrap().unwrap() as f32,
10.39
);
assert_relative_eq!(
result.next().unwrap()[1].value::<f64>().unwrap() as f32,
result.next().unwrap()[1].value::<f64>().unwrap().unwrap() as f32,
9.29
);
assert_relative_eq!(
result.next().unwrap()[1].value::<f64>().unwrap() as f32,
result.next().unwrap()[1].value::<f64>().unwrap().unwrap() as f32,
7.54
);
assert_relative_eq!(
result.next().unwrap()[1].value::<f64>().unwrap() as f32,
result.next().unwrap()[1].value::<f64>().unwrap().unwrap() as f32,
7.8
);
assert_relative_eq!(
result.next().unwrap()[1].value::<f64>().unwrap() as f32,
result.next().unwrap()[1].value::<f64>().unwrap().unwrap() as f32,
10.34
);
assert_relative_eq!(
result.next().unwrap()[1].value::<f64>().unwrap() as f32,
result.next().unwrap()[1].value::<f64>().unwrap().unwrap() as f32,
11.01
);
assert_relative_eq!(
result.next().unwrap()[1].value::<f64>().unwrap() as f32,
result.next().unwrap()[1].value::<f64>().unwrap().unwrap() as f32,
10.54
);
assert_relative_eq!(
result.next().unwrap()[1].value::<f64>().unwrap() as f32,
result.next().unwrap()[1].value::<f64>().unwrap().unwrap() as f32,
8.01
);
assert_relative_eq!(
result.next().unwrap()[1].value::<f64>().unwrap() as f32,
result.next().unwrap()[1].value::<f64>().unwrap().unwrap() as f32,
8.99
);
assert_relative_eq!(
result.next().unwrap()[1].value::<f64>().unwrap() as f32,
result.next().unwrap()[1].value::<f64>().unwrap().unwrap() as f32,
8.73
);
assert!(result.next().is_none());
Expand All @@ -271,8 +271,8 @@ mod tests {

#[pg_test]
fn test_asap_equivalence() {
Spi::execute(|client| {
let mut value_result = client.select(
Spi::connect(|mut client| {
let mut value_result = client.update(
"
SELECT time::text, value
FROM unnest(
Expand All @@ -291,9 +291,9 @@ mod tests {
) AS v(i, val)
)) s",
None,
None);
None).unwrap();

let mut tvec_result = client.select(
let mut tvec_result = client.update(
"
SELECT time::text, value
FROM unnest(
Expand All @@ -314,13 +314,13 @@ mod tests {
), 10)
))",
None,
None);
None).unwrap();

for _ in 0..10 {
let v = value_result.next().unwrap();
let t = tvec_result.next().unwrap();
assert_eq!(v[1].value::<&str>(), t[1].value::<&str>());
assert_eq!(v[2].value::<f64>(), t[2].value::<f64>());
assert_eq!(v[2].value::<f64>().unwrap(), t[2].value::<f64>().unwrap());
}
assert!(value_result.next().is_none());
assert!(tvec_result.next().is_none());
Expand Down
Loading