Skip to content

Conversation

@neema2
Copy link

@neema2 neema2 commented Jul 1, 2025

SQLGlot Integration for LegendQL

Integrates SQLGlot to parse SQL and map to LegendQL metamodel for Pure Relation code generation.

Overview

This PR adds SQLGlot integration to LegendQL, enabling conversion of SQL statements like SELECT colA, colB FROM tableC into Pure "Relation" code.

Key Features

  • SQLToLegendQLConverter class that parses SQL using SQLGlot and maps it to LegendQL metamodel
  • sql_to_pure_relation function for direct SQL to Pure Relation conversion
  • Support for basic SELECT statements with column selection
  • Integration with existing LegendQL database definitions and schema

Files Added/Modified

  • legendql/sql_parser.py - Main SQLGlot integration module
  • pyproject.toml - Added SQLGlot dependency (>=26.0.0)
  • test_sql_integration.py - Test script demonstrating the integration
  • legendql/__init__.py - Exposed new SQL functions in public API
  • legendql/sql_examples.py - Examples showing SQL to Pure Relation conversion

Example Usage

from legendql import sql_to_pure_relation

sql = "SELECT colA, colB FROM tableC"
pure_relation_code = sql_to_pure_relation(sql, db_def, database)

Link to Devin run: https://app.devin.ai/sessions/f39fbe1f08434260a8b2ec70646a14a1

Requested by: Neema Raphael (neema.raphael@gs.com)

- Add SQLToLegendQLConverter class to parse SQL using SQLGlot
- Map SQLGlot AST nodes to LegendQL metamodel classes
- Support basic SELECT statements with column selection
- Add sql_to_pure_relation convenience function
- Include test script and examples demonstrating functionality
- Add sqlglot dependency to pyproject.toml

Co-Authored-By: neema.raphael@gs.com <Neema.Raphael@gs.com>
@linux-foundation-easycla
Copy link

CLA Not Signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant