MCPcopy Create free account
hub / github.com/apache/datafusion / ambiguous_distinct_check

Method ambiguous_distinct_check

datafusion/expr/src/logical_plan/builder.rs:755–792  ·  view source on GitHub ↗
(
        missing_exprs: &[Expr],
        missing_cols: &IndexSet<Column>,
        projection_exprs: &[Expr],
    )

Source from the content-addressed store, hash-verified

753 }
754
755 fn ambiguous_distinct_check(
756 missing_exprs: &[Expr],
757 missing_cols: &IndexSet<Column>,
758 projection_exprs: &[Expr],
759 ) -> Result<()> {
760 if missing_exprs.is_empty() {
761 return Ok(());
762 }
763
764 // if the missing columns are all only aliases for things in
765 // the existing select list, it is ok
766 //
767 // This handles the special case for
768 // SELECT col as <alias> ORDER BY <alias>
769 //
770 // As described in https://github.com/apache/datafusion/issues/5293
771 let all_aliases = missing_exprs.iter().all(|e| {
772 projection_exprs.iter().any(|proj_expr| {
773 if let Expr::Alias(Alias { expr, .. }) = proj_expr {
774 e == expr.as_ref()
775 } else {
776 false
777 }
778 })
779 });
780 if all_aliases {
781 return Ok(());
782 }
783
784 let missing_col_names = missing_cols
785 .iter()
786 .map(|col| col.flat_name())
787 .collect::<String>();
788
789 plan_err!(
790 "For SELECT DISTINCT, ORDER BY expressions {missing_col_names} must appear in select list"
791 )
792 }
793
794 /// Apply a sort by provided expressions with default direction
795 pub fn sort_by(

Callers

nothing calls this directly

Calls 7

allMethod · 0.80
flat_nameMethod · 0.80
is_emptyMethod · 0.45
iterMethod · 0.45
anyMethod · 0.45
as_refMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected