Skip to content

Commit

Permalink
fix(cubesql): udf format_type prepared statement fix (#5260)
Browse files Browse the repository at this point in the history
  • Loading branch information
gandronchik committed Sep 30, 2022
1 parent f83009c commit 307ed1b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 68 deletions.
6 changes: 4 additions & 2 deletions rust/cubesql/cubesql/src/compile/engine/udf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ type OidType = UInt32Type;
// TODO: Combine with downcast
fn cast_oid_arg(argument: &ArrayRef, name: &str) -> Result<ArrayRef> {
match argument.data_type() {
DataType::Int32 | DataType::Int64 => {
// TODO: rm Utf8 && LargeUtf8 when Prepared Statements support integer types
DataType::Int32 | DataType::Int64 | DataType::Utf8 | DataType::LargeUtf8 => {
cast(&argument, &DataType::UInt32).map_err(|err| err.into())
}
// We use UInt32 for OID
Expand Down Expand Up @@ -1524,7 +1525,8 @@ pub fn create_format_type_udf() -> ScalarUDF {
let tmp = cast_oid_arg(&args[0], "oid")?;
let oids = downcast_primitive_arg!(tmp, "oid", OidType);
// TODO: See pg_attribute.atttypmod
let typemods = downcast_primitive_arg!(args[1], "typemod", Int64Type);
let typemods = cast(&args[1], &DataType::Int64)?;
let typemods = downcast_primitive_arg!(typemods, "typemod", Int64Type);

let result = oids
.iter()
Expand Down
3 changes: 2 additions & 1 deletion rust/cubesql/cubesql/src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7077,7 +7077,8 @@ ORDER BY \"COUNT(count)\" DESC"
format_type(t.oid, 4) ft4,
format_type(t.oid, 0) ft0,
format_type(t.oid, -1) ftneg,
format_type(t.oid, NULL::bigint) ftnull
format_type(t.oid, NULL::bigint) ftnull,
format_type(cast(t.oid as text), '5') ftstr
FROM pg_catalog.pg_type t
ORDER BY t.oid ASC
;
Expand Down
Loading

0 comments on commit 307ed1b

Please sign in to comment.