MCPcopy Create free account
hub / github.com/PRQL/prql / translate_select_item

Function translate_select_item

prqlc/prqlc/src/sql/gen_expr.rs:781–808  ·  view source on GitHub ↗
(cid: rq::CId, ctx: &mut Context)

Source from the content-addressed store, hash-verified

779}
780
781pub(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
810fn translate_windowed(
811 expr: ExprOrSource,

Callers 1

translate_select_itemsFunction · 0.85

Calls 7

translate_cidFunction · 0.85
translate_ident_partFunction · 0.85
into_astMethod · 0.80
mapMethod · 0.80
genMethod · 0.80
getMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected