Parse and Evaluate a VQL-Style WHERE Clause Over Records

Last updated: November 29, 2026

Quick Overview

Implement a tokenizer and recursive-descent parser for a small query filter language with field comparisons (=, !=, <, <=, >, >=), string and number literals, AND, OR, NOT and parentheses, then return the ids of records that match.

Veeva Systems
Coding & Algorithms
Software Engineer
Veeva Systems
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Implement a tokenizer and recursive-descent parser for a small query filter language with field comparisons (=, !=, <, <=, >, >=), string and number literals, AND, OR, NOT and parentheses, then return the ids of records that match.

Vault exposes VQL, an SQL-like query language over documents and objects, so platform engineers regularly reason about grammars, precedence and evaluation semantics. The interviewer checks operator precedence (NOT over AND over OR), clean separation of tokenizing, parsing and evaluation, and clear error handling for malformed input.

What the Interviewer Expects
  • Writes a grammar first with correct precedence: OR lowest, then AND, then NOT and atoms
  • Separates tokenizer, parser (producing an AST) and evaluator
  • Handles quoted strings with escapes and distinguishes keywords from field names
  • Raises clear syntax errors for incomplete or trailing input
  • Defines behavior for missing fields and type mismatches
  • Analyzes complexity as linear in query length plus query size times record count
Key Topics to Cover
recursive descent parsing
tokenization
operator precedence
abstract syntax tree
query languages
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you add IN ('a','b') and LIKE 'abc%' operators?
  • How would you push this filter down to a SQL database instead of evaluating in memory, without injection risk?
  • How would you add field-level security so a user cannot filter on fields they cannot see?
  • How would you implement SQL three-valued logic for NULL?
Sharpen Your Skills on Codemia

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

Practice DSA Problems
Sample Answer
Requirements

Input: a WHERE string such as status__v = 'approved' AND (major_version__v >= 2 OR type__v = 'Promo') and a list of record dicts. Output: ids of matching records. Precedence: NOT binds tightest, the...

High-Level Design

Grammar:

expr := term (OR term)* term := factor (AND factor)* factor := NOT factor | '(' expr ')' | field op literal

A regex tokenizer emits (kind, value) pairs; keywords are case-insensit...


Submit Your Answer
Markdown supported

Related Questions