Skip to content
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

nexus: support uuid arrays #2316

Merged
merged 1 commit into from
Dec 4, 2024
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
6 changes: 6 additions & 0 deletions nexus/peer-postgres/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ fn values_from_row(row: &Row) -> Vec<Value> {
let uuid: Option<Uuid> = row.get(i);
uuid.map(Value::Uuid).unwrap_or(Value::Null)
}
&Type::UUID_ARRAY => {
let uuid: Option<Vec<Uuid>> = row.get(i);
uuid.map(ArrayValue::Uuid)
.map(Value::Array)
.unwrap_or(Value::Null)
}
&Type::INET | &Type::CIDR => {
let s: Option<MaskedIpAddr> = row.get(i);
s.map(Value::IpAddr).unwrap_or(Value::Null)
Expand Down
16 changes: 16 additions & 0 deletions nexus/value/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use bytes::{BufMut, Bytes, BytesMut};
use chrono::{DateTime, NaiveDate, NaiveTime, Utc};
use pgwire::types::ToSqlText;
use postgres_types::{IsNull, ToSql, Type};
use uuid::{Uuid, fmt::Hyphenated};

#[derive(Debug, PartialEq, Clone)]
pub enum ArrayValue {
Expand All @@ -21,6 +22,7 @@ pub enum ArrayValue {
Text(Vec<String>),
Binary(Vec<Bytes>),
VarBinary(Vec<Bytes>),
Uuid(Vec<Uuid>),
Date(Vec<NaiveDate>),
Time(Vec<NaiveTime>),
TimeWithTimeZone(Vec<NaiveTime>),
Expand Down Expand Up @@ -94,6 +96,11 @@ impl ArrayValue {
.map(|v| serde_json::Value::String(hex::encode(v)))
.collect(),
),
ArrayValue::Uuid(arr) => serde_json::Value::Array(
arr.iter()
.map(|v| serde_json::Value::String(v.to_string()))
.collect(),
),
ArrayValue::Date(arr) => serde_json::Value::Array(
arr.iter()
.map(|&v| serde_json::Value::String(v.to_string()))
Expand Down Expand Up @@ -151,6 +158,7 @@ impl ToSql for ArrayValue {
ArrayValue::Text(arr) => arr.to_sql(ty, out)?,
ArrayValue::Binary(_arr) => todo!("support encoding array of binary"),
ArrayValue::VarBinary(_arr) => todo!("support encoding array of varbinary"),
ArrayValue::Uuid(arr) => arr.to_sql(ty, out)?,
ArrayValue::Date(arr) => arr.to_sql(ty, out)?,
ArrayValue::Time(arr) => arr.to_sql(ty, out)?,
ArrayValue::TimeWithTimeZone(arr) => arr.to_sql(ty, out)?,
Expand Down Expand Up @@ -229,6 +237,14 @@ impl ToSqlText for ArrayValue {
ArrayValue::Text(arr) => array_to_sql_text!(arr, ty, out),
ArrayValue::Binary(_arr) => todo!("implement encoding array of binary"),
ArrayValue::VarBinary(_arr) => todo!("implement encoding array of varbinary"),
ArrayValue::Uuid(arr) => {
let mut buf = [0u8; Hyphenated::LENGTH];
for v in arr {
out.put_slice(b"'");
out.put_slice(v.hyphenated().encode_lower(&mut buf).as_bytes());
out.put_slice(b"',");
}
}
ArrayValue::Date(arr) => array_to_sql_text!(arr, ty, out),
ArrayValue::Time(arr) => array_to_sql_text!(arr, ty, out),
ArrayValue::TimeWithTimeZone(arr) => array_to_sql_text!(arr, ty, out),
Expand Down
Loading