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
9 changes: 3 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ azure_storage_blobs = "0.20"
aws-sdk-s3 = "1"
aws-config = "1"

# LOCAL ONLY — DO NOT COMMIT — Zscaler blocks crates.io; fetch zerocopy from GitHub instead
[patch.crates-io]
zerocopy = { git = "https://github.com/google/zerocopy", tag = "v0.8.40" }
brotli = { git = "https://github.com/dropbox/rust-brotli", tag = "7.0.0" }

34 changes: 33 additions & 1 deletion src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@ pub async fn run_query(
sql: &str,
max_rows: usize,
) -> anyhow::Result<Vec<JsonValue>> {
let df = ctx.sql(sql).await.context("SQL query failed")?;
let df = ctx.sql(sql).await.map_err(|e| {
let detail = e.to_string();
if detail.contains("No field named") {
anyhow::anyhow!(
"SQL query failed: {detail}\n\
Hint: unquoted identifiers are lowercased by DataFusion — \
column names that are SQL reserved words or mixed-case must be \
double-quoted, e.g. SELECT \"ENDPERIOD\" instead of SELECT ENDPERIOD"
)
} else {
anyhow::anyhow!("SQL query failed: {detail}")
}
})?;
let limited = df
.limit(0, Some(max_rows))
.context("Failed to apply row limit")?;
Expand Down Expand Up @@ -84,6 +96,26 @@ mod tests {
assert!(res.is_err());
}

#[tokio::test]
async fn query_reserved_word_column_error_includes_hint() {
// Simulate a table with a reserved-word column name (lowercased by DataFusion).
// DataFusion lowercases unquoted identifiers, so referencing ENDPERIOD unquoted
// tries to find 'endperiod' which doesn't match the stored '"ENDPERIOD"'.
let ctx = SessionContext::new();
ctx.sql(r#"CREATE TABLE data AS SELECT * FROM (VALUES ('2024-01-01')) AS t("ENDPERIOD")"#)
.await
.unwrap()
.collect()
.await
.unwrap();
let err = run_query(&ctx, "SELECT MIN(ENDPERIOD) FROM data", 100)
.await
.unwrap_err();
let msg = err.to_string();
assert!(msg.contains("No field named"), "expected field error, got: {msg}");
assert!(msg.contains("double-quoted"), "expected quoting hint, got: {msg}");
}

#[tokio::test]
async fn head_returns_first_n_rows() {
let ctx = numeric_ctx().await;
Expand Down
Loading