fix: extrace field in case when (#4178)

This commit is contained in:
Huaijin
2024-08-12 10:39:07 +08:00
committed by GitHub
parent 9f94db2feb
commit dbd0f8487c
+12 -2
View File
@@ -882,8 +882,8 @@ fn get_field_name_from_expr(expr: &SqlExpr) -> Result<Option<Vec<String>>, anyho
SqlExpr::Case {
operand: _,
conditions,
results: _,
else_result: _,
results,
else_result,
} => {
let mut fields = Vec::new();
for expr in conditions.iter() {
@@ -891,6 +891,16 @@ fn get_field_name_from_expr(expr: &SqlExpr) -> Result<Option<Vec<String>>, anyho
fields.extend(v);
}
}
for expr in results.iter() {
if let Some(v) = get_field_name_from_expr(expr)? {
fields.extend(v);
}
}
if let Some(expr) = else_result.as_ref() {
if let Some(v) = get_field_name_from_expr(expr)? {
fields.extend(v);
}
}
Ok((!fields.is_empty()).then_some(fields))
}
SqlExpr::AtTimeZone { timestamp, .. } => get_field_name_from_expr(timestamp),