Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Parsing utilities to validate and split SQL statements for CrateDB.

License

NotificationsYou must be signed in to change notification settings

crate/cratedb-sqlparse

Repository files navigation

Antlr4 is a parser generator for reading, processing and executing text, there are severaltarget languages (Java, Python, JavaScript, Dart) available. CrateDB uses the Java target.

The repository holds libraries/packages created from some of those available languages, sofar:Python andJavaScript. More might be added if needed in the future.

These libraries allow you to parse Crate's SQL dialect without sending it to a CrateDB instance.

Install

You can install the package in both its Python and JavaScript variants.

Python

pip install cratedb-sqlparse

JavaScript

npm install @cratedb/cratedb-sqlparse

Synopsis

fromcratedb_sqlparseimportsqlparsequery="""    SELECT * FROM SYS.SHARDS;    INSERT INTO doc.tbl VALUES (1);"""statements=sqlparse(query)select_query=statements[0]print(select_query.query)# 'SELECT * FROM SYS.SHARDS'

Limitations

All the implemented libraries can validate SQL, split queries and parse using antrl4's listeners.

Listeners are partially implemented, which means that we can only parse:

  • Create table statements: table name, schema, and 'with' options

If more metadata is needed, it can be requested in a new issue.

New features should preferably be implemented in all available targets.

Adding a new target

The target language has to be available in antlr4,seehttps://github.com/antlr/antlr4/blob/master/doc/targets.md.

Add the new target and paths to the build script, seesetup_grammar.py.

There are several features that would need to be implemented, like case-insensitive input stream, nativeexceptions as error listener, dollar-strings and any new one. See past commits to see how they wereimplemented in Python and Javascript, remember thatCrateDB'S SQLParser written in Java is the mostcomplete and the default reference.

Development

The generated parser is not uploaded to the repository because it is huge.To use the package locally or to build a different version use the build script.Further information can be found in thedeveloper guide.

About

Parsing utilities to validate and split SQL statements for CrateDB.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp