Skip to content

Latest commit

 

History

History
93 lines (52 loc) · 5.08 KB

File metadata and controls

93 lines (52 loc) · 5.08 KB
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
Loading

CodeBoardingDemoContact

Details

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.

Compiler Entry Point

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:

Query Translator

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:

Operator Translator

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:

Function Translator

Converts SQL functions (e.g., COUNT, SUM, DateTrunc) into MongoDB aggregation expressions or query components, managing function aliases and field references.

Related Classes/Methods:

Type/Construct Converter

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:

SQL Tokenizer/AST Representation

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:

Aggregation Pipeline Builder

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: