Skip to content

Commit

Permalink
use truncationDiagnostics down at the column
Browse files Browse the repository at this point in the history
buffer level
  • Loading branch information
pacman82 committed Sep 26, 2023
1 parent aa1c24b commit 8e6b3fb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 24 deletions.
6 changes: 3 additions & 3 deletions odbc-api/src/buffers/any_buffer.rs
Expand Up @@ -6,7 +6,7 @@ use crate::{
columnar_bulk_inserter::BoundInputSlice,
error::TooLargeBufferSize,
handles::{CData, CDataMut, HasDataType, StatementRef},
Bit, DataType, Error,
Bit, DataType, Error, cursor::TruncationDiagnostics,
};

use super::{
Expand Down Expand Up @@ -633,12 +633,12 @@ unsafe impl ColumnBuffer for AnyBuffer {
}
}

fn has_truncated_values(&self, num_rows: usize) -> bool {
fn has_truncated_values(&self, num_rows: usize) -> Option<TruncationDiagnostics> {
match self {
AnyBuffer::Binary(col) => col.has_truncated_values(num_rows),
AnyBuffer::Text(col) => col.has_truncated_values(num_rows),
AnyBuffer::WText(col) => col.has_truncated_values(num_rows),
_ => false,
_ => None,
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions odbc-api/src/buffers/bin_column.rs
Expand Up @@ -3,7 +3,7 @@ use crate::{
columnar_bulk_inserter::BoundInputSlice,
error::TooLargeBufferSize,
handles::{CData, CDataMut, HasDataType, Statement, StatementRef},
DataType, Error,
DataType, Error, cursor::TruncationDiagnostics,
};

use log::debug;
Expand Down Expand Up @@ -101,17 +101,17 @@ impl BinColumn {
}
}

/// `true` if any value is truncated in the range [0, num_rows).
/// `Some` if any value is truncated in the range [0, num_rows).
///
/// After fetching data we may want to know if any value has been truncated due to the buffer
/// not being able to hold elements of that size. This method checks the indicator buffer
/// element wise.
pub fn has_truncated_values(&self, num_rows: usize) -> bool {
pub fn has_truncated_values(&self, num_rows: usize) -> Option<TruncationDiagnostics> {
self.indicators
.iter()
.copied()
.take(num_rows)
.any(|indicator| Indicator::from_isize(indicator).is_truncated(self.max_len))
.any(|indicator| Indicator::from_isize(indicator).is_truncated(self.max_len)).then_some(TruncationDiagnostics { })
}

/// Changes the maximum element length the buffer can hold. This operation is useful if you find
Expand Down Expand Up @@ -350,12 +350,12 @@ impl<'c> BinColumnView<'c> {
}
}

/// `true` if any value is truncated in the range [0, num_rows).
/// `Some` if any value is truncated in the range [0, num_rows).
///
/// After fetching data we may want to know if any value has been truncated due to the buffer
/// not being able to hold elements of that size. This method checks the indicator buffer
/// element wise.
pub fn has_truncated_values(&self) -> bool {
pub fn has_truncated_values(&self) -> Option<TruncationDiagnostics> {
self.col.has_truncated_values(self.num_rows)
}
}
Expand Down
12 changes: 6 additions & 6 deletions odbc-api/src/buffers/columnar.rs
Expand Up @@ -107,7 +107,7 @@ where
fn has_truncated_values(&self) -> Option<TruncationDiagnostics> {
self.columns
.iter()
.any(|col_buffer| col_buffer.1.has_truncated_values(*self.num_rows)).then_some(TruncationDiagnostics { })
.find_map(|col_buffer| col_buffer.1.has_truncated_values(*self.num_rows))
}
}

Expand Down Expand Up @@ -155,12 +155,12 @@ pub unsafe trait ColumnBuffer: CDataMut {
/// Current capacity of the column
fn capacity(&self) -> usize;

/// `true` if any value is truncated in the range [0, num_rows).
/// `Some` if any value is truncated in the range [0, num_rows).
///
/// After fetching data we may want to know if any value has been truncated due to the buffer
/// not being able to hold elements of that size. This method checks the indicator buffer
/// element wise.
fn has_truncated_values(&self, num_rows: usize) -> bool;
fn has_truncated_values(&self, num_rows: usize) -> Option<TruncationDiagnostics>;
}

unsafe impl<T> ColumnBuffer for WithDataType<T>
Expand All @@ -181,7 +181,7 @@ where
self.value.capacity()
}

