Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(spans): Collapse constants in SQL select #2867

Merged
merged 3 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,12 @@ mod tests {
);

scrub_sql_test!(
select_with_nulls,
r#"SELECT foo, NULL, "bar", baz, NULL, NULL, zap FROM my_table"#,
"SELECT .. FROM my_table"
);

scrub_sql_test!(
fallback_hex,
r#"SELECT {ts '2023-12-24 23:59'}, 0x123456789AbCdEf"#,
"SELECT %s, %s"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ impl NormalizeVisitor {
Ident::new("..")
}

/// Check if a selected item can be erased into `..`. Currently we only collapse simple
/// columns (`col1` or `col1 AS foo`).
/// Check if a selected item can be erased into `..`.
/// We only collapse simple values (e.g. NULL) and columns (`col1` or `col1 AS foo`).
fn is_collapsible(item: &SelectItem) -> bool {
match item {
SelectItem::UnnamedExpr(expr) => {
matches!(expr, Expr::Identifier(_) | Expr::CompoundIdentifier(_))
}
SelectItem::ExprWithAlias { expr, .. } => {
matches!(expr, Expr::Identifier(_) | Expr::CompoundIdentifier(_))
SelectItem::UnnamedExpr(expr) | SelectItem::ExprWithAlias { expr, .. } => {
matches!(
expr,
Expr::Value(_) | Expr::Identifier(_) | Expr::CompoundIdentifier(_)
)
}
_ => false,
}
Expand Down
Loading