-
Notifications
You must be signed in to change notification settings - Fork 12
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
Numeric improvement and fix #65
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,8 +23,7 @@ use crate::{ | |
geometry::{is_postgis_geometry_type, Geometry}, | ||
map::{is_map_type, Map}, | ||
pg_arrow_type_conversions::{ | ||
extract_precision_from_numeric_typmod, extract_scale_from_numeric_typmod, | ||
MAX_DECIMAL_PRECISION, | ||
extract_precision_and_scale_from_numeric_typmod, should_write_numeric_as_text, | ||
}, | ||
}, | ||
}; | ||
|
@@ -65,8 +64,8 @@ pub(crate) struct PgToArrowAttributeContext { | |
is_geometry: bool, | ||
is_map: bool, | ||
attribute_contexts: Option<Vec<PgToArrowAttributeContext>>, | ||
scale: Option<usize>, | ||
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. What are the changes here for? Related to the 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. Postgres returns scale and precision as But we adjust negative scale e.g. |
||
precision: Option<usize>, | ||
scale: Option<u32>, | ||
precision: Option<u32>, | ||
} | ||
|
||
impl PgToArrowAttributeContext { | ||
|
@@ -126,8 +125,9 @@ impl PgToArrowAttributeContext { | |
let precision; | ||
let scale; | ||
if attribute_typoid == NUMERICOID { | ||
precision = Some(extract_precision_from_numeric_typmod(typmod)); | ||
scale = Some(extract_scale_from_numeric_typmod(typmod)); | ||
let (p, s) = extract_precision_and_scale_from_numeric_typmod(typmod); | ||
precision = Some(p); | ||
scale = Some(s); | ||
} else { | ||
precision = None; | ||
scale = None; | ||
|
@@ -274,7 +274,7 @@ fn to_arrow_primitive_array( | |
.precision | ||
.expect("missing precision in context"); | ||
|
||
if precision > MAX_DECIMAL_PRECISION { | ||
if should_write_numeric_as_text(precision) { | ||
reset_fallback_to_text_context(attribute_context.typoid, attribute_context.typmod); | ||
|
||
to_arrow_primitive_array!(FallbackToText, tuples, attribute_context) | ||
|
@@ -359,7 +359,7 @@ fn to_arrow_list_array( | |
.precision | ||
.expect("missing precision in context"); | ||
|
||
if precision > MAX_DECIMAL_PRECISION { | ||
if should_write_numeric_as_text(precision) { | ||
reset_fallback_to_text_context(attribute_context.typoid, attribute_context.typmod); | ||
|
||
to_arrow_list_array!(pgrx::Array<FallbackToText>, tuples, attribute_context) | ||
|
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.
I believe this is true, but just being explicit in my understanding: So effectively if you want
numeric
with larger precision than 38 you need to explicitly define it there, it just will not end up being an actual stored numeric, but reads/writes will work to convert transparently from the Postgres side?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.
True. An example