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

Method sql_compound_field_access_to_expr

datafusion/sql/src/expr/mod.rs:1128–1249  ·  view source on GitHub ↗
(
        &self,
        root: SQLExpr,
        access_chain: Vec<AccessExpr>,
        schema: &DFSchema,
        planner_context: &mut PlannerContext,
    )

Source from the content-addressed store, hash-verified

1126 }
1127
1128 fn sql_compound_field_access_to_expr(
1129 &self,
1130 root: SQLExpr,
1131 access_chain: Vec<AccessExpr>,
1132 schema: &DFSchema,
1133 planner_context: &mut PlannerContext,
1134 ) -> Result<Expr> {
1135 let (root, access_chain) = self.extract_root_and_access_chain(
1136 root,
1137 access_chain,
1138 schema,
1139 planner_context,
1140 )?;
1141 let fields = access_chain
1142 .into_iter()
1143 .map(|field| match field {
1144 AccessExpr::Subscript(subscript) => {
1145 match subscript {
1146 Subscript::Index { index } => {
1147 // index can be a name, in which case it is a named field access
1148 match index {
1149 SQLExpr::Value(ValueWithSpan {
1150 value:
1151 Value::SingleQuotedString(s)
1152 | Value::DoubleQuotedString(s),
1153 span: _,
1154 }) => Ok(Some(GetFieldAccess::NamedStructField {
1155 name: ScalarValue::from(s),
1156 })),
1157 SQLExpr::JsonAccess { .. } => {
1158 not_impl_err!("JsonAccess")
1159 }
1160 // otherwise treat like a list index
1161 _ => Ok(Some(GetFieldAccess::ListIndex {
1162 key: Box::new(self.sql_expr_to_logical_expr(
1163 index,
1164 schema,
1165 planner_context,
1166 )?),
1167 })),
1168 }
1169 }
1170 Subscript::Slice {
1171 lower_bound,
1172 upper_bound,
1173 stride,
1174 } => {
1175 // Means access like [:2]
1176 let lower_bound = if let Some(lower_bound) = lower_bound {
1177 self.sql_expr_to_logical_expr(
1178 lower_bound,
1179 schema,
1180 planner_context,
1181 )
1182 } else {
1183 not_impl_err!("Slice subscript requires a lower bound")
1184 }?;
1185

Callers 1

Calls 9

newFunction · 0.85
flattenMethod · 0.80
litFunction · 0.50
mapMethod · 0.45
into_iterMethod · 0.45
get_expr_plannersMethod · 0.45
plan_field_accessMethod · 0.45

Tested by

no test coverage detected