Skip to content

Commit

Permalink
Target .net standard 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gloomweaver committed Jun 13, 2024
1 parent a58d2b6 commit 5f9813f
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 53 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Spice/Spice.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>11.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
6 changes: 6 additions & 0 deletions Spice/src/Config/SpiceDefaultConfigCloud.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Spice.Config;

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

internal static class SpiceDefaultConfigLocal
{
public static readonly string FlightAddress = Environment.GetEnvironmentVariable("SPICE_LOCAL_FLIGHT_URL") ?? "grpc://localhost:50051";
}
24 changes: 24 additions & 0 deletions Spice/src/Extension/AsyncEnumerableExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

namespace Spice.Extension;


public static class AsyncEnumerableExtensions
{
public static IEnumerable<T> ToBlockingEnumerable<T>(this IAsyncEnumerable<T> asyncEnumerable)
{
var enumerator = asyncEnumerable.GetAsyncEnumerator();
try
{
while (true)
{
var moveNextTask = Task.Run(() => enumerator.MoveNextAsync().AsTask());
if (!moveNextTask.GetAwaiter().GetResult()) break;
yield return enumerator.Current;
}
}
finally
{
Task.Run(() => enumerator.DisposeAsync()).GetAwaiter().GetResult();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
using Apache.Arrow.Flight.Client;
using Grpc.Core;
using Grpc.Net.Client;
using Spice.Extension;

namespace Spice.flight;
namespace Spice.Flight;

internal class SpiceFlightClient
{
Expand Down
6 changes: 2 additions & 4 deletions Spice/src/SpiceClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Apache.Arrow;
using Spice.config;
using Spice.flight;
using Spice.Config;
using Spice.Flight;

namespace Spice;

Expand All @@ -9,8 +9,6 @@ public class SpiceClient
public string? AppId { get; internal set; }
public string? ApiKey { get; internal set; }
public string FlightAddress { get; internal set; } = SpiceDefaultConfigLocal.FlightAddress;
public string FirecacheAddress { get; internal set; } = SpiceDefaultConfigLocal.FirecacheAddress;
public string HttpAddress { get; internal set; } = SpiceDefaultConfigLocal.HttpAddress;
public int MaxRetries { get; internal set; } = 3;

private SpiceFlightClient? FlightClient { get; set; }
Expand Down
36 changes: 9 additions & 27 deletions Spice/src/SpiceClientBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
using Spice.config;
using Spice.Config;

namespace Spice;

public class SpiceClientBuilder
{
private readonly SpiceClient _spiceClient = new();

public SpiceClientBuilder WithApiKey(string apiKey)
public SpiceClientBuilder WithFlightAddress(string flightAddress)
{
_spiceClient.FlightAddress = flightAddress;
return this;
}

public SpiceClientBuilder WithSpiceCloud(string apiKey)
{
var parts = apiKey.Split('|');
if (parts.Length != 2)
Expand All @@ -15,32 +21,8 @@ public SpiceClientBuilder WithApiKey(string apiKey)
}
_spiceClient.AppId = parts[0];
_spiceClient.ApiKey = apiKey;
return this;
}

public SpiceClientBuilder WithHttpAddress(string httpAddress)
{
_spiceClient.HttpAddress = httpAddress;
return this;
}

public SpiceClientBuilder WithFlightAddress(string flightAddress)
{
_spiceClient.FlightAddress = flightAddress;
return this;
}

public SpiceClientBuilder WithFirecacheAddress(string firecacheAddress)
{
_spiceClient.FirecacheAddress = firecacheAddress;
return this;
}

public SpiceClientBuilder WithSpiceCloud()
{
_spiceClient.HttpAddress = SpiceDefaultConfigCloud.HttpAddress;

_spiceClient.FlightAddress = SpiceDefaultConfigCloud.FlightAddress;
_spiceClient.FirecacheAddress = SpiceDefaultConfigCloud.FirecacheAddress;
return this;
}

Expand Down
8 changes: 0 additions & 8 deletions Spice/src/config/SpiceDefaultConfigCloud.cs

This file was deleted.

8 changes: 0 additions & 8 deletions Spice/src/config/SpiceDefaultConfigLocal.cs

This file was deleted.

6 changes: 2 additions & 4 deletions SpiceTest/FlightQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ public class FlightQueryTest
public async Task TestDoGetAsync()
{
var client = new SpiceClientBuilder()
.WithApiKey("323337|b42eceab2e7c4a60a04ad57bebea830d")
.WithSpiceCloud()
.WithSpiceCloud("323337|b42eceab2e7c4a60a04ad57bebea830d")
.Build();
var result =
client.DoGetAsync("""SELECT number, "timestamp", hash FROM eth.recent_blocks ORDER BY number LIMIT 10""");
Expand All @@ -25,8 +24,7 @@ public async Task TestDoGetAsync()
public void TestDoGetSync()
{
var client = new SpiceClientBuilder()
.WithApiKey("323337|b42eceab2e7c4a60a04ad57bebea830d")
.WithSpiceCloud()
.WithSpiceCloud("323337|b42eceab2e7c4a60a04ad57bebea830d")
.Build();
var result =
client.DoGet("""SELECT number, "timestamp", hash FROM eth.recent_blocks ORDER BY number LIMIT 10""");
Expand Down

0 comments on commit 5f9813f

Please sign in to comment.