fn has_truncated_values(&self, num_rows: usize) -> bool {
fn has_truncated_values(&self, num_rows: usize) -> Option<TruncationDiagnostics> {
self.value.has_truncated_values(num_rows)
}
}
Expand Down Expand Up @@ -424,8 +424,8 @@ where
self.len()
}

fn has_truncated_values(&self, _num_rows: usize) -> bool {
false
fn has_truncated_values(&self, _num_rows: usize) -> Option<TruncationDiagnostics> {
None
}
}

Expand Down
16 changes: 8 additions & 8 deletions odbc-api/src/buffers/text_column.rs
Expand Up @@ -2,7 +2,7 @@ use crate::{
columnar_bulk_inserter::BoundInputSlice,
error::TooLargeBufferSize,
handles::{CData, CDataMut, HasDataType, Statement, StatementRef},
DataType, Error,
DataType, Error, cursor::TruncationDiagnostics,
};

use super::{ColumnBuffer, Indicator};
Expand Down Expand Up @@ -135,18 +135,18 @@ impl<C> TextColumn<C> {
}
}

/// `true` if any value is truncated in the range [0, num_rows).
/// `Some` if any value is truncated in the range [0, num_rows).
///
/// After fetching data we may want to know if any value has been truncated due to the buffer
/// not being able to hold elements of that size. This method checks the indicator buffer
/// element wise.
pub fn has_truncated_values(&self, num_rows: usize) -> bool {
pub fn has_truncated_values(&self, num_rows: usize) -> Option<TruncationDiagnostics> {
let max_bin_length = self.max_str_len * size_of::<C>();
self.indicators
.iter()
.copied()
.take(num_rows)
.any(|indicator| Indicator::from_isize(indicator).is_truncated(max_bin_length))
.any(|indicator| Indicator::from_isize(indicator).is_truncated(max_bin_length)).then_some(TruncationDiagnostics { })
}

/// Changes the maximum string length the buffer can hold. This operation is useful if you find
Expand Down Expand Up @@ -330,13 +330,13 @@ where
self.indicators.len()
}

fn has_truncated_values(&self, num_rows: usize) -> bool {
fn has_truncated_values(&self, num_rows: usize) -> Option<TruncationDiagnostics> {
let max_bin_length = self.max_str_len * size_of::<C>();
self.indicators
.iter()
.copied()
.take(num_rows)
.any(|indicator| Indicator::from_isize(indicator).is_truncated(max_bin_length))
.any(|indicator| Indicator::from_isize(indicator).is_truncated(max_bin_length)).then_some(TruncationDiagnostics { })
}
}

Expand Down Expand Up @@ -405,12 +405,12 @@ impl<'c, C> TextColumnView<'c, C> {
self.col.max_len()
}

/// `true` if any value is truncated.
/// `Some` if any value is truncated.
///
/// After fetching data we may want to know if any value has been truncated due to the buffer
/// not being able to hold elements of that size. This method checks the indicator buffer
/// element wise.
pub fn has_truncated_values(&self) -> bool {
pub fn has_truncated_values(&self) -> Option<TruncationDiagnostics> {
self.col.has_truncated_values(self.num_rows)
}
}
Expand Down
1 change: 0 additions & 1 deletion odbc-api/src/cursor.rs
Expand Up @@ -417,7 +417,6 @@ unsafe impl<T: RowSetBuffer> RowSetBuffer for &mut T {

/// Additional information in case of writing a value into too short a buffer.
pub struct TruncationDiagnostics {

}

/// In order to save on network overhead, it is recommended to use block cursors instead of fetching
Expand Down

0 comments on commit 8e6b3fb

Please sign in to comment.