Giter VIP home page Giter VIP logo

lacquer's Issues

Improve error messages

The syntax error message is a bit off and doesn't produce helpful output about the token the error is seen at.

COUNT(*)

SELECT COUNT(*) FROM foo

currently fails as a syntax error

publish to pypi

Would you be willing to publish this package to pypi so that it'll be easier to install ?

UNION parse seems to be case sensitive

Hey @brianv0

First of, awesome job on this parser. I came across an issue, easy to work around, but though I would share. When parsing queries with UNION, it parser correctly only if UNION is upper case. See below:

Query 1:
	SELECT name,sex FROM zoo_a.animals UNION SELECT name,sex FROM zoo_b.animals
Result 1:
	{'query_body': {'distinct': True, 'line': 0, 'pos': 0, 'relations': [QuerySpecification(select=Select(distinct=False, select_items=[SingleColumn(expression=QualifiedNameReference(name=QualifiedName(name))), SingleColumn(expression=QualifiedNameReference(name=QualifiedName(sex)))]), from_=Table(name=QualifiedName(zoo_a.animals)), order_by=[]), QuerySpecification(select=Select(distinct=False, select_items=[SingleColumn(expression=QualifiedNameReference(name=QualifiedName(name))), SingleColumn(expression=QualifiedNameReference(name=QualifiedName(sex)))]), from_=Table(name=QualifiedName(zoo_b.animals)), order_by=[])]}, 'line': 0, 'order_by': [], 'pos': 0}
==================================================
Query 2:
	SELECT name,sex FROM zoo_a.animals union SELECT name,sex FROM zoo_b.animals
Result 2:
	{'query_body': {'distinct': True, 'line': 0, 'right': None, 'pos': 0, 'left': QuerySpecification(select=Select(distinct=False, select_items=[SingleColumn(expression=QualifiedNameReference(name=QualifiedName(name))), SingleColumn(expression=QualifiedNameReference(name=QualifiedName(sex)))]), from_=Table(name=QualifiedName(zoo_a.animals)), order_by=[])}, 'line': 0, 'order_by': [], 'pos': 0}

Equal: False

Cheers

Resolving table/column for UNION queries

@brianv0 I was leveraging the logic you provided in the examples/gather_columns.py script, and agree with your logic for a query of the form,

SELECT foo, b.bar FROM a JOIN b ON a.id = b.id

which results in a table/column resolution of:

SingleColumn(expression=QualifiedNameReference(name=QualifiedName(foo))): [Table(name=QualifiedName(a)), Table(name=QualifiedName(b))]
SingleColumn(expression=QualifiedNameReference(name=QualifiedName(b.bar))): [Table(name=QualifiedName(b))]

i.e., from the query one cannot decipher whether the column foo is from a or b, however for a UNION type query

SELECT foo AS bar FROM a UNION SELECT bar FROM b

the table/column resolution is:

SingleColumn(alias='bar', expression=QualifiedNameReference(name=QualifiedName(foo))): [Table(name=QualifiedName(b)), Table(name=QualifiedName(a))]
SingleColumn(expression=QualifiedNameReference(name=QualifiedName(bar))): [Table(name=QualifiedName(b)), Table(name=QualifiedName(a))]

although it's apparent from the query that the foo column is from table a and the bar column is from table b. Do you know of any resolution to this issue?

Create a query analysis module/api for common operations

Based on examples/gather_columns.py and other needs, it'd be good to see if we can define a API for answering common questions about queries, like what tables and columns are referenced in a given query.

I'm not sure if there's enough overlap in the questions people want to ask, so this issue is a placeholder to understand them, and a continuation of #13.

CAST throws Syntax error

Howdy - I just tried out lacquer and it seems like CAST causes an uninformative error to be thrown

In [44]: parser.parse("SELECT CAST(a AS BIGINT) FROM b")
  File "<string>", line 94
    SELECT CAST(a AS BIGINT) FROM b
          ^
SyntaxError: Syntax error

FYI @johnbodley

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.