Skip to content

Commit 98f1148

Browse files
authored
Fix #1326 (#1328)
1 parent 4908be4 commit 98f1148

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

pgml-extension/src/orm/model.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,8 @@ impl Model {
955955
.map_or(snapshot::NULL_CATEGORY_KEY.to_string(), |k| k.to_string())
956956
}
957957
pgrx_pg_sys::NUMERICOID => {
958-
let element: Result<Option<AnyNumeric>, TryFromDatumError> = tuple.get_by_index(index);
958+
let element: Result<Option<AnyNumeric>, TryFromDatumError> =
959+
tuple.get_by_index(index);
959960
element
960961
.unwrap()
961962
.map_or(snapshot::NULL_CATEGORY_KEY.to_string(), |k| k.to_string())
@@ -999,7 +1000,8 @@ impl Model {
9991000
features.push(element.unwrap().map_or(f32::NAN, |v| v as f32));
10001001
}
10011002
pgrx_pg_sys::NUMERICOID => {
1002-
let element: Result<Option<AnyNumeric>, TryFromDatumError> = tuple.get_by_index(index);
1003+
let element: Result<Option<AnyNumeric>, TryFromDatumError> =
1004+
tuple.get_by_index(index);
10031005
features.push(element.unwrap().map_or(f32::NAN, |v| v.try_into().unwrap()));
10041006
}
10051007
// TODO handle NULL to NaN for arrays

pgml-extension/src/orm/snapshot.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ impl Snapshot {
749749
.map(|c| c.quoted_name())
750750
.collect::<Vec<String>>()
751751
.join(", "),
752-
self.relation_name(),
752+
self.relation_name_quoted(),
753753
match self.materialized {
754754
// If the snapshot is materialized, we already randomized it.
755755
true => "",
@@ -990,7 +990,10 @@ impl Snapshot {
990990
"int8" => row[column.position].value::<i64>().unwrap().map(|v| v.to_string()),
991991
"float4" => row[column.position].value::<f32>().unwrap().map(|v| v.to_string()),
992992
"float8" => row[column.position].value::<f64>().unwrap().map(|v| v.to_string()),
993-
"numeric" => row[column.position].value::<AnyNumeric>().unwrap().map(|v| v.to_string()),
993+
"numeric" => row[column.position]
994+
.value::<AnyNumeric>()
995+
.unwrap()
996+
.map(|v| v.to_string()),
994997
"bpchar" | "text" | "varchar" => {
995998
row[column.position].value::<String>().unwrap().map(|v| v.to_string())
996999
}
@@ -1084,7 +1087,7 @@ impl Snapshot {
10841087
check_column_size(column, vec.len());
10851088

10861089
for j in vec {
1087-
vector.push(j.rescale::<6,0>().unwrap().try_into().unwrap())
1090+
vector.push(j.rescale::<6, 0>().unwrap().try_into().unwrap())
10881091
}
10891092
}
10901093
_ => error!(
@@ -1101,7 +1104,10 @@ impl Snapshot {
11011104
"int8" => row[column.position].value::<i64>().unwrap().map(|v| v as f32),
11021105
"float4" => row[column.position].value::<f32>().unwrap(),
11031106
"float8" => row[column.position].value::<f64>().unwrap().map(|v| v as f32),
1104-
"numeric" => row[column.position].value::<AnyNumeric>().unwrap().map(|v| v.rescale::<6,0>().unwrap().try_into().unwrap()),
1107+
"numeric" => row[column.position]
1108+
.value::<AnyNumeric>()
1109+
.unwrap()
1110+
.map(|v| v.rescale::<6, 0>().unwrap().try_into().unwrap()),
11051111
_ => error!(
11061112
"Unhandled type for quantitative scalar column: {} {:?}",
11071113
column.name, column.pg_type
@@ -1156,6 +1162,16 @@ impl Snapshot {
11561162
false => self.relation_name.clone(),
11571163
}
11581164
}
1165+
1166+
fn relation_name_quoted(&self) -> String {
1167+
match self.materialized {
1168+
true => self.snapshot_name(), // Snapshot name is already safe.
1169+
false => {
1170+
let (schema_name, table_name) = Self::fully_qualified_table(&self.relation_name);
1171+
format!("\"{}\".\"{}\"", schema_name, table_name)
1172+
}
1173+
}
1174+
}
11591175
}
11601176

11611177
#[inline]

0 commit comments

Comments
 (0)