Parsing utilities to validate and split SQL statements for CrateDB.
Project description
CrateDB SQL Parser for Python
This package provides utilities to validate and split SQL statements specifically designed for CrateDB.
It is built upon CrateDB's antlr4 grammar, ensuring accurate parsing tailored to CrateDB's SQL dialect.
It draws inspiration from sqlparse
.
Installation.
Usage:
from cratedb_sqlparse import sqlparse
query = """
SELECT * FROM SYS.SHARDS;
INSERT INTO doc.tbl VALUES (1);
"""
statements = sqlparse(query)
print(len(statements))
# 2
select_query = statements[0]
print(select_query.query)
# 'SELECT * FROM SYS.SHARDS'
print(select_query.type)
# 'SELECT'
print(select_query.tree)
# (statement (query (queryNoWith (queryTerm (querySpec SELECT (selectItem *) FROM (relation (aliasedRelation (relationPrimary (table (qname (ident (unquotedIdent SYS)) . (ident (unquotedIdent (nonReserved SHARDS)))))))))))))
sqlparse('SUUULECT * FROM sys.shards')
# cratedb_sqlparse.parser.parser.ParsingException: line1:0 mismatched input 'SUUULECT' expecting {'SELECT', 'DEALLOCATE', ...}
Development
git clone https://github.com/crate/cratedb-sqlparse
cd cratedb-sqlparse/cratedb_sqlparse_py
python3 -m venv .venv
source .venv/bin/activate
pip install --editable='.[develop,generate,release,test]'
poe check
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
cratedb_sqlparse-0.0.2.tar.gz
(119.5 kB
view hashes)
Built Distribution
Close
Hashes for cratedb_sqlparse-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5106d66b91656de5d778c8479462e0010d35ca44d990ce0f75862d3621071d3e |
|
MD5 | 17c3f1a4193af2b3a7977b13bc2c0c48 |
|
BLAKE2b-256 | 291ec6fa83205dd4f86305f34fdee560eb66a5b8381b2702b45f20a2e45628a5 |