Skip to content

Commit 01a6ee9

Browse files
committed
netstandard2.1
1 parent 1b8b1d0 commit 01a6ee9

File tree

10 files changed

+66
-38
lines changed

10 files changed

+66
-38
lines changed

.github/workflows/dotnet.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ jobs:
150150
ls -lahS src/chdb/*
151151
cp libchdb.so src/chdb/
152152
ls -lahS src/chdb/libchdb*
153+
dontnet nuget sources add -n chdb ./nupkg
153154
dotnet pack src/chdb-tool/chdb-tool.csproj -c Release --include-symbols --version-suffix ${{ github.run_number }}
154155
ls -lahS nupkg
155156

Directory.Build.props

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<Project>
22
<PropertyGroup>
3-
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
43
<RuntimeIdentifiers>linux-x64;osx-x64</RuntimeIdentifiers>
54
<ImplicitUsings>enable</ImplicitUsings>
65
<Nullable>enable</Nullable>
@@ -13,7 +12,7 @@
1312
<GenerateDocumentationFile>True</GenerateDocumentationFile>
1413
<EnablePackageValidation>true</EnablePackageValidation>
1514
<PackageOutputPath>../../nupkg</PackageOutputPath>
16-
<Version>0.0.2.0$(GITHUB_RUN_NUMBER)</Version>
15+
<Version>0.0.3.0$(GITHUB_RUN_NUMBER)</Version>
1716
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
1817
<PackageVersion Condition="'$(BuildNumber)' != ''">$(Version).$(BuildNumber)</PackageVersion>
1918
<Authors>vilinski</Authors>

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ Probably you better served using the clickhouse client and run `clickhouse local
5252
Requires .NET SDK 6.0 or later.
5353

5454
```bash
55-
#dotnet tool install --global chdb-tool-<OS>-<ARCH>
56-
dotnet tool install --global chdb-tool-linux-x64
55+
dotnet tool install --global chdb-tool
5756
```
5857

5958
OS supported: linux, osx

src/chdb-tool/Program.cs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,28 @@ void PrintHelp()
2121
if (args.Length == 0 || args[0] == "--help" || args[0] == "-h")
2222
{
2323
PrintHelp();
24-
return;
2524
}
26-
if (args[0] == "--version" || args[0] == "-v")
25+
else if (args[0] == "--version" || args[0] == "-v")
2726
{
2827
PrintVersion();
29-
return;
3028
}
31-
try
32-
{
33-
var result = ChDb.ChDb.Query(args[0], args.Length > 1 && !args[1].StartsWith('-') ? args[1] : "PrettyCompact");
34-
if (result == null)
35-
return; // TODO behavior changed in 1.2.1
36-
Console.WriteLine(result.Buf);
37-
if (!args.Contains("--quiet") && !args.Contains("-q"))
29+
else
30+
try
3831
{
39-
Console.WriteLine($"Elapsed: {result.Elapsed} s, read {result.RowsRead} rows, {result.BytesRead} bytes" +
40-
$", {result.RowsRead / result.Elapsed.TotalSeconds:F0} rows/s, {result.BytesRead / result.Elapsed.TotalSeconds:F0} bytes/s");
41-
if (!string.IsNullOrWhiteSpace(result.ErrorMessage))
42-
Console.Error.WriteLine("Error message: " + result.ErrorMessage);
32+
var result = ChDb.ChDb.Query(args[0], args.Length > 1 && !args[1].StartsWith('-') ? args[1] : "PrettyCompact");
33+
if (result == null)
34+
return; // TODO behavior changed in 1.2.1
35+
Console.WriteLine(result.Text);
36+
if (!args.Contains("--quiet") && !args.Contains("-q"))
37+
{
38+
Console.WriteLine($"Elapsed: {result.Elapsed} s, read {result.RowsRead} rows, {result.BytesRead} bytes" +
39+
$", {result.RowsRead / result.Elapsed.TotalSeconds:F0} rows/s, {result.BytesRead / result.Elapsed.TotalSeconds:F0} bytes/s");
40+
if (!string.IsNullOrWhiteSpace(result.ErrorMessage))
41+
Console.Error.WriteLine("Error message: " + result.ErrorMessage);
42+
}
43+
}
44+
catch (ArgumentException e)
45+
{
46+
Console.Error.WriteLine(e.Message);
47+
Environment.Exit(1);
4348
}
44-
}
45-
catch (ArgumentException e)
46-
{
47-
Console.Error.WriteLine(e.Message);
48-
Environment.Exit(1);
49-
}

src/chdb-tool/chdb-tool.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
</ItemGroup>
1212

1313
<PropertyGroup>
14+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
1415
<OutputType>Exe</OutputType>
1516
<PackAsTool>true</PackAsTool>
1617
<ToolCommandName>chdb</ToolCommandName>

src/chdb/ChDb.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public static class ChDb
3333
/// </remarks>
3434
public static LocalResult? Query(string query, string? format = null)
3535
{
36-
ArgumentNullException.ThrowIfNull(query);
36+
if (query is null)
37+
throw new ArgumentNullException(nameof(query));
3738
var argv = new[] {
3839
"clickhouse",
3940
"--multiquery",
@@ -49,7 +50,7 @@ public static class ChDb
4950
{
5051
var prefix = $"--{key}=";
5152
if (arg.StartsWith(prefix))
52-
return arg[prefix.Length..];
53+
return arg.Substring(prefix.Length);
5354
}
5455
return null;
5556
}

src/chdb/LocalResult.cs

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,41 @@ namespace ChDb;
55
/// <summary>
66
/// The query result.
77
/// </summary>
8-
/// <param name="Buf">Result buffer.</param>
9-
/// <param name="ErrorMessage">Error message if occured.</param>
10-
/// <param name="RowsRead">Number of rows read</param>
11-
/// <param name="BytesRead">Number of bytes read</param>
12-
/// <param name="Elapsed">Query time elapsed, in seconds.</param>
13-
public record LocalResult(byte[]? Buf, string? ErrorMessage, ulong RowsRead, ulong BytesRead, TimeSpan Elapsed)
8+
public record LocalResult
149
{
10+
public byte[]? Buf { get; }
11+
public string? ErrorMessage { get; }
1512
/// <summary>
1613
/// By text formats contains a result text.
1714
/// </summary>
1815
public string? Text => Buf == null ? null : System.Text.Encoding.UTF8.GetString(Buf);
16+
public ulong RowsRead { get; }
17+
public ulong BytesRead { get; }
18+
public TimeSpan Elapsed { get; }
19+
20+
/// <param name="Buf">Result buffer.</param>
21+
/// <param name="ErrorMessage">Error message if occured.</param>
22+
/// <param name="RowsRead">Number of rows read</param>
23+
/// <param name="BytesRead">Number of bytes read</param>
24+
/// <param name="Elapsed">Query time elapsed, in seconds.</param>
25+
public LocalResult(byte[]? Buf, string? ErrorMessage, ulong RowsRead, ulong BytesRead, TimeSpan Elapsed)
26+
{
27+
this.Buf = Buf;
28+
this.ErrorMessage = ErrorMessage;
29+
this.RowsRead = RowsRead;
30+
this.BytesRead = BytesRead;
31+
this.Elapsed = Elapsed;
32+
}
1933

2034
internal static LocalResult? FromPtr(nint ptr)
2135
{
22-
Handle? h = null;
2336
if (ptr == IntPtr.Zero)
2437
return null;
25-
h = Marshal.PtrToStructure<Handle>(ptr);
38+
var h = Marshal.PtrToStructure<Handle>(ptr);
2639
if (h == null)
2740
return null;
2841

29-
var errorMessage = h.error_message == IntPtr.Zero ? null : Marshal.PtrToStringUTF8(h.error_message);
42+
var errorMessage = h.error_message == IntPtr.Zero ? null : MarshalPtrToStringUTF8(h.error_message);
3043
if (errorMessage != null)
3144
return new LocalResult(null, errorMessage, 0, 0, TimeSpan.Zero);
3245

@@ -38,6 +51,18 @@ public record LocalResult(byte[]? Buf, string? ErrorMessage, ulong RowsRead, ulo
3851
return new LocalResult(buf, errorMessage, h.rows_read, h.bytes_read, elapsed);
3952
}
4053

54+
private static string MarshalPtrToStringUTF8(nint ptr)
55+
{
56+
unsafe
57+
{
58+
var str = (byte*)ptr;
59+
var length = 0;
60+
for (var i = str; *i != 0; i++, length++) ;
61+
var clrString = System.Text.Encoding.UTF8.GetString(str, length);
62+
return clrString;
63+
}
64+
}
65+
4166
[StructLayout(LayoutKind.Sequential)]
4267
internal class Handle
4368
{

src/chdb/Session.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ public record Session : IDisposable
55
/// <summary>
66
/// Output format for queries if not explicitely specified. Default is TabSeparated
77
/// </summary>
8-
public string? Format { get; init; }
8+
public string? Format { get; set; }
99
/// <summary>
1010
/// Path to the ClickHouse data directory. If not set, a temporary directory will be used.
1111
/// </summary>
1212
public string? DataPath { get; set; } = Path.Combine(Path.GetTempPath(), "chdb_");
1313
/// <summary>
1414
/// Query Log Level.
1515
/// </summary>
16-
public string? LogLevel { get; init; }
16+
public string? LogLevel { get; set; }
1717
/// <summary>
1818
/// Whether to delete the data directory on dispose. Default is true.
1919
/// </summary>
20-
public bool IsTemp { get; init; } = true;
20+
public bool IsTemp { get; set; } = true;
2121

2222
public void Dispose()
2323
{

src/chdb/chdb.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
<PropertyGroup>
44
<InternalsVisibleTo>tests</InternalsVisibleTo>
5+
<TargetFramework>netstandard2.1</TargetFramework>
56
<!-- <PackageId Condition="$(IsLinuxX64) == true" >chdb-linux-x64</PackageId>
67
<PackageId Condition="$(IsLinuxArm64) == true" >chdb-linux-arm64</PackageId>
78
<PackageId Condition="$(IsOsxX64) == true" >chdb-osx-x64</PackageId>
89
<PackageId Condition="$(IsOsxArm64) == true" >chdb-osx-arm64</PackageId> -->
910
<PackageId>chdb</PackageId>
1011
<Title>chdb</Title>
1112
<Description>chdb native bindings for dotnet core</Description>
13+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1214
</PropertyGroup>
1315

1416
<ItemGroup>

test/ChDbTest/test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
45
<IsPackable>false</IsPackable>
56
<IsTestProject>true</IsTestProject>
67
</PropertyGroup>

0 commit comments

Comments
 (0)