-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to the .NET 8 SDK and use some new C# features. (#362)
* Update SDK to .NET 8. * Use collection expressions. * Suppress two Sonar warnings in an example. * Use file-scoped namespaces.
- Loading branch information
1 parent
404bf86
commit 8526f4a
Showing
99 changed files
with
14,032 additions
and
14,119 deletions.
There are no files selected for viewing
129 changes: 64 additions & 65 deletions
129
examples/TileDB.CSharp.Example/ExampleAggregateQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,83 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace TileDB.CSharp.Examples | ||
namespace TileDB.CSharp.Examples; | ||
|
||
static class ExampleAggregateQuery | ||
{ | ||
static class ExampleAggregateQuery | ||
{ | ||
private static readonly string ArrayPath = ExampleUtil.MakeExamplePath("aggregate-array"); | ||
private static readonly Context Ctx = Context.GetDefault(); | ||
private static readonly string ArrayPath = ExampleUtil.MakeExamplePath("aggregate-array"); | ||
private static readonly Context Ctx = Context.GetDefault(); | ||
|
||
private static void CreateArray() | ||
{ | ||
// Create array | ||
var dim1 = Dimension.Create(Ctx, "rows", boundLower: 1, boundUpper: 4, extent: 4); | ||
var dim2 = Dimension.Create(Ctx, "cols", boundLower: 1, boundUpper: 4, extent: 4); | ||
var domain = new Domain(Ctx); | ||
domain.AddDimension(dim1); | ||
domain.AddDimension(dim2); | ||
var array_schema = new ArraySchema(Ctx, ArrayType.Sparse); | ||
var attr = new Attribute(Ctx, "a", DataType.Int32); | ||
array_schema.AddAttribute(attr); | ||
array_schema.SetDomain(domain); | ||
array_schema.Check(); | ||
private static void CreateArray() | ||
{ | ||
// Create array | ||
var dim1 = Dimension.Create(Ctx, "rows", boundLower: 1, boundUpper: 4, extent: 4); | ||
var dim2 = Dimension.Create(Ctx, "cols", boundLower: 1, boundUpper: 4, extent: 4); | ||
var domain = new Domain(Ctx); | ||
domain.AddDimension(dim1); | ||
domain.AddDimension(dim2); | ||
var array_schema = new ArraySchema(Ctx, ArrayType.Sparse); | ||
var attr = new Attribute(Ctx, "a", DataType.Int32); | ||
array_schema.AddAttribute(attr); | ||
array_schema.SetDomain(domain); | ||
array_schema.Check(); | ||
|
||
Array.Create(Ctx, ArrayPath, array_schema); | ||
} | ||
Array.Create(Ctx, ArrayPath, array_schema); | ||
} | ||
|
||
private static void WriteArray() | ||
private static void WriteArray() | ||
{ | ||
using (var array_write = new Array(Ctx, ArrayPath)) | ||
{ | ||
using (var array_write = new Array(Ctx, ArrayPath)) | ||
array_write.Open(QueryType.Write); | ||
using (var query_write = new Query(array_write)) | ||
{ | ||
array_write.Open(QueryType.Write); | ||
using (var query_write = new Query(array_write)) | ||
{ | ||
query_write.SetLayout(LayoutType.GlobalOrder); | ||
query_write.SetDataBuffer("rows", new int[] { 1, 2 }); | ||
query_write.SetDataBuffer("cols", new int[] { 1, 4 }); | ||
query_write.SetDataBuffer("a", new int[] { 1, 2 }); | ||
query_write.Submit(); | ||
query_write.SetDataBuffer("rows", new int[] { 3 }); | ||
query_write.SetDataBuffer("cols", new int[] { 3 }); | ||
query_write.SetDataBuffer("a", new int[] { 3 }); | ||
query_write.SubmitAndFinalize(); | ||
} | ||
array_write.Close(); | ||
query_write.SetLayout(LayoutType.GlobalOrder); | ||
query_write.SetDataBuffer("rows", new int[] { 1, 2 }); | ||
query_write.SetDataBuffer("cols", new int[] { 1, 4 }); | ||
query_write.SetDataBuffer("a", new int[] { 1, 2 }); | ||
query_write.Submit(); | ||
query_write.SetDataBuffer("rows", new int[] { 3 }); | ||
query_write.SetDataBuffer("cols", new int[] { 3 }); | ||
query_write.SetDataBuffer("a", new int[] { 3 }); | ||
query_write.SubmitAndFinalize(); | ||
} | ||
array_write.Close(); | ||
} | ||
} | ||
|
||
private static void ReadArray() | ||
{ | ||
ulong[] count = { 0 }; | ||
long[] sum = { 0 }; | ||
|
||
using (var array_read = new Array(Ctx, ArrayPath)) | ||
{ | ||
array_read.Open(QueryType.Read); | ||
using var query_read = new Query(array_read); | ||
query_read.SetLayout(LayoutType.Unordered); | ||
using var channel = query_read.GetDefaultChannel(); | ||
channel.ApplyAggregate(AggregateOperation.Count, "Count"); | ||
channel.ApplyAggregate(AggregateOperation.Unary(AggregateOperator.Sum, "a"), "Sum"); | ||
query_read.SetDataBuffer("Count", count); | ||
query_read.SetDataBuffer("Sum", sum); | ||
query_read.Submit(); | ||
array_read.Close(); | ||
} | ||
private static void ReadArray() | ||
{ | ||
ulong[] count = [0]; | ||
long[] sum = [0]; | ||
|
||
Console.WriteLine($"Count: {count[0]}"); | ||
Console.WriteLine($"Sum: {sum[0]}"); | ||
using (var array_read = new Array(Ctx, ArrayPath)) | ||
{ | ||
array_read.Open(QueryType.Read); | ||
using var query_read = new Query(array_read); | ||
query_read.SetLayout(LayoutType.Unordered); | ||
using var channel = query_read.GetDefaultChannel(); | ||
channel.ApplyAggregate(AggregateOperation.Count, "Count"); | ||
channel.ApplyAggregate(AggregateOperation.Unary(AggregateOperator.Sum, "a"), "Sum"); | ||
query_read.SetDataBuffer("Count", count); | ||
query_read.SetDataBuffer("Sum", sum); | ||
query_read.Submit(); | ||
array_read.Close(); | ||
} | ||
|
||
public static void Run() | ||
{ | ||
if (Directory.Exists(ArrayPath)) | ||
{ | ||
Directory.Delete(ArrayPath, true); | ||
} | ||
Console.WriteLine($"Count: {count[0]}"); | ||
Console.WriteLine($"Sum: {sum[0]}"); | ||
} | ||
|
||
CreateArray(); | ||
WriteArray(); | ||
ReadArray(); | ||
public static void Run() | ||
{ | ||
if (Directory.Exists(ArrayPath)) | ||
{ | ||
Directory.Delete(ArrayPath, true); | ||
} | ||
|
||
CreateArray(); | ||
WriteArray(); | ||
ReadArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.