8000 feat(postgres): read each column's type modifier by colinhacks · Pull Request #180 · colinhacks/reylo · GitHub
[go: up one dir, main page]

Skip to content
< 8000 div data-target="react-partial.reactRoot">
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion engine/facade/src/clients/tokio_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl AsyncAnswerer<Describe> for Answers<'_> {
let columns: Vec<Value> = stmt
.columns()
.iter()
.map(|c| json!({ "name": c.name(), "oid": c.type_().oid(), "table": c.table_oid().unwrap_or(0), "attnum": c.column_id().map_or(0, i32::from) }))
.map(|c| json!({ "name": c.name(), "oid": c.type_().oid(), "table": c.table_oid().unwrap_or(0), "attnum": c.column_id().map_or(0, i32::from), "typmod": c.type_modifier() }))
.collect();
serde_json::from_value(json!({ "params": params, "columns": columns })).map(Ok).map_err(|e| HostError(e.to_string()))
}
Expand Down
2 changes: 1 addition & 1 deletion engine/native/src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl Program for Postgres {
Ok(stmt) => json!({
"status": "described",
"params": stmt.params().iter().map(tokio_postgres::types::Type::oid).collect::<Vec<_>>(),
"columns": stmt.columns().iter().map(|col| json!({ "name": col.name(), "oid": col.type_().oid(), "table": col.table_oid().unwrap_or(0), "attnum": col.column_id().map_or(0, i32::from) })).collect::<Vec<_>>(),
"columns": stmt.columns().iter().map(|col| json!({ "name": col.name(), "oid": col.type_().oid(), "table": col.table_oid().unwrap_or(0), "attnum": col.column_id().map_or(0, i32::from), "typmod": col.type_modifier() })).collect::<Vec<_>>(),
}),
Err(e) => failure(&e),
}
Expand Down
4 changes: 4 additions & 0 deletions engine/postgres/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ pub struct RawColumn {
pub table: u32,
#[serde(default)]
pub attnum: i32,
/// The column's type modifier as RowDescription reports it (`varchar(20)`, `numeric(10,2)`);
/// -1, none, where the host sends none.
#[serde(default = "crate::pgtypes::no_typmod")]
pub typmod: i32,
}

/// Postgres, for [`reylo_engine_core::api::call`].
Expand Down
6 changes: 3 additions & 3 deletions engine/postgres/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3597,7 +3597,7 @@ mod tests {
}

fn col(nullable: bool, type_oid: u32) -> DescribedColumn {
DescribedColumn { name: "a".into(), type_oid, type_name: String::new(), nullable, nullable_items: None, values: None, document: None, non_finite: Default::default(), whole_row: false }
DescribedColumn { name: "a".into(), type_oid, typmod: -1, type_name: String::new(), nullable, nullable_items: None, values: None, document: None, non_finite: Default::default(), whole_row: false }
}

#[test]
Expand Down Expand Up @@ -4473,8 +4473,8 @@ mod tests {
assert_eq!(p.head[1], None);
assert_eq!(p.leaves.as_deref(), Some("SELECT u AS a0 FROM users u WHERE u.id = NULL"));
// The probe says whether it was the row after all: a column named like the alias is not.
let row = DescribedColumn { name: "whole".into(), type_oid: 16500, type_name: "users".into(), nullable: true, nullable_items: None, values: None, document: None, non_finite: Default::default(), whole_row: false };
let column = DescribedColumn { name: "whole".into(), type_oid: oid::TEXT, type_name: "text".into(), nullable: true, nullable_items: None, values: None, document: None, non_finite: Default::default(), whole_row: false };
let row = DescribedColumn { name: "whole".into(), type_oid: 16500, typmod: -1, type_name: "users".into(), nullable: true, nullable_items: None, values: None, document: None, non_finite: Default::default(), whole_row: false };
let column = DescribedColumn { name: "whole".into(), type_oid: oid::TEXT, typmod: -1, type_name: "text".into(), nullable: true, nullable_items: None, values: None, document: None, non_finite: Default::default(), whole_row: false };
assert!(resolve(p.head[0].as_ref().unwrap(), Some(&[row])).non_null);
assert!(!resolve(p.head[0].as_ref().unwrap(), Some(&[column])).non_null);
assert_eq!(pg("SELECT p FROM users u LEFT JOIN posts p ON p.user_id = u.id").head[0], None);
Expand Down
6 changes: 3 additions & 3 deletions engine/postgres/src/jsonshape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1476,9 +1476,9 @@ impl ResolveCtx<'_> {
/// A probe's column as a type: what the catalog says of it, with what the probe's own
/// analysis said of an array it builds (`array[x, null]` holds a NULL element) and of the
/// values, the document and the non-finite values a CHECK keeps it to or out of, as a result
/// column gets them.
/// column gets them, under the type modifier its describe reported (`varchar(20)`'s size).
fn column(&self, col: &DescribedColumn) -> Type {
let ty = if col.whole_row { self.registry.render_row(col.type_oid) } else { self.registry.render(col.type_oid) };
let ty = if col.whole_row { self.registry.render_row(col.type_oid) } else { self.registry.render_typmod(col.type_oid, col.typmod) };
col.non_finite.apply(crate::postgres::with_document(crate::postgres::with_values(crate::postgres::with_items(ty, col.nullable_items), col.values.as_deref(), self.registry.is_string(col.type_oid)), col.document.as_ref()))
}

Expand Down Expand Up @@ -2390,7 +2390,7 @@ mod tests {
const BYTEA: u32 = 17;

fn column(name: &str, type_oid: u32, type_name: &str, nullable: bool) -> DescribedColumn {
DescribedColumn { name: name.into(), type_oid, type_name: type_name.into(), nullable, nullable_items: None, values: None, document: None, non_finite: Default::default(), whole_row: false }
DescribedColumn { name: name.into(), type_oid, typmod: -1, type_name: type_name.into(), nullable, nullable_items: None, values: None, document: None, non_finite: Default::default(), whole_row: false }
}

#[test]
Expand Down
Loading
Loading
0