Skip to main content

A sql parser which support mysql, oceanbase and odps

Project description

sqlgpt-parser

sqlgpt-parser is a Python implementation of an SQL parser that effectively converts SQL statements into Abstract Syntax Trees (AST). By leveraging AST tree comparisons between two SQL queries, it becomes possible to achieve robust evaluation of text-to-SQL models.

Quick Start

Install

pip install sqlgpt-parser

Parser SQL

>> > from sqlgpt_parser.parser.mysql_parser import parser as mysql_parser
>> > mysql_parser.parse("select * from t")
Query(query_body=QuerySpecification(select=Select(distinct=False, select_items=[
    SingleColumn(expression=QualifiedNameReference(name=QualifiedName.of("*")))]),
                                    from_=Table(name=QualifiedName.of("t"), for_update=False), order_by=[], limit=0,
                                    offset=0, for_update=False, nowait_or_wait=False), order_by=[], limit=0, offset=0)
>> > from sqlgpt_parser.parser.oceanbase_parser import parser as oceanbase_parser
>> > oceanbase_parser.parse("select * from t")
Query(query_body=QuerySpecification(select=Select(distinct=False, select_items=[
    SingleColumn(expression=QualifiedNameReference(name=QualifiedName.of("*")))]),
                                    from_=Table(name=QualifiedName.of("t"), for_update=False), order_by=[], limit=0,
                                    offset=0, for_update=False, nowait_or_wait=False), order_by=[], limit=0, offset=0)
>> > from sqlgpt_parser.parser.odps_parser import parser as odps_parser
>> > odps_parser.parse("select * from t")
Query(query_body=QuerySpecification(select=Select(distinct=False, select_items=[
    SingleColumn(expression=QualifiedNameReference(name=QualifiedName.of("*")))]),
                                    from_=Table(name=QualifiedName.of("t"), for_update=False), order_by=[], limit=0,
                                    offset=0, for_update=False, nowait_or_wait=False), order_by=[], limit=0, offset=0)

Format SQL

>>> from sqlgpt_parser.format.formatter import format_sql
>>> from sqlgpt_parser.mysql_parser import parser
>>> result=parser.parse("select * from t")
>>> format_sql(result)
'SELECT\n  *\nFROM\n  t'

Getting Started with SQL Parser Development

English Document: SQL Parser Development Guide

中文文档:SQL Parser 开发指南

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlgpt_parser-0.0.1a3.tar.gz (2.5 MB view details)

Uploaded Source

Built Distribution

sqlgpt_parser-0.0.1a3-py3-none-any.whl (2.7 MB view details)

Uploaded Python 3

File details

Details for the file sqlgpt_parser-0.0.1a3.tar.gz.

File metadata

  • Download URL: sqlgpt_parser-0.0.1a3.tar.gz
  • Upload date:
  • Size: 2.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for sqlgpt_parser-0.0.1a3.tar.gz
Algorithm Hash digest
SHA256 a5d9d66ff711ad595a596595fe6430f564a7df3da1d9bd8530f240de0d706ecd
MD5 12b180796908923f6654f180076e18cf
BLAKE2b-256 dc6d087fb45296a71459798df30aa7bc1c145ff4ebc6a35c90b42d45a3f236ce

See more details on using hashes here.

File details

Details for the file sqlgpt_parser-0.0.1a3-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlgpt_parser-0.0.1a3-py3-none-any.whl
Algorithm Hash digest
SHA256 e76dc18ca20b7c3f6433239adfadc2342da945b79c7d950b64fd3dd76b1b7089
MD5 9941fea1e2ccef6313ca56f9300f1103
BLAKE2b-256 39308b0668ddcea1b7c6e3ad24f15c7c2a4c5e1d8ac51f5b9b79b863b7e95929

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page