Skip to content
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
7 changes: 6 additions & 1 deletion crates/duckdb/src/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::str;

use arrow::datatypes::DataType;

use crate::{Error, Result, Statement};
use crate::{core::LogicalTypeHandle, Error, Result, Statement};

/// Information about a column of a DuckDB query.
#[derive(Debug)]
Expand Down Expand Up @@ -160,6 +160,11 @@ impl Statement<'_> {
pub fn column_type(&self, idx: usize) -> DataType {
self.stmt.column_type(idx)
}

/// Returns the declared logical data type of the column.
pub fn column_logical_type(&self, idx: usize) -> LogicalTypeHandle {
self.stmt.column_logical_type(idx)
}
}

#[cfg(test)]
Expand Down
22 changes: 22 additions & 0 deletions crates/duckdb/src/core/logical_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,28 @@ impl LogicalTypeHandle {
};
unsafe { Self::new(c_logical_type) }
}

/// Alias of the logical type.
pub fn get_alias(&self) -> Option<String> {
unsafe {
let alias_ptr = duckdb_logical_type_get_alias(self.ptr);
if alias_ptr.is_null() {
None
} else {
let c_str = CString::from_raw(alias_ptr);
let alias = c_str.to_str().unwrap();
Some(alias.to_string())
}
}
}

/// Set the alias of the logical type.
pub fn set_alias(&self, alias: &str) {
unsafe {
let alias = CString::new(alias).unwrap();
duckdb_logical_type_set_alias(self.ptr, alias.as_ptr());
}
}
}

#[cfg(test)]
Expand Down
10 changes: 9 additions & 1 deletion crates/duckdb/src/raw_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use arrow::{
use super::{ffi, Result};
#[cfg(feature = "polars")]
use crate::arrow2;
use crate::{error::result_from_duckdb_arrow, Error};
use crate::{core::LogicalTypeHandle, error::result_from_duckdb_arrow, Error};

/// Private newtype for DuckDB prepared statements that finalize themselves when dropped.
///
Expand Down Expand Up @@ -215,6 +215,14 @@ impl RawStatement {
self.schema().field(idx).data_type().to_owned()
}

#[inline]
pub fn column_logical_type(&self, idx: usize) -> LogicalTypeHandle {
unsafe {
let ptr = ffi::duckdb_prepared_statement_column_logical_type(self.ptr, idx as u64);
LogicalTypeHandle::new(ptr)
}
}

#[inline]
pub fn schema(&self) -> SchemaRef {
self.schema.clone().unwrap()
Expand Down