Skip to content
Open
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
20 changes: 17 additions & 3 deletions process_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import json
import sqlite3
from typing import List
from nltk import word_tokenize

CLAUSE_KEYWORDS = ('select', 'from', 'where', 'group', 'order', 'limit', 'intersect', 'union', 'except')
Expand Down Expand Up @@ -112,11 +113,24 @@ def get_schema_from_json(fpath):

return schema

def find_quoted_strings(text: str) -> List[int]:
quote_idxs = []
idx = 0
escaped = False
while idx < len(text):
if escaped:
idx, escaped = idx + 1, False
c = text[idx]
if c == "\\":
escaped = True
elif c == "\'" or c == "\"":
quote_idxs.append(idx)
idx += 1
return quote_idxs


def tokenize(string):
string = str(string)
string = string.replace("\'", "\"") # ensures all string values wrapped by "" problem??
quote_idxs = [idx for idx, char in enumerate(string) if char == '"']
quote_idxs = find_quoted_strings(string)
assert len(quote_idxs) % 2 == 0, "Unexpected quote"

# keep string value as token
Expand Down