Skip to content

Commit

Permalink
Get QUERY_BATCH_SIZE at compile time
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelff committed Jan 18, 2024
1 parent 2314d76 commit 6903408
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions query-engine/connectors/sql-query-connector/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,29 @@ impl<'a> Context<'a> {
}
}

/// Overrides the default number of allowed elements in query's `IN` or `NOT IN`
/// statement for the currently loaded connector.
/// Certain databases error out if querying with too many items. For test
/// purposes, this value can be set with the `QUERY_BATCH_SIZE` environment
/// value to a smaller number.
#[cfg(not(target_arch = "wasm32"))]
fn get_batch_size(default: usize) -> Option<usize> {
use once_cell::sync::Lazy;

/// Overrides the default number of allowed elements in query's `IN` or `NOT IN`
/// statement for the currently loaded connector.
/// Certain databases error out if querying with too many items. For test
/// purposes, this value can be set with the `QUERY_BATCH_SIZE` environment
/// value to a smaller number.
static BATCH_SIZE_OVERRIDE: Lazy<Option<usize>> = Lazy::new(|| {
std::env::var("QUERY_BATCH_SIZE")
.ok()
.map(|size| size.parse().expect("QUERY_BATCH_SIZE: not a valid size"))
});

(*BATCH_SIZE_OVERRIDE).or(Some(default))
}

/// In WASM there's no runtime environment, so we can't read the QUERY_BATCH_SIZE var at runtime.
/// In tests however we depend on that var being set, but we can get away with a build-time override
#[cfg(target_arch = "wasm32")]
fn get_batch_size(default: usize) -> Option<usize> {
option_env!("QUERY_BATCH_SIZE")
.map(|size| size.parse().expect("QUERY_BATCH_SIZE: not a valid size"))
.or(Some(default))
}

0 comments on commit 6903408

Please sign in to comment.