Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add meta-parser for json output #26

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions mo_sql_parsing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from threading import Lock

from mo_sql_parsing.sql_parser import SQLParser, scrub_literal, scrub
import mo_sql_parsing.json_converter import *

parseLocker = Lock() # ENSURE ONLY ONE PARSING AT A TIME

Expand All @@ -24,6 +25,28 @@ def parse(sql):
return scrub(parse_result)


def parse_json(sql):

query = sql.lower()

try :
query_parsed = {}
query_reg = parse(query)
alias = get_tables(query_reg,{})[1]
query_parsed['tables_from'] = get_tables_fj(query_reg, {})[0]
query_parsed['tables_join'] = get_tables_fj(query_reg, {})[1]
query_parsed['projections'] = get_projections(query_reg, alias)
query_parsed['attributes_where'] = get_atts_where(query_reg, alias)
query_parsed['attributes_groupby'] = get_atts_group_by(query_reg, alias)
query_parsed['attributes_orderby'] = get_atts_order_by(query_reg, alias)
query_parsed['attributes_having'] = get_atts_having(query_reg, alias)
query_parsed['functions'] = get_functions(query_reg)
return query_parsed

except :
print(query)
return {}

def format(json, **kwargs):
from mo_sql_parsing.formatting import Formatter

Expand Down
Loading