microsoft / vscode-jupyter

VS Code Jupyter extension
https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter
MIT License
1.28k stars 288 forks source link

Support querying language support to notebooks #9945

Open minsa110 opened 2 years ago

minsa110 commented 2 years ago

Feedback from PyCon 2022

"Can I connect to my database and use SQL / other querying functionalities within the notebook? For example, can I query for data from a cell in SQL with things like intellisense support, and directly use the output data as a pandas dataframe? Right now, I'm having to run my queries in a different tool, save the result, and load it onto my notebook... Or sometimes I'd write the queries in my notebook, but it would just be in string format without any intellisense, so even in that case, I have to use a different tool to generate the queries, then copy and paste it into my notebook..."

greazer commented 2 years ago

This is already supported via cell magics (%). Let's chat, and perhaps we can add this to Discussions tips and tricks or something. The .NET interactive kernel can help with this too.

DonJayamanne commented 2 years ago

Right now, I'm having to run my queries in a different tool, save the result, and load it onto my notebook.

This leads me to believe that the user is already using some cell magic of the like to run sql queries. I think one approachis to get better completion from language servers like SQL to support code completion for the SQL queries after the %%sql text in python code.

This way the user doesn't need to change anything in their workflow, they can continue to use the same python kernel, and write the queries the same way, but have completions from sql extension (just like you get completions for KQL qqueries with %%kql magic in python cells from the vscode-kusto extension)

feihuao commented 1 year ago

I also need this function to automatically completion sql in cell.

feihuao commented 1 year ago

Azure Data Studio Notebooks support this feature.

seppestas commented 3 months ago

This could be done by making VSCode support IPython completers .

It's possible for custom completers to be registered in IPython, which is especially useful for IPython magic, which can change the behaviour of notebook cells or lines.

E.g. when using ipython-sql, it would be great to have autocompletion for SQL keywords, and even better, support Azure Data Studio Notebooks SQL kernel like behaviour which can autocomplete things like table and column names. Using the SQL kernel in Azure Data Studio is IMHO not that useful because (afaik) it is not possible to do things like plotting the data. Having access to the data in a more general and capable language like Python is far more useful than being limited to (T)SQL.

It is somewhat possible to do this with vscode-jupyter by setting the cell syntax to sql, but this causes VSCode to give an error about the %sql / %%sql line not being valid: "Incorrect syntax near '%'.

An other use-case for this is getting logs from e.g. Sumo logic. Currently there is no IPython magic for this, but it would be awesome to have one that could autocomplete Sumo logic queries.