(cid: rq::CId, ctx: &mut Context)
| 779 | } |
| 780 | |
| 781 | pub(super) fn translate_select_item(cid: rq::CId, ctx: &mut Context) -> Result<SelectItem> { |
| 782 | let expr = translate_cid(cid, ctx)?.into_ast(); |
| 783 | |
| 784 | let inferred_name = match &expr { |
| 785 | // sql_ast::Expr::Identifier is used for s-strings |
| 786 | sql_ast::Expr::CompoundIdentifier(parts) => parts.last().map(|p| &p.value), |
| 787 | _ => None, |
| 788 | } |
| 789 | .filter(|n| *n != "*"); |
| 790 | |
| 791 | let expected = ctx.anchor.column_names.get(&cid); |
| 792 | |
| 793 | if inferred_name != expected { |
| 794 | // use expected name |
| 795 | let ident = expected.cloned().unwrap_or_else(|| { |
| 796 | // or use something that will not clash with other names |
| 797 | ctx.anchor.col_name.gen() |
| 798 | }); |
| 799 | ctx.anchor.column_names.insert(cid, ident.to_string()); |
| 800 | |
| 801 | return Ok(SelectItem::ExprWithAlias { |
| 802 | alias: translate_ident_part(ident, ctx), |
| 803 | expr, |
| 804 | }); |
| 805 | } |
| 806 | |
| 807 | Ok(SelectItem::UnnamedExpr(expr)) |
| 808 | } |
| 809 | |
| 810 | fn translate_windowed( |
| 811 | expr: ExprOrSource, |
no test coverage detected