All Projects → ballista-compute → Sqlparser Rs

ballista-compute / Sqlparser Rs

Licence: apache-2.0
Extensible SQL Lexer and Parser for Rust

Programming Languages

rust
11053 projects

Labels

Projects that are alternatives of or similar to Sqlparser Rs

Sql Parser
A validating SQL lexer and parser with a focus on MySQL dialect.
Stars: ✭ 284 (-53.21%)
Mutual labels:  sql, parser
Sqlformat
.NET SQL Parser and Formatter Tool and SSMS Plugin
Stars: ✭ 49 (-91.93%)
Mutual labels:  sql, parser
Imdbpy
IMDbPY is a Python package useful to retrieve and manage the data of the IMDb movie database about movies, people, characters and companies
Stars: ✭ 792 (+30.48%)
Mutual labels:  sql, parser
Flora Sql Parser
Parse SQL (select) statements into abstract syntax tree (AST) and convert ASTs back to SQL.
Stars: ✭ 186 (-69.36%)
Mutual labels:  sql, parser
Sqlparser
Simple SQL parser meant for querying CSV files
Stars: ✭ 249 (-58.98%)
Mutual labels:  sql, parser
Tsql Parser
Library Written in C# For Parsing SQL Server T-SQL Scripts in .Net
Stars: ✭ 203 (-66.56%)
Mutual labels:  sql, parser
Ts Sql
A SQL database implemented purely in TypeScript type annotations.
Stars: ✭ 2,324 (+282.87%)
Mutual labels:  sql, parser
Jsqlparser
JSqlParser parses an SQL statement and translate it into a hierarchy of Java classes. The generated hierarchy can be navigated using the Visitor Pattern
Stars: ✭ 3,405 (+460.96%)
Mutual labels:  sql, parser
Syntax Parser
Light and fast 🚀parser! With zero dependents. - Sql Parser Demo added!
Stars: ✭ 317 (-47.78%)
Mutual labels:  sql, parser
Goconfig
Package goconfig is a fully functional and comments-support configuration file (.ini) parser.
Stars: ✭ 568 (-6.43%)
Mutual labels:  parser
Poco
The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.
Stars: ✭ 5,762 (+849.26%)
Mutual labels:  sql
Sp whoisactive
sp_whoisactive
Stars: ✭ 566 (-6.75%)
Mutual labels:  sql
Self Attentive Parser
High-accuracy NLP parser with models for 11 languages.
Stars: ✭ 569 (-6.26%)
Mutual labels:  parser
Hue
Open source SQL Query Assistant service for Databases/Warehouses
Stars: ✭ 351 (-42.17%)
Mutual labels:  sql
Lol Html
Low output latency streaming HTML parser/rewriter with CSS selector-based API
Stars: ✭ 566 (-6.75%)
Mutual labels:  parser
World countries
Constantly updated lists of world countries and their associated alpha-2, alpha-3 and numeric country codes as defined by the ISO 3166 standard, available in CSV, JSON , PHP and SQL formats, in multiple languages and with national flags included
Stars: ✭ 598 (-1.48%)
Mutual labels:  sql
Webassemblyjs
Toolchain for WebAssembly
Stars: ✭ 566 (-6.75%)
Mutual labels:  parser
Pimpmylog
🍭 Log viewer for your web server
Stars: ✭ 564 (-7.08%)
Mutual labels:  parser
Siuba
Python library for using dplyr like syntax with pandas and SQL
Stars: ✭ 605 (-0.33%)
Mutual labels:  sql
Github Ds
A collection of Ruby libraries for working with SQL on top of ActiveRecord's connection
Stars: ✭ 597 (-1.65%)
Mutual labels:  sql

Extensible SQL Lexer and Parser for Rust

License Version Build Status Coverage Status Gitter Chat

The goal of this project is to build a SQL lexer and parser capable of parsing SQL that conforms with the ANSI/ISO SQL standard while also making it easy to support custom dialects so that this crate can be used as a foundation for vendor-specific parsers.

This parser is currently being used by the DataFusion query engine, LocustDB, and Ballista.

Example

To parse a simple SELECT statement:

use sqlparser::dialect::GenericDialect;
use sqlparser::parser::Parser;

