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.
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
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- 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 ProblemsSample Answer
Requirements
- Comparisons:
=, !=, <, <=, >, >=between a field path and a literal (number, quoted string,true/false). - Boolean ops
AND,OR,NOT, parentheses;ANDbinds tighter thanOR. - 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...