-
Notifications
You must be signed in to change notification settings - Fork 76
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
[Fix 954]: #955
[Fix 954]: #955
Changes from all commits
7ee41aa
13e7b70
513ff3a
ff2a751
96aaa5b
7c5be39
6a4f010
d2bf6e5
c29d518
4c22928
ab819ad
b44633f
f897b88
6755b15
4701e6e
3957a0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,11 +228,14 @@ def without_sql_comment(parser, line): | |
""" | ||
|
||
args = _option_strings_from_parser(parser) | ||
pattern = re.compile(r'([\'"])(.*?)\1') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add some comment to explain this code |
||
line = pattern.sub(lambda match: match.group().replace(" ", "@@SPACE@@"), line) | ||
result = itertools.takewhile( | ||
lambda word: (not word.startswith("--")) or (word in args), | ||
shlex.split(line, posix=False), | ||
lambda word: (not word.startswith("--")) or (word in args), line.split() | ||
) | ||
return " ".join(result) | ||
result = " ".join(result) | ||
result = result.replace("@@SPACE@@", " ") | ||
return result | ||
|
||
|
||
def split_args_and_sql(line): | ||
|
@@ -274,20 +277,26 @@ def split_args_and_sql(line): | |
# If any SQL commands are found in the line, we split the line into args and sql. | ||
# Note: lines without SQL commands will not be split | ||
# ex. %sql duckdb:// or %sqlplot boxplot --table data.csv | ||
if not any(cmd in line_no_filenames for cmd in SQL_COMMANDS): | ||
return arg_line, sql_line | ||
|
||
# Identify beginning of sql query using keywords | ||
split_idx = -1 | ||
for token in line.split(): | ||
if token.lower() in SQL_COMMANDS: | ||
# Found index at which to split line | ||
split_idx = line.find(token) | ||
break | ||
|
||
# Split line into args and sql, beginning at sql keyword | ||
if split_idx != -1: | ||
arg_line, sql_line = line[:split_idx], line[split_idx:] | ||
if "<<" in line: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add some comments to explain this code |
||
[before_assign, after_assign] = line.split("<<") | ||
result_var = before_assign.split()[-1] | ||
arg_line = " ".join(before_assign.split()[:-1]) | ||
sql_line = result_var + " << " + after_assign | ||
|
||
elif any(cmd in line_no_filenames for cmd in SQL_COMMANDS) or any( | ||
cmd.upper() in line_no_filenames for cmd in SQL_COMMANDS | ||
): | ||
# Identify beginning of sql query using keywords | ||
split_idx = -1 | ||
for token in line.split(): | ||
if token.lower() in SQL_COMMANDS: | ||
# Found index at which to split line | ||
split_idx = line.find(token) | ||
break | ||
|
||
# Split line into args and sql, beginning at sql keyword | ||
if split_idx != -1: | ||
arg_line, sql_line = line[:split_idx], line[split_idx:] | ||
|
||
return arg_line, sql_line | ||
|
||
|
@@ -301,14 +310,13 @@ def magic_args(magic_execute, line, cmd_from, allowed_duplicates=None): | |
arg_line, sql_line = split_args_and_sql(line) | ||
|
||
args = shlex.split(arg_line, posix=False) | ||
|
||
if len(args) > 1: | ||
check_duplicate_arguments(magic_execute, cmd_from, args, allowed_duplicates) | ||
|
||
parsed = magic_execute.parser.parse_args(args) | ||
|
||
if sql_line: | ||
parsed.line = shlex.split(sql_line, posix=False) | ||
parsed.line = sql_line.split() | ||
|
||
return parsed | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,8 @@ def __init__(self, connectstr): | |
self.connectstr = connectstr | ||
|
||
def query(self, txt): | ||
return ip.run_line_magic("sql", "%s %s" % (self.connectstr, txt)) | ||
ip.run_line_magic("sql", self.connectstr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we running run_line_magic two times now? |
||
return ip.run_line_magic("sql", "%s" % txt) | ||
|
||
|
||
sql_env = SqlEnv("sqlite://") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the changelog is for end users, so there's no need to disclose internal stuff like shlex. it's better to phrase the entry in a way that end users can understand