Skip to content

Commit

Permalink
compat fix tui 0.27, fix modified int64 error on filelist, enforce er…
Browse files Browse the repository at this point in the history
…ror-check
  • Loading branch information
aprxi committed Aug 2, 2024
1 parent 8055dd1 commit 2043b8d
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lumni/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ tokio = { version = "1.12", default-features = false, features = ["rt-multi-thre
# tokio = { version = "1.12", default-features = false, features = ["full"], optional = true }
clap = { version = "4.2" , default-features = false, features = ["std", "help"], optional = true }
crossterm = { version = "0.27", optional = true }
ratatui = { version = ">=0.26.0, <1", default-features = false, features = ["crossterm"], optional = true }
ratatui = { version = ">=0.27.0, <1", default-features = false, features = ["crossterm"], optional = true }
arboard = { version = "3.2", default-features = false, optional = true }

# WEB
Expand Down
2 changes: 1 addition & 1 deletion lumni/src/apps/builtin/llm/prompt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env_logger = { version = "0.9" }
tokio = { version = "1.12", default-features = false, features = ["rt-multi-thread", "macros"] }
clap = { version = "4.2" , default-features = false, features = ["std", "help"] }
crossterm = { version = "0.27" }
ratatui = { version = ">=0.26.0, <1", default-features = false, features = ["crossterm"] }
ratatui = { version = ">=0.27.0, <1", default-features = false, features = ["crossterm"] }
arboard = { version = "3.2", default-features = false }

lumni = { git = "https://github.com/serverlessnext/lumni", branch = "main" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl<'a> ConversationListModal<'a> {
.begin_symbol(None)
.end_symbol(None);

let scrollbar_area = area.inner(&Margin {
let scrollbar_area = area.inner(Margin {
vertical: 1,
horizontal: 0,
});
Expand Down
1 change: 0 additions & 1 deletion lumni/src/handlers/object_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ impl ObjectStoreHandler {
parsed_uri.scheme.to_string(),
parsed_uri.bucket.as_ref().unwrap()
);

let object_store = ObjectStore::new(&bucket_uri, config).unwrap();
object_store
.list_files(
Expand Down
2 changes: 1 addition & 1 deletion lumni/src/localfs/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl ObjectStoreTrait for LocalFsBucket {
filter,
table,
)
.await;
.await?;
Ok(())
}

Expand Down
9 changes: 4 additions & 5 deletions lumni/src/localfs/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crossbeam_channel::{bounded, Sender};
use rayon::prelude::*;

use crate::table::{FileObjectTable, TableColumnValue};
use crate::{FileObject, FileObjectFilter};
use crate::{FileObject, FileObjectFilter, InternalError};

pub async fn list_files(
path: &Path,
Expand All @@ -18,13 +18,12 @@ pub async fn list_files(
recursive: bool,
filter: &Option<FileObjectFilter>,
table: &mut FileObjectTable,
) {
) -> Result<(), InternalError> {
if let Some(columns) = selected_columns {
println!("Selected columns: {:?}", columns);
}

let max_count = max_keys.map(|m| m as usize).unwrap_or(usize::MAX);
//let count = AtomicUsize::new(0);
let count = Arc::new(AtomicUsize::new(0));
let (sender, receiver) = bounded(500);

Expand Down Expand Up @@ -60,8 +59,9 @@ pub async fn list_files(

// Batch insert all rows at once
if !rows.is_empty() {
let _ = table.add_rows(rows).await;
table.add_rows(rows).await?;
}
Ok(())
}

fn process_directory(
Expand Down Expand Up @@ -129,7 +129,6 @@ fn process_entry(
selected_columns: &Option<Vec<&str>>,
) -> Option<HashMap<String, TableColumnValue>> {
let metadata = entry.metadata().ok()?;

if metadata.is_file() {
handle_file(entry, filter, selected_columns)
} else if metadata.is_dir() && filter.is_none() {
Expand Down
7 changes: 6 additions & 1 deletion lumni/src/table/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ macro_rules! create_column_types {

create_column_types!(Int32Column, OptionalInt32Column, i32);
create_column_types!(Uint64Column, OptionalUint64Column, u64);
create_column_types!(Int64Column, OptionalInt64Column, i64);
create_column_types!(FloatColumn, OptionalFloatColumn, f64);
create_column_types!(StringColumn, OptionalStringColumn, String);

Expand All @@ -108,10 +109,14 @@ impl TableColumnValue {
TableColumnValue::OptionalUint64Column(Some(val)) => {
val.to_string()
}
TableColumnValue::OptionalInt64Column(Some(val)) => val.to_string(),
TableColumnValue::OptionalFloatColumn(Some(val)) => val.to_string(),
TableColumnValue::OptionalStringColumn(Some(val)) => val.clone(),
// Match any None variant for Optional types
_ => "NULL".to_string(),
_ => {
log::error!("Unexpected TableColumnValue: {:?}", self);
"NULL".to_string()
}
}
}
}
25 changes: 13 additions & 12 deletions lumni/src/table/file_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::collections::HashMap;
use std::sync::Arc;

use crate::table::{
OptionalUint64Column, StringColumn, TableRow, Uint64Column,
OptionalInt64Column, StringColumn, TableRow, Uint64Column,
};
use crate::utils::formatters::{bytes_human_readable, time_human_readable};
use crate::{FileObject, Table, TableCallback, TableColumn, TableColumnValue};
use crate::{FileObject, InternalError, Table, TableCallback, TableColumn, TableColumnValue};

pub struct FileObjectTable {
columns: Vec<(String, Box<dyn TableColumn>)>, // Store columns in order
Expand Down Expand Up @@ -37,7 +37,7 @@ impl FileObjectTable {
.add_column("size", Box::new(Uint64Column(Vec::new()))),
"modified" => table.add_column(
"modified",
Box::new(OptionalUint64Column(Vec::new())),
Box::new(OptionalInt64Column(Vec::new())),
),
_ => panic!("Invalid column name: {}", column),
}
Expand All @@ -52,7 +52,7 @@ impl FileObjectTable {
.add_column("size", Box::new(Uint64Column(Vec::new()))),
"modified" => table.add_column(
"modified",
Box::new(OptionalUint64Column(Vec::new())),
Box::new(OptionalInt64Column(Vec::new())),
),
// should not be reachable because valid_columns is hardcoded
_ => panic!("Invalid column name: {}", column),
Expand Down Expand Up @@ -87,7 +87,7 @@ impl Table for FileObjectTable {
fn add_row(
&mut self,
row_data: Vec<(String, TableColumnValue)>,
) -> Result<(), String> {
) -> Result<(), InternalError> {
if let Some(callback) = &self.callback {
let mut row = TableRow::new(row_data.clone(), Some(&print_row));
callback.on_row_add(&mut row);
Expand All @@ -98,10 +98,12 @@ impl Table for FileObjectTable {
let (_, column) = &mut self.columns[index];
column.append(value)?;
} else {
return Err(format!("Column '{}' not found", column_name));
return Err(InternalError::InternalError(format!(
"Column '{}' not found",
column_name
)));
}
}

Ok(())
}

Expand Down Expand Up @@ -182,10 +184,9 @@ impl FileObjectTable {
pub async fn add_file_objects(
&mut self,
file_objects: Vec<FileObject>,
) -> Result<(), String> {
) -> Result<(), InternalError> {
for file_object in file_objects {
let mut row_data: Vec<(String, TableColumnValue)> = Vec::new();

for (column_name, _) in &self.columns {
if let Some(value) =
file_object.get_value_by_column_name(column_name)
Expand All @@ -205,10 +206,10 @@ impl FileObjectTable {
pub async fn add_rows(
&mut self,
rows: Vec<HashMap<String, TableColumnValue>>,
) -> Result<(), String> {
for row_data in rows {
let mut row_vec: Vec<(String, TableColumnValue)> = Vec::new();
) -> Result<(), InternalError> {

for row_data in rows.iter() {
let mut row_vec: Vec<(String, TableColumnValue)> = Vec::new();
// Iterate over self.columns to maintain the defined order
for (column_name, _) in &self.columns {
if let Some(value) = row_data.get(column_name) {
Expand Down
4 changes: 3 additions & 1 deletion lumni/src/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub use columns::*;
pub use file_object::FileObjectTable;
pub use object_store::ObjectStoreTable;

use crate::InternalError;

pub struct TableRow<'a> {
data: Vec<(String, TableColumnValue)>,
print_fn: Option<&'a (dyn Fn(&TableRow) + 'a)>,
Expand Down Expand Up @@ -86,6 +88,6 @@ pub trait Table: Debug {
fn add_row(
&mut self,
row_data: Vec<(String, TableColumnValue)>,
) -> Result<(), String>;
) -> Result<(), InternalError>;
fn fmt_debug(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result;
}
9 changes: 6 additions & 3 deletions lumni/src/table/object_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Table for ObjectStoreTable {
fn add_row(
&mut self,
row_data: Vec<(String, TableColumnValue)>,
) -> Result<(), String> {
) -> Result<(), InternalError> {
if let Some(callback) = &self.callback {
let mut row = TableRow::new(row_data.clone(), Some(&print_row));
callback.on_row_add(&mut row);
Expand All @@ -83,7 +83,10 @@ impl Table for ObjectStoreTable {
{
column.append(value)?;
} else {
return Err(format!("Column '{}' not found", column_name));
return Err(InternalError::InternalError(format!(
"Column {} not found in table",
column_name
)));
}
}

Expand All @@ -109,7 +112,7 @@ impl ObjectStoreTable {
pub async fn add_object_store(
&mut self,
object_store: ObjectStore,
) -> Result<(), String> {
) -> Result<(), InternalError> {
let row_data = vec![(
"uri".to_string(),
TableColumnValue::StringColumn(object_store.uri()),
Expand Down

0 comments on commit 2043b8d

Please sign in to comment.