Skip to content

Commit ab819ad

Browse files
committed
fixed breaking tests due to wrong splitting of argument and sql_lines
1 parent 4c22928 commit ab819ad

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/sql/parse.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,12 @@ def without_sql_comment(parser, line):
229229

230230
args = _option_strings_from_parser(parser)
231231
pattern = re.compile(r'([\'"])(.*?)\1')
232-
temp_line = pattern.sub(lambda x: x.group().replace(" ", ""), line)
233-
spaces_removed = len(line) - len(temp_line)
232+
line = pattern.sub(lambda match: match.group().replace(" ", "@@SPACE@@"), line)
234233
result = itertools.takewhile(
235-
lambda word: (not word.startswith("--")) or (word in args), temp_line.split()
234+
lambda word: (not word.startswith("--")) or (word in args), line.split()
236235
)
237236
result = " ".join(result)
238-
result = line[: len(result) + spaces_removed]
237+
result = result.replace("@@SPACE@@", " ")
239238
return result
240239

241240

@@ -278,7 +277,13 @@ def split_args_and_sql(line):
278277
# If any SQL commands are found in the line, we split the line into args and sql.
279278
# Note: lines without SQL commands will not be split
280279
# ex. %sql duckdb:// or %sqlplot boxplot --table data.csv
281-
if any(cmd in line_no_filenames for cmd in SQL_COMMANDS) or any(
280+
if "<<" in line:
281+
[before_assign, after_assign] = line.split("<<")
282+
result_var = before_assign.split()[-1]
283+
arg_line = " ".join(before_assign.split()[:-1])
284+
sql_line = result_var + " << " + after_assign
285+
286+
elif any(cmd in line_no_filenames for cmd in SQL_COMMANDS) or any(
282287
cmd.upper() in line_no_filenames for cmd in SQL_COMMANDS
283288
):
284289
# Identify beginning of sql query using keywords

0 commit comments

Comments
 (0)