Evaluate a List Filter Expression for a Cloud Resources API

Last updated: November 29, 2026

Quick Overview

Implement the filter parameter of a list method: parse expressions like 'size > 100 AND (type = "pdf" OR starred)' into an AST and evaluate them against resource dicts, with AND binding tighter than OR and NOT supported.

Google
Software Engineering Fundamentals
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Hard

0

0

0 solved


Implement the filter parameter of a list method: parse expressions like 'size > 100 AND (type = "pdf" OR starred)' into an AST and evaluate them against resource dicts, with AND binding tighter than OR and NOT supported.

Google APIs accept a filter string on list methods, and teams implement the grammar themselves. Onsite interviewers use it to see a clean tokenizer, a recursive descent parser with correct precedence, and good error messages rather than eval or regex hacks.

What the Interviewer Expects
  • Write a tokenizer that handles quoted strings, numbers, identifiers and operators
  • Use recursive descent with OR < AND < NOT < comparison precedence
  • Build an AST once and evaluate it per resource
  • Report syntax errors with a position
  • Treat a bare identifier as a truthiness test
Key Topics to Cover
recursive descent parsing
tokenizer
operator precedence
AIP-160
AST evaluation
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you push this filter down into a SQL or Spanner query?
  • How would you support the has operator ':' for repeated fields?
  • How do you stop a malicious filter from being too expensive?
  • How would you handle type mismatches like size = "abc"?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements
  • Comparisons: =, !=, <, <=, >, >= between a field path and a literal (number, quoted string, true/false).
  • Boolean ops AND, OR, NOT, parentheses; AND binds tighter than OR.
  • Bare fi...
High-Level Design

Grammar:

expr := term (OR term)* term := factor (AND factor)* factor := NOT factor | '(' expr ')' | cmp cmp := IDENT (OP literal)?

The tokenizer is one regex with named groups that wa...


Submit Your Answer
Markdown supported