fn normalize_field_access_after_subscript(
stmt: &mut Statement,
normalize_ident: bool,
)Expand description
Normalizes dot field accesses that follow a subscript for DataFusion.
sqlparser represents j.o.l[1].inner.l[2] as a compound field access with
the following access chain:
Dot(Identifier("o")),
Dot(Identifier("l")),
Subscript(1),
Dot(Identifier("inner")),
Dot(Identifier("l")),
Subscript(2)DataFusion first resolves the leading j.o.l through
JsonExprPlanner::plan_compound_identifier, which produces an untyped
json_get with path o.l. Before invoking JsonExprPlanner::plan_field_access,
however, DataFusion eagerly converts every remaining access into a
GetFieldAccess. It accepts string values but not [SqlExpr::Identifier]s
in [AccessExpr::Dot] after a subscript. Without this normalization, that
conversion fails at .inner, and plan_field_access is never called, even
for the preceding [1].
This function converts dot identifiers after the first subscript into
Dot(Value(SingleQuotedString(...))), applying DataFusion’s identifier
normalization before discarding whether each identifier was quoted. It
changes neither the SQL text nor the dot accesses into subscript nodes: the
resulting AST is conceptually j.o.l[1].'inner'.'l'[2]. DataFusion converts
the string-valued dot accesses into named field accesses, which
plan_field_access safely encodes as bracket members. It can then extend the
JSON path to o.l[1]["inner"]["l"][2].
This behavior is unchanged in the latest upstream releases checked here: DataFusion 55.0.0 and sqlparser 0.62.0.
TODO(LFC): Remove this workaround after upstream supports dot identifiers after subscripts.