-
Notifications
You must be signed in to change notification settings - Fork 328
add support for numerics #1324
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
Merged
Merged
add support for numerics #1324
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -990,6 +990,7 @@ impl Snapshot { | |
"int8" => row[column.position].value::<i64>().unwrap().map(|v| v.to_string()), | ||
"float4" => row[column.position].value::<f32>().unwrap().map(|v| v.to_string()), | ||
"float8" => row[column.position].value::<f64>().unwrap().map(|v| v.to_string()), | ||
"numeric" => row[column.position].value::<AnyNumeric>().unwrap().map(|v| v.to_string()), | ||
"bpchar" | "text" | "varchar" => { | ||
row[column.position].value::<String>().unwrap().map(|v| v.to_string()) | ||
} | ||
|
@@ -1078,6 +1079,14 @@ impl Snapshot { | |
vector.push(j as f32) | ||
} | ||
} | ||
"numeric[]" => { | ||
let vec = row[column.position].value::<Vec<AnyNumeric>>().unwrap().unwrap(); | ||
check_column_size(column, vec.len()); | ||
|
||
for j in vec { | ||
vector.push(j.rescale::<6,0>().unwrap().try_into().unwrap()) | ||
} | ||
} | ||
_ => error!( | ||
"Unhandled type for quantitative array column: {} {:?}", | ||
column.name, column.pg_type | ||
|
@@ -1092,6 +1101,7 @@ impl Snapshot { | |
"int8" => row[column.position].value::<i64>().unwrap().map(|v| v as f32), | ||
"float4" => row[column.position].value::<f32>().unwrap(), | ||
"float8" => row[column.position].value::<f64>().unwrap().map(|v| v as f32), | ||
"numeric" => row[column.position].value::<AnyNumeric>().unwrap().map(|v| v.rescale::<6,0>().unwrap().try_into().unwrap()), | ||
_ => error!( | ||
"Unhandled type for quantitative scalar column: {} {:?}", | ||
column.name, column.pg_type | ||
Comment on lines
1105
to
1107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And now that you have the type oids, you could call its output function here and just get its string representation from Postgres. Who knows if it'd then be something you could otherwise handle, but maybe? Same thing around line 1090 for the array case. |
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey! @montanalow asked me to take a quick look here.
I feel like these string types names would be better as OID values. pgrx has them all in
pg_sys::
, likepg_sys::INT8OID
,pg_sys::NUMERICOID
,pg_sys::NUMERICARRAYOID
, and so on. It looks like this is the approach you use up inmodel.rs
already.I guess you'd have to figure out the type oids wherever you construct the
Column
entries, but that doesn't seem too difficult. I think in that SELECT statement around line 505 you could writeudt_name::text::regtype::oid
instead ofudt_name::TEXT
.Comparing on Oid value will be a little more performant, I suppose, and it'll future proof you from accidentally making type-os in the code.