dotnet / interactive

.NET Interactive combines the power of .NET with many other languages to create notebooks, REPLs, and embedded coding experiences. Share code, explore data, write, and learn across your apps in ways you couldn't before.
MIT License
2.9k stars 387 forks source link

SQL results not rendered with nteract data explorer #2545

Closed travisgan closed 1 year ago

travisgan commented 1 year ago

.NET Interactive © 2020 Microsoft Corporation Version: 1.0.355307+4cc71ae4e275fd80852b9c2faa317bc3a0033d2c Library version: 1.0.0-beta.22553.7+4cc71ae4e275fd80852b9c2faa317bc3a0033d2c Build date: 2022-11-28T21:03:16.1596190Z https://github.com/dotnet/interactive

When executing a sql query, the result is rendered in a plain table (like html table). For example,

!sql-mydb

select * from sys.databases

As opposed to multiple 'older' video showcase, the demo always shows that sql query rendered in nteract data explorer. https://youtu.be/938jBJ-tK3c?t=1134 https://youtu.be/m5d6pG_R05M?t=1186

At one point in the first video, @jonsequitur mentioned that by default sql result should be rendered with nteract data explorer. Not sure if anything has changed since then or is there anything additional need to be installed or configured to have the sql query result in a better/richer format (eg. nteract data explorer)?

sasaendler commented 1 year ago

Hi. I'm facing the same issue. "Change presentation" dialog on data result only offers text/plain as option. I couldn't find a nteract extension. What am I missing?

Running Polyglot Notebooks v1.0.3606020.

Best Regards.

colombod commented 1 year ago

The behaviour changed a while back. nteractDataExplorer and SandDanddance are no longer part of the core product. By default we will emit text/html preview and text/csv mimetypes so that custom renderers can be used.

This is the normal behaviour

image

Then using a custom renderer we go from this

image

to this

image

Just installing the Data Table Renderers from the VSCode Market plalce

To use nteract or sanddance load the extensions

#r "nuget: SandDance.InteractiveExtension, 1.0.74"

Then there are to options:

  1. use Sanddance as default for html
  2. share the result from sql to C# and use the data[0].ExploreWithSandDance().Display(); code

For option 1:

after the package is loaded use the following code to configure sanddace as default explorer

using SandDance.InteractiveExtension;
using Microsoft.DotNet.Interactive;
using Microsoft.DotNet.Interactive.Formatting;
using Microsoft.DotNet.Interactive.Formatting.TabularData;

DataExplorer.SetDefault<TabularDataResource, SandDanceDataExplorer>();

Now when you run the sql statements you get this

image

Remember to set the right output renderer image

For Option 2

Run the query like this

#!sql-AdventureWorks2019 --name savedData
select TOP (50) * from Person.Person

The results will be stored using the name savedData

in a csharp cell now do

#!share --from sql-AdventureWorks2019 savedData

As it is a result set now do

savedData[0].ExploreWithSandDance().Display();

And you get

image

@claudiaregio we should cover this in a document

sasaendler commented 1 year ago

@colombod Thank you for your great helpful response.

travisgan commented 1 year ago

@colombod thank you for the clarification. how do you exactly get to this data table view in your example? is that from nteract extension and how do you load that as default data explorer (instead of the sanddance example graphical view)?

image

travisgan commented 1 year ago

Never mind. The data table renderer extension will show that view as long as the correct right output renderer is selected. Thanks.