@@ -103,6 +103,17 @@ class ProtoToPredicateBuilder final : private ExprFactory {
103103 }
104104 return e;
105105 }
106+
107+ // Returns either the path specified by the "match_path" annotation,
108+ // or the default path derived from the field name.
109+ Expr GetFieldPath (const Expr& base_expr,
110+ const ::google::protobuf::FieldDescriptor* field) {
111+ std::string match_path_val = GetMatchPath (field);
112+ if (!match_path_val.empty ()) {
113+ return ParseAndBuildPath (match_path_val);
114+ }
115+ return NewSelect (NextId (), base_expr, field->name ());
116+ }
106117 ExprId NextId () { return id_++; }
107118
108119 // ---------------------------------------------------------------------------
@@ -246,7 +257,7 @@ class ProtoToPredicateBuilder final : private ExprFactory {
246257 const FieldDescriptor* const value_field =
247258 field->message_type ()->FindFieldByName (" value" );
248259
249- Expr map_path = NewSelect ( NextId (), base_expr, field-> name () );
260+ Expr map_path = GetFieldPath ( base_expr, field);
250261
251262 struct MapEntry {
252263 const Message* message;
@@ -355,7 +366,7 @@ class ProtoToPredicateBuilder final : private ExprFactory {
355366 const Message& sub_message =
356367 reflection->GetRepeatedMessage (message, field, i);
357368 std::vector<Expr> sub_predicates;
358- Expr sub_base = NewSelect ( NextId (), base_expr, field-> name () );
369+ Expr sub_base = GetFieldPath ( base_expr, field);
359370 CEL_RETURN_IF_ERROR (Walk (sub_message, sub_base, sub_predicates));
360371 message_asts.push_back (LogicalAnd (sub_predicates));
361372 }
@@ -426,11 +437,11 @@ class ProtoToPredicateBuilder final : private ExprFactory {
426437 }
427438 } else if (field->cpp_type () == FieldDescriptor::CPPTYPE_MESSAGE ) {
428439 const Message& sub_message = reflection->GetMessage (message, field);
429- Expr field_path = NewSelect ( NextId (), base_expr, field-> name () );
440+ Expr field_path = GetFieldPath ( base_expr, field);
430441 CEL_RETURN_IF_ERROR (Walk (sub_message, field_path, predicates));
431442 } else {
432443 // Primitive field: base_expr.field == <value>
433- Expr field_path = NewSelect ( NextId (), base_expr, field-> name () );
444+ Expr field_path = GetFieldPath ( base_expr, field);
434445 predicates.push_back (
435446 ConstructEquality (std::move (field_path),
436447 PrimitiveToExpr (message, reflection, field)));
0 commit comments