Skip to content

Commit

Permalink
vdk-jupyter: use vdksql for SQL cells and steps (#2729)
Browse files Browse the repository at this point in the history
%%vdksql is preferred over `job_input.execute_query` in a notebook as
it's generally easier to write, debug has better table visualization. So
we should default to it.
  • Loading branch information
antoniivanov authored Oct 2, 2023
1 parent 90c6518 commit f590640
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ export const populateNotebook = async (notebookTracker: INotebookTracker) => {
' <li> The below cells are automatically generated corresponding to a step (.sql file or .py file with VDK run(job_input) function) in your original job.</li>\n',
' <li> When you see a title saying <b>"Step generated from: sample.py"</b> before some blocks of code, \n',
' it means that the code below that title was created from the "sample.py" file.</li>\n',
' <li> Similarly, if you come across code cells that have the format <b>"job_input.execute_query(query_string)"</b> ,\n',
' it means that those cells contain code generated from ".sql" files.</li>\n',
' <li> Similarly, if you come across code cells that start <b>%%vdksql</b> contain code generated from ".sql" steps.</li>\n',
' <li> On the other hand, code cells originating from ".py" files remain unchanged.\n',
' However, an additional cell is included that calls the "run" function using the command <b>"run(job_input)"</b> . \n',
' This cell executes the "run" function from the code generated from the ".py" file.</li>\n',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _process_python_files(self, file):
def _process_sql_files(self, file):
with open(file) as f:
content = f.read()
self._code_structure.append(f'job_input.execute_query("""{content}""")')
self._code_structure.append(f"%%vdksql\n{content}")
self._removed_files.append(os.path.basename(file))
os.remove(file)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,15 @@
},
"outputs": [],
"source": [
"\"\"\"\n",
"This and the subsequent cells are marked as VDK cells.\n",
"%%vdksql\n",
"/*\n",
"Cells with '%%vdksql' magic are VDK SQL Cell (step).\n",
"\n",
"Cells can be marked or unmarked as VDK cells through the gearwheel menu\n",
"to the right.\n",
"\"\"\"\n",
"Note that this and the subsequent cells are marked as VDK cells.\n",
"Cells can be marked or unmarked as VDK cells through the gearwheel menu to the right.\n",
"*/\n",
"\n",
"job_input.execute_query(\n",
" \"CREATE TABLE IF NOT EXISTS hello_world (id NVARCHAR);\"\n",
")"
"CREATE TABLE IF NOT EXISTS hello_world (id NVARCHAR)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_cleanup(self):
def test_get_code_structure(self):
self.processor.process_files()
expected_code_structure = [
f'job_input.execute_query("""{self.sql_content}""")',
f"%%vdksql\n{self.sql_content}",
self.py_content_run,
self.py_content_run_multiline,
self.py_content_run_spaces,
Expand Down

0 comments on commit f590640

Please sign in to comment.