Add Notebook conversion logic (#1027)

* Add logic to convert Notebook doc into SQL query

* move classes

* Add logic for SQL -> Notebook

* Fix a few trimming issues
This commit is contained in:
Charles Gagnon
2020-08-03 07:54:06 -07:00
committed by GitHub
parent ac40cdc84a
commit bf4911795f
3 changed files with 198 additions and 35 deletions

View File

@@ -0,0 +1,65 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
namespace Microsoft.SqlTools.ServiceLayer.NotebookConvert
{
/// <summary>
/// Basic schema wrapper for parsing a Notebook document
/// </summary>
public class NotebookDocument
{
[JsonProperty("metadata")]
public NotebookMetadata NotebookMetadata;
[JsonProperty("nbformat_minor")]
public int NotebookFormatMinor = 2;
[JsonProperty("nbformat")]
public int NotebookFormat = 4;
[JsonProperty("cells")]
public IList<NotebookCell> Cells = new List<NotebookCell>();
}
public class NotebookMetadata
{
[JsonProperty("kernelspec")]
public NotebookKernelSpec KernelSpec;
[JsonProperty("language_info")]
public NotebookLanguageInfo LanguageInfo;
}
public class NotebookKernelSpec
{
[JsonProperty("name")]
public string Name;
[JsonProperty("display_name")]
public string DisplayName;
[JsonProperty("language")]
public string Language;
}
public class NotebookLanguageInfo
{
[JsonProperty("name")]
public string Name;
[JsonProperty("version")]
public string Version;
}
/// <summary>
/// Cell of a Notebook document
/// </summary>
public class NotebookCell
{
public NotebookCell(string cellType, IList<String> source)
{
this.CellType = cellType;
this.Source = source;
}
[JsonProperty("cell_type")]
public string CellType;
[JsonProperty("source")]
public IList<string> Source;
}
}