use crate::{catalog::index_policy::ducklake_base_type, error::Error};
pub(crate) fn ensure_inlinable(column_name: &str, column_type: &str) -> Result<(), Error> {
if ducklake_base_type(column_type) == "VARIANT" {
return Err(Error::Unsupported(format!(
"moraine: column {column_name} is {column_type}, which moraine cannot store — its \
inline data is serialized through Arrow, and DuckDB's Arrow format has no VARIANT \
support. Use JSON (or another type) instead."
)));
}
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn variant_is_refused_as_unsupported_everything_else_allowed() {
let err = ensure_inlinable("v", "VARIANT").unwrap_err();
assert!(matches!(err, Error::Unsupported(_)));
let text = err.to_string();
for expected in ["moraine", "VARIANT", "Arrow"] {
assert!(text.contains(expected), "{text}");
}
assert!(ensure_inlinable("v", "variant").is_err());
for ty in ["BIGINT", "JSON", "STRUCT(a VARCHAR)", "GEOMETRY", "UUID"] {
assert!(ensure_inlinable("c", ty).is_ok(), "{ty}");
}
}
}