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
2 changes: 1 addition & 1 deletion litellm-rust/crates/storage-clickhouse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod read;

pub use error::Error;
pub use insert::{insert_compressed_rows, insert_encoded_rows};
pub use read::{Parameter, Query, execute_read, fetch, fetch_json};
pub use read::{Parameter, Query, READ_LIMITS, ReadLimits, execute_read, fetch, fetch_json};
use url::Url;

#[derive(Clone)]
Expand Down
22 changes: 18 additions & 4 deletions litellm-rust/crates/storage-clickhouse/src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@ use serde::{Deserialize, Serialize, de::DeserializeOwned};

use crate::{Connection, Error};

const MAX_RESPONSE_BYTES: usize = 4 * 1024 * 1024;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ReadLimits {
pub result_rows: u64,
pub response_bytes: usize,
pub execution_seconds: u64,
}

pub const READ_LIMITS: ReadLimits = ReadLimits {
result_rows: 1000,
response_bytes: 4 * 1024 * 1024,
execution_seconds: 10,
};

#[derive(Debug, Deserialize, Serialize)]
#[serde(untagged)]
Expand Down Expand Up @@ -78,9 +89,12 @@ pub async fn execute_read(
.clear()
.extend_pairs(existing_pairs)
.append_pair("readonly", "1")
.append_pair("max_result_rows", "1000")
.append_pair("max_result_rows", &READ_LIMITS.result_rows.to_string())
.append_pair("result_overflow_mode", "throw")
.append_pair("max_execution_time", "10")
.append_pair(
"max_execution_time",
&READ_LIMITS.execution_seconds.to_string(),
)
.append_pair("wait_end_of_query", "1")
.append_pair("default_format", "JSON");

Expand All @@ -101,7 +115,7 @@ pub async fn execute_read(

let mut body = Vec::new();
while let Some(chunk) = response.chunk().await.map_err(|_| Error::Transport)? {
if body.len() + chunk.len() > MAX_RESPONSE_BYTES {
if body.len() + chunk.len() > READ_LIMITS.response_bytes {
return Err(Error::ResponseTooLarge);
}
body.extend_from_slice(&chunk);
Expand Down
2 changes: 1 addition & 1 deletion litellm-rust/crates/traces-clickhouse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use error::Error;
pub use insert::{InsertRow, InsertTable, encode_rows, insert_rows, insert_shared_rows};
pub use litellm_storage_clickhouse::{Connection, Parameter};
pub use litellm_traces::{QueryScope, ReadQuery};
pub use query::{execute_read, query_help, query_sql};
pub use query::{QueryHelp, execute_read, query_help, query_sql};
pub use query_access::QueryReaders;
pub use schema::{
NORMALIZED_FIELD_DEFINITIONS, NormalizedFieldDefinition, ensure_schema, schema_statements,
Expand Down
Loading
Loading