Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
montanalow merged 1 commit intomasterfrommontana/1041
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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
17 changes: 17 additions & 0 deletionspgml-extension/src/orm/model.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -954,6 +954,12 @@ impl Model {
.unwrap()
.map_or(snapshot::NULL_CATEGORY_KEY.to_string(), |k| k.to_string())
}
pgrx_pg_sys::NUMERICOID => {
let element: Result<Option<AnyNumeric>, TryFromDatumError> = tuple.get_by_index(index);
element
.unwrap()
.map_or(snapshot::NULL_CATEGORY_KEY.to_string(), |k| k.to_string())
}
_ => error!(
"Unsupported type for categorical column: {:?}. oid: {:?}",
column.name, attribute.atttypid
Expand DownExpand Up@@ -992,6 +998,10 @@ impl Model {
let element: Result<Option<f64>, TryFromDatumError> = tuple.get_by_index(index);
features.push(element.unwrap().map_or(f32::NAN, |v| v as f32));
}
pgrx_pg_sys::NUMERICOID => {
let element: Result<Option<AnyNumeric>, TryFromDatumError> = tuple.get_by_index(index);
features.push(element.unwrap().map_or(f32::NAN, |v| v.try_into().unwrap()));
}
// TODO handle NULL to NaN for arrays
pgrx_pg_sys::BOOLARRAYOID => {
let element: Result<Option<Vec<bool>>, TryFromDatumError> =
Expand DownExpand Up@@ -1035,6 +1045,13 @@ impl Model {
features.push(*j as f32);
}
}
pgrx_pg_sys::NUMERICARRAYOID => {
let element: Result<Option<Vec<AnyNumeric>>, TryFromDatumError> =
tuple.get_by_index(index);
for j in element.as_ref().unwrap().as_ref().unwrap() {
features.push(j.clone().try_into().unwrap());
}
}
_ => error!(
"Unsupported type for quantitative column: {:?}. oid: {:?}",
column.name, attribute.atttypid
Expand Down
10 changes: 10 additions & 0 deletionspgml-extension/src/orm/snapshot.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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" => {
Comment on lines 990 to 994
Copy link

@eeeebbbbrrrreeeebbbbrrrrFeb 22, 2024
edited
Loading

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 inpg_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 theColumn 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.

row[column.position].value::<String>().unwrap().map(|v| v.to_string())
}
Expand DownExpand Up@@ -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
Expand All@@ -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
Copy link

@eeeebbbbrrrreeeebbbbrrrrFeb 22, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

And now that you have the type oids, youcould 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.

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp