Skip to content

heyanger/sqltools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

SQL tools

This module provides sql to tree parsing as well as edit sequence generation (based on SyntaxSQLNet https://arxiv.org/abs/1810.05237)

Usage

Converting a sql into a tree and back

from sqltools.parser import to_tree, to_sql

sql = 'SELECT * FROM table'
tree = to_tree(sql)
parsed = to_sql(tree)

Support for tables

from sqltools.parser import to_tree, to_sql

sql = "SELECT t1.salary, hours FROM instructor AS t1 JOIN othertable AS t2 LIMIT 1"

table_info = {
    'instructor': ['salary', 'hours'],
    'othertable': ['abc']
}

tree = to_tree(sql, table_info)
parsed = to_sql(tree)

Generating an edit sequence and apply sequence

from sqltools.parser import to_tree, to_sql
from sqltools.sequence import generate_sequence, apply_sequence_sql

sql1 = "SELECT * FROM owners"
sql2 = "SELECT count(*) FROM owners WHERE state = 'Arizona'"

# SQL based
sequence = generate_sequence_sql(sql1, sql2)
assert(apply_sequence_sql(sql1, sequence) == sql2)

# Tree based
sequence = generate_sequence(to_tree(sql1), to_tree(sql2))
assert(to_sql(apply_sequence(to_tree(sql1), sequence)) == sql2)

Queries not supported

  • Nested Queries in FROM i.e. SELECT * FROM (SELECT * FROM table)
  • complex AND/OR queries

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages