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

Returning Vec<Vec<f32>> produces unexpected results #1762

Open
jawj opened this issue Jul 8, 2024 · 4 comments
Open

Returning Vec<Vec<f32>> produces unexpected results #1762

jawj opened this issue Jul 8, 2024 · 4 comments
Labels
confusing This doesn't seem right

Comments

@jawj
Copy link

jawj commented Jul 8, 2024

I have a function that returns a nested Vec<Vec<f32>>:

#[pg_extern]
fn test_nested() -> Vec<Vec<f32>> {
    vec![vec![1.1, 1.2, 1.3], vec![2.1, 2.2, 2.3]]
}

I expected the same results as this:

# select ARRAY[ARRAY[1.1, 1.2, 1.3], ARRAY[2.1, 2.2, 2.3]];
             array             
-------------------------------
 {{1.1,1.2,1.3},{2.1,2.2,2.3}}
(1 row)

# select array_dims(ARRAY[ARRAY[1.1, 1.2, 1.3], ARRAY[2.1, 2.2, 2.3]]);
 array_dims 
------------
 [1:2][1:3]
(1 row)

But instead I get this:

# select test_nested();
            test_nested            
-----------------------------------
 {"{1.1,1.2,1.3}","{2.1,2.2,2.3}"}
(1 row)

# select array_dims(test_nested());
 array_dims 
------------
 [1:2]
(1 row)

Is this a bug, or have I misunderstood something?

Is there some other way I can return a nested real[][] array from a Rust function?

@workingjubilee
Copy link
Member

workingjubilee commented Jul 8, 2024

No, we do not currently have support for multidimensional arrays, and when we do, they will not be nested Vecs.

@workingjubilee
Copy link
Member

This is why they should not be nested Vecs:

# SELECT array_dims('{{1,2,3,4},{5,6},{7,8,9}}'::int[][]);
ERROR:  malformed array literal: "{{1,2,3,4},{5,6},{7,8,9}}"
LINE 1: SELECT array_dims('{{1,2,3,4},{5,6},{7,8,9}}'::int[][]);
                          ^
DETAIL:  Multidimensional arrays must have sub-arrays with matching dimensions.

Vec<Vec<T>> does not enforce this requirement. However, it is very simple to define a type that does (and indeed the real reason multidimensional array support has been blocked, right now, is "I'm too busy implementing fixes for everything else").

@jawj
Copy link
Author

jawj commented Jul 8, 2024

OK: thanks for the explanation, and for all your work on this project.

@workingjubilee workingjubilee changed the title Returning Vec<Vec<f32>> does not produce nested arrays Returning Vec<Vec<f32>> produces unexpected results Jul 8, 2024
@workingjubilee workingjubilee added the confusing This doesn't seem right label Jul 8, 2024
@workingjubilee
Copy link
Member

This bug report could be considered a duplicate of #968 but I am currently considering retooling the RetAbi implementations so that this just does not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confusing This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants