graph LR
Compiler_Entry_Point["Compiler Entry Point"]
Query_Translator["Query Translator"]
Operator_Translator["Operator Translator"]
Function_Translator["Function Translator"]
Type_Construct_Converter["Type/Construct Converter"]
SQL_Tokenizer_AST_Representation["SQL Tokenizer/AST Representation"]
Aggregation_Pipeline_Builder["Aggregation Pipeline Builder"]
Compiler_Entry_Point -- "invokes" --> Query_Translator
Query_Translator -- "delegates to" --> Operator_Translator
Query_Translator -- "delegates to" --> Function_Translator
Query_Translator -- "delegates to" --> Type_Construct_Converter
Query_Translator -- "delegates to" --> Aggregation_Pipeline_Builder
Query_Translator -- "relies on" --> SQL_Tokenizer_AST_Representation
Operator_Translator -- "relies on" --> SQL_Tokenizer_AST_Representation
Function_Translator -- "relies on" --> SQL_Tokenizer_AST_Representation
Type_Construct_Converter -- "relies on" --> SQL_Tokenizer_AST_Representation
Aggregation_Pipeline_Builder -- "relies on" --> SQL_Tokenizer_AST_Representation
The SQL to MongoDB Query Compiler subsystem is the core translation engine within Djongo, responsible for converting SQL Abstract Syntax Trees (ASTs) into native MongoDB queries or aggregation pipelines. It embodies the Interpreter and Data Mapper patterns, translating high-level SQL constructs into low-level MongoDB operations.
Acts as the high-level interface for the Django ORM, receiving SQL query representations and initiating the compilation process. It orchestrates the overall translation by delegating to the core query translation logic.
Related Classes/Methods:
The central orchestrator of the SQL to MongoDB conversion. It parses incoming SQL statements, manages the overall query structure (including collection and field mapping), and dispatches specific translation tasks for different SQL operations (DML/DDL) to specialized sub-components. It constructs the final MongoDB query or aggregation pipeline.
Related Classes/Methods:
Translates SQL comparison and logical operators (e.g., =, LIKE, AND, OR) into their corresponding MongoDB query operators ($eq, $regex, $and, $or), handling precedence and negation.
Related Classes/Methods:
Converts SQL functions (e.g., COUNT, SUM, DateTrunc) into MongoDB aggregation expressions or query components, managing function aliases and field references.
Related Classes/Methods:
Handles specific data type conversions between SQL/Django and MongoDB types. It also translates certain SQL constructs (e.g., DISTINCT, LIMIT, OFFSET) into their MongoDB equivalents (e.g., $group, $limit, $skip), managing field lookups and _id conversions.
Related Classes/Methods:
Provides foundational classes and utilities for representing SQL tokens, statements, identifiers, and constants. This component is crucial for parsing SQL fragments and maintaining a structured representation of the SQL query during the translation process.
Related Classes/Methods:
Specializes in constructing complex MongoDB aggregation pipelines from SQL queries that require operations like GROUP BY, JOIN (simulated), or advanced data transformations.
Related Classes/Methods: