Design and Implement a Mini SQL Query Engine
Design and Implement a Mini SQL Query Engine
You are tasked with designing and implementing a simplified SQL query engine. The engine will operate on in-memory tables, each defined by a schema (column names and types) and containing a collection of rows. The engine should accept a SQL query string, execute it against the provided tables, and return the result set.
The exercise emphasizes scoping: start with a basic subset of SQL and be prepared to extend it based on interviewer-defined features. The goal is to design for extensibility, allowing new clauses to be integrated cleanly.
Constraints & Assumptions:
- Tables are fully in memory. Data fits within memory constraints.
- Focus on read-only
SELECTqueries. Transactions, persistence, and writes are out of scope for the base version. - v1 Target:
SELECT <columns> FROM <table> WHERE <predicate>.- Predicates support comparison operators (
=,!=,<,<=,>,>=). - Predicates support logical operators (
AND,OR).
- Predicates support comparison operators (
- Potential Extensions:
ORDER BY+LIMIT, aggregate functions (COUNT,SUM,AVG,MIN,MAX) withGROUP BY, andINNER JOINof two tables. - Keywords can be treated case-insensitively. Assume a simplified, well-formed grammar unless schema validation is explicitly requested.
Phased Implementation:
- Architecture: Outline the engine's stages, component boundaries, and how future features like JOIN and GROUP BY would integrate.
- Core Implementation: Parse and execute the base
SELECT ... FROM ... WHERE ...query, including predicate logic. - Extensions: Implement
ORDER BY+LIMIT, aggregate functions withGROUP BY, andINNER JOIN.
AI interview prep
Core dilemma
Balancing the complexity of parsing and executing a declarative query language against the need for a clean, extensible architecture that can accommodate future SQL features without significant refactoring.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Design and Implement a Mini SQL Query Engine
Design and Implement a Mini SQL Query Engine
You are tasked with designing and implementing a simplified SQL query engine. The engine will operate on in-memory tables, each defined by a schema (column names and types) and containing a collection of rows. The engine should accept a SQL query string, execute it against the provided tables, and return the result set.
The exercise emphasizes scoping: start with a basic subset of SQL and be prepared to extend it based on interviewer-defined features. The goal is to design for extensibility, allowing new clauses to be integrated cleanly.
Constraints & Assumptions:
- Tables are fully in memory. Data fits within memory constraints.
- Focus on read-only
SELECTqueries. Transactions, persistence, and writes are out of scope for the base version. - v1 Target:
SELECT <columns> FROM <table> WHERE <predicate>.- Predicates support comparison operators (
=,!=,<,<=,>,>=). - Predicates support logical operators (
AND,OR).
- Predicates support comparison operators (
- Potential Extensions:
ORDER BY+LIMIT, aggregate functions (COUNT,SUM,AVG,MIN,MAX) withGROUP BY, andINNER JOINof two tables. - Keywords can be treated case-insensitively. Assume a simplified, well-formed grammar unless schema validation is explicitly requested.
Phased Implementation:
- Architecture: Outline the engine's stages, component boundaries, and how future features like JOIN and GROUP BY would integrate.
- Core Implementation: Parse and execute the base
SELECT ... FROM ... WHERE ...query, including predicate logic. - Extensions: Implement
ORDER BY+LIMIT, aggregate functions withGROUP BY, andINNER JOIN.