use super::core::ColumnView;
use crate::column::{BooleanColumn, Column, ColumnType, Float64Column, Int64Column, StringColumn};
use crate::error::{Error, Result};
use std::any::Any;
impl ColumnView {
pub fn column_type(&self) -> ColumnType {
self.column.column_type()
}
pub fn len(&self) -> usize {
self.column.len()
}
pub fn is_empty(&self) -> bool {
self.column.is_empty()
}
pub fn as_int64(&self) -> Option<&crate::column::Int64Column> {
if let Column::Int64(ref col) = self.column {
Some(col)
} else {
None
}
}
pub fn as_float64(&self) -> Option<&crate::column::Float64Column> {
if let Column::Float64(ref col) = self.column {
Some(col)
} else {
None
}
}
pub fn as_string(&self) -> Option<&crate::column::StringColumn> {
if let Column::String(ref col) = self.column {
Some(col)
} else {
None
}
}
pub fn as_boolean(&self) -> Option<&crate::column::BooleanColumn> {
if let Column::Boolean(ref col) = self.column {
Some(col)
} else {
None
}
}
pub fn column(&self) -> &Column {
&self.column
}
pub fn into_column(self) -> Column {
self.column
}
pub fn get_f64(&self, index: usize) -> Result<Option<f64>> {
match &self.column {
Column::Float64(col) => col.get(index),
_ => Err(Error::ColumnTypeMismatch {
name: self.column.name().unwrap_or("").to_string(),
expected: ColumnType::Float64,
found: self.column.column_type(),
}),
}
}
pub fn get_i64(&self, index: usize) -> Result<Option<i64>> {
match &self.column {
Column::Int64(col) => col.get(index),
_ => Err(Error::ColumnTypeMismatch {
name: self.column.name().unwrap_or("").to_string(),
expected: ColumnType::Int64,
found: self.column.column_type(),
}),
}
}
pub fn get_string(&self, index: usize) -> Result<Option<String>> {
match &self.column {
Column::String(col) => match col.get(index)? {
Some(s) => Ok(Some(s.to_string())),
None => Ok(None),
},
_ => Err(Error::ColumnTypeMismatch {
name: self.column.name().unwrap_or("").to_string(),
expected: ColumnType::String,
found: self.column.column_type(),
}),
}
}
pub fn get_bool(&self, index: usize) -> Result<Option<bool>> {
match &self.column {
Column::Boolean(col) => col.get(index),
_ => Err(Error::ColumnTypeMismatch {
name: self.column.name().unwrap_or("").to_string(),
expected: ColumnType::Boolean,
found: self.column.column_type(),
}),
}
}
}