let sql = "SELECT a, b, 123, myfunc(b) \
           FROM table_1 \
           WHERE a > b AND b < 100 \
           ORDER BY a DESC, b";

let dialect = GenericDialect {}; // or AnsiDialect, or your own dialect ...

let ast = Parser::parse_sql(&dialect, sql).unwrap();

println!("AST: {:?}", ast);

This outputs

AST: [Query(Query { ctes: [], body: Select(Select { distinct: false, projection: [UnnamedExpr(Identifier("a")), UnnamedExpr(Identifier("b")), UnnamedExpr(Value(Long(123))), UnnamedExpr(Function(Function { name: ObjectName(["myfunc"]), args: [Identifier("b")], over: None, distinct: false }))], from: [TableWithJoins { relation: Table { name: ObjectName(["table_1"]), alias: None, args: [], with_hints: [] }, joins: [] }], selection: Some(BinaryOp { left: BinaryOp { left: Identifier("a"), op: Gt, right: Identifier("b") }, op: And, right: BinaryOp { left: Identifier("b"), op: Lt, right: Value(Long(100)) } }), group_by: [], having: None }), order_by: [OrderByExpr { expr: Identifier("a"), asc: Some(false) }, OrderByExpr { expr: Identifier("b"), asc: None }], limit: None, offset: None, fetch: None })]

Command line

To parse a file and dump the results as JSON:

$ cargo run --features json_example --example cli FILENAME.sql [--dialectname]

SQL compliance

SQL was first standardized in 1987, and revisions of the standard have been published regularly since. Most revisions have added significant new features to the language, and as a result no database claims to support the full breadth of features. This parser currently supports most of the SQL-92 syntax, plus some syntax from newer versions that have been explicitly requested, plus some MSSQL, PostgreSQL, and other dialect-specific syntax. Whenever possible, the online SQL:2016 grammar is used to guide what syntax to accept.

Unfortunately, stating anything more specific about compliance is difficult. There is no publicly available test suite that can assess compliance automatically, and doing so manually would strain the project's limited resources. Still, we are interested in eventually supporting the full SQL dialect, and we are slowly building out our own test suite.

If you are assessing whether this project will be suitable for your needs, you'll likely need to experimentally verify whether it supports the subset of SQL that you need. Please file issues about any unsupported queries that you discover. Doing so helps us prioritize support for the portions of the standard that are actually used. Note that if you urgently need support for a feature, you will likely need to write the implementation yourself. See the Contributing section for details.

Supporting custom SQL dialects

This is a work in progress, but we have some notes on writing a custom SQL parser.

Design

The core expression parser uses the Pratt Parser design, which is a top-down operator-precedence (TDOP) parser, while the surrounding SQL statement parser is a traditional, hand-written recursive descent parser. Eli Bendersky has a good tutorial on TDOP parsers, if you are interested in learning more about the technique.

We are a fan of this design pattern over parser generators for the following reasons:

  • Code is simple to write and can be concise and elegant
  • Performance is generally better than code generated by parser generators
  • Debugging is much easier with hand-written code
  • It is far easier to extend and make dialect-specific extensions compared to using a parser generator

Contributing

Contributions are highly encouraged!

Pull requests that add support for or fix a bug in a feature in the SQL standard, or a feature in a popular RDBMS, like Microsoft SQL Server or PostgreSQL, will almost certainly be accepted after a brief review. For particularly large or invasive changes, consider opening an issue first, especially if you are a first time contributor, so that you can coordinate with the maintainers. CI will ensure that your code passes cargo test, cargo fmt, and cargo clippy, so you will likely want to run all three commands locally before submitting your PR.

If you are unable to submit a patch, feel free to file an issue instead. Please try to include:

  • some representative examples of the syntax you wish to support or fix;
  • the relevant bits of the SQL grammar, if the syntax is part of SQL:2016; and
  • links to documentation for the feature for a few of the most popular databases that support it.

Please be aware that, while we strive to address bugs and review PRs quickly, we make no such guarantees for feature requests. If you need support for a feature, you will likely need to implement it yourself. Our goal as maintainers is to facilitate the integration of various features from various contributors, but not to provide the implementations ourselves, as we simply don't have the resources.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].