Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base implementation + Flight API #1

Merged
merged 26 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: pr

on:
push:
branches: ["trunk"]
pull_request:
branches: ["trunk"]

jobs:
build_and_test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
sgrebnov marked this conversation as resolved.
Show resolved Hide resolved
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
env:
API_KEY: ${{ secrets.SPICE_CLOUD_API_KEY }}
run: dotnet test --no-build --verbosity normal
134 changes: 134 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates
**/.idea/

# Build results

[Dd]ebug/
[Rr]elease/
x64/
[Bb]in/
[Oo]bj/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.svclog
*.scc

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# Click-Once directory
publish/

# Publish Web Output
*.Publish.xml
*.pubxml
*.azurePubxml

# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
packages/
## TODO: If the tool you use requires repositories.config, also uncomment the next line
!packages/repositories.config

# Windows Azure Build Output
csx/
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
![Ss]tyle[Cc]op.targets
~$*
*~
*.dbmdl
*.[Pp]ublish.xml

*.publishsettings

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
App_Data/*.mdf
App_Data/*.ldf

# =========================
# Windows detritus
# =========================

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Mac desktop service store files
.DS_Store

_NCrunch*
51 changes: 49 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,49 @@
# spice-csharp
C# SDK for Spice AI OSS
# Dotnet Spice SDK

Dotnet SDK for Spice.ai.
- Supports .NET Standard 2.0 and .NET 6.0.
- Asynchronous I/O.

## Usage

<!-- NOTE: If you're changing the code examples below, make sure you update `tests/readme_test.rs`. -->

### Usage with locally running [spice runtime](https://github.com/spiceai/spiceai)

Follow the [quickstart guide](https://github.com/spiceai/spiceai?tab=readme-ov-file#%EF%B8%8F-quickstart-local-machine) to install and run spice locally

```csharp
using Spice;

var client = new SpiceClientBuilder().Build();
```

### New client with https://spice.ai cloud

```csharp
using Spice;

var client = new SpiceClientBuilder()
.WithApiKey("API_KEY")
.WithSpiceCloud()
.Build();
```

### Arrow Query

SQL Query

```csharp
using Spice;

var client = new SpiceClientBuilder()
.WithApiKey("API_KEY")
.WithSpiceCloud()
.Build();

var data = await client.Query("SELECT * FROM eth.recent_blocks LIMIT 10;");
```

## Documentation

Check out our [Documentation](https://docs.spice.ai/sdks/dotnet-sdk) to learn more about how to use the Dotnet SDK.
22 changes: 22 additions & 0 deletions Spice.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spice", "Spice\Spice.csproj", "{EF94CCFC-48CD-4EE5-B263-C4996F5C2AA7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpiceTest", "SpiceTest\SpiceTest.csproj", "{2B63CBFD-EAE1-4072-AE24-FCB00DBC6F9B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EF94CCFC-48CD-4EE5-B263-C4996F5C2AA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EF94CCFC-48CD-4EE5-B263-C4996F5C2AA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EF94CCFC-48CD-4EE5-B263-C4996F5C2AA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EF94CCFC-48CD-4EE5-B263-C4996F5C2AA7}.Release|Any CPU.Build.0 = Release|Any CPU
{2B63CBFD-EAE1-4072-AE24-FCB00DBC6F9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B63CBFD-EAE1-4072-AE24-FCB00DBC6F9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B63CBFD-EAE1-4072-AE24-FCB00DBC6F9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B63CBFD-EAE1-4072-AE24-FCB00DBC6F9B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
18 changes: 18 additions & 0 deletions Spice/Spice.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<LangVersion>11.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
gloomweaver marked this conversation as resolved.
Show resolved Hide resolved
<Version>0.1.0</Version>
<Nullable>enable</Nullable>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
sgrebnov marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Apache.Arrow" Version="16.1.0"/>
<PackageReference Include="Apache.Arrow.Flight" Version="16.1.0"/>
<PackageReference Include="Polly" Version="8.4.0"/>
</ItemGroup>


</Project>
37 changes: 37 additions & 0 deletions Spice/src/Auth/Auth.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright 2024 The Spice.ai OSS Authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

using System.Net.Http.Headers;
using System.Text;

namespace Spice.Auth;

internal static class AuthHeaderBuilder
{
public static AuthenticationHeaderValue BasicAuth(string appId, string apiKey)
{
return AuthenticationHeaderValue.Parse("Basic " +
Convert.ToBase64String(Encoding
.UTF8
.GetBytes($"{appId}:{apiKey}")));
}
}
29 changes: 29 additions & 0 deletions Spice/src/Config/SpiceDefaultConfigCloud.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2024 The Spice.ai OSS Authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

namespace Spice.Config;
gloomweaver marked this conversation as resolved.
Show resolved Hide resolved

internal static class SpiceDefaultConfigCloud
{
public static readonly string FlightAddress =
Environment.GetEnvironmentVariable("SPICE_FLIGHT_URL") ?? "https://flight.spiceai.io:443";
}
29 changes: 29 additions & 0 deletions Spice/src/Config/SpiceDefaultConfigLocal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2024 The Spice.ai OSS Authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

namespace Spice.Config;

internal static class SpiceDefaultConfigLocal
{
public static readonly string FlightAddress =
Environment.GetEnvironmentVariable("SPICE_LOCAL_FLIGHT_URL") ?? "http://localhost:50051";
}
39 changes: 39 additions & 0 deletions Spice/src/Errors/SpiceException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright 2024 The Spice.ai OSS Authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

namespace Spice.Errors;

/// <summary>
/// Spice Client SDK exceptions.
/// </summary>
[Serializable]
public class SpiceException : Exception
{
public SpiceStatus Status { get; private set; }

internal SpiceException(SpiceStatus status) : this(status, status.ToString()) {}

internal SpiceException(SpiceStatus status, string message) : base(message)
{
Status = status;
}
}
Loading