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

Method sql_identifier_to_expr

datafusion/sql/src/expr/identifier.rs:34–114  ·  view source on GitHub ↗
(
        &self,
        id: Ident,
        schema: &DFSchema,
        planner_context: &mut PlannerContext,
    )

Source from the content-addressed store, hash-verified

32
33impl<S: ContextProvider> SqlToRel<'_, S> {
34 pub(super) fn sql_identifier_to_expr(
35 &self,
36 id: Ident,
37 schema: &DFSchema,
38 planner_context: &mut PlannerContext,
39 ) -> Result<Expr> {
40 let id_span = id.span;
41 if id.value.starts_with('@') && id.quote_style.is_none() {
42 // TODO: figure out if ScalarVariables should be insensitive.
43 let var_names = vec![id.value];
44 let field = self
45 .context_provider
46 .get_variable_field(&var_names)
47 .or_else(|| {
48 self.context_provider
49 .get_variable_type(&var_names)
50 .map(|ty| ty.into_nullable_field_ref())
51 })
52 .ok_or_else(|| {
53 plan_datafusion_err!("variable {var_names:?} has no type information")
54 })?;
55 Ok(Expr::ScalarVariable(field, var_names))
56 } else {
57 // Don't use `col()` here because it will try to
58 // interpret names with '.' as if they were
59 // compound identifiers, but this is not a compound
60 // identifier. (e.g. it is "foo.bar" not foo.bar)
61 let normalize_ident = self.ident_normalizer.normalize(id);
62
63 // lambdas parameters have higher precedence
64 if let Some(field) = planner_context.lambda_parameters().get(&normalize_ident)
65 {
66 let mut lambda_var =
67 LambdaVariable::new(normalize_ident, Some(Arc::clone(field)));
68 if self.options.collect_spans
69 && let Some(span) = Span::try_from_sqlparser_span(id_span)
70 {
71 lambda_var.spans_mut().add_span(span);
72 }
73 return Ok(Expr::LambdaVariable(lambda_var));
74 }
75
76 // Check for qualified field with unqualified name
77 if let Ok((qualifier, _)) =
78 schema.qualified_field_with_unqualified_name(normalize_ident.as_str())
79 {
80 let mut column = Column::new(
81 qualifier.filter(|q| q.table() != UNNAMED_TABLE).cloned(),
82 normalize_ident,
83 );
84 if self.options.collect_spans
85 && let Some(span) = Span::try_from_sqlparser_span(id_span)
86 {
87 column.spans_mut().add_span(span);
88 }
89 return Ok(Expr::Column(column));
90 }
91

Calls 15

newFunction · 0.85
is_noneMethod · 0.80
get_variable_fieldMethod · 0.80
add_spanMethod · 0.80
outer_schemas_iterMethod · 0.80
LambdaVariableClass · 0.50
ColumnClass · 0.50
mapMethod · 0.45
get_variable_typeMethod · 0.45
normalizeMethod · 0.45

Tested by

no test coverage detected