Skip to content

fix: ordered_param_types and add unit test#357

Open
cemremengu wants to merge 1 commit into
datafusion-contrib:masterfrom
cemremengu:patch-1
Open

fix: ordered_param_types and add unit test#357
cemremengu wants to merge 1 commit into
datafusion-contrib:masterfrom
cemremengu:patch-1

Conversation

@cemremengu

Copy link
Copy Markdown

ordered_param_types() received inferred parameter types from DataFusion as a HashMap keyed by strings such as $1, $2, ..., $10. Because HashMaps are unordered, the code sorted the keys before building the positional parameter type list returned to the client.

However, the keys were sorted lexicographically:

$1, $10, $2, $3, ...

instead of numerically:

$1, $2, $3, ..., $10

For queries with more than nine placeholders, this caused parameter types to be assigned to the wrong positions. For example, the type inferred for $10 could be reported or used as if it belonged to $2. As a result, clients could bind or deserialize values using incorrect PostgreSQL types, such as treating a UUID parameter as a timestamp.

The fix was to sort parameters by their numeric suffix:

types.sort_by_key(|(key, _)| {
    key.trim_start_matches('$')
        .parse::<u32>()
        .unwrap_or(u32::MAX)
});

Refactor sorting of parameter types to sort numerically based on placeholder keys. Add unit test to verify correct sorting of parameter types.
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