Skip to content

Commit 7e51db1

Browse files
committed
Merge remote-tracking branch 'origin/main' into tableService
# Conflicts: # src/Ydb.Sdk/src/Services/Table/TableClient.cs # src/Ydb.Sdk/tests/Utils.cs
2 parents d56e211 + 5ccb9cd commit 7e51db1

File tree

93 files changed

+3340
-82
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+3340
-82
lines changed

.github/workflows/lint.yml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@ on:
88

99
jobs:
1010
autoformatter:
11+
strategy:
12+
matrix:
13+
source-dir: ["./src/", "./examples/src/", "./slo/src/"]
14+
include:
15+
- source-dir: "./src/"
16+
solutionFile: "YdbSdk.sln"
17+
- source-dir: "./examples/src/"
18+
solutionFile: "YdbExamples.sln"
19+
- source-dir: "./slo/src/"
20+
solutionFile: "src.sln"
1121
name: autoformat check
12-
concurrency:
13-
group: lint-autoformat-${{ github.ref }}
14-
cancel-in-progress: true
1522
runs-on: ubuntu-latest
1623
steps:
1724
- name: Checkout
@@ -21,15 +28,18 @@ jobs:
2128
with:
2229
dotnet-version: '6.0.x'
2330
- name: Restore
24-
run: dotnet restore ./src/YdbSdk.sln
31+
run: dotnet restore ${{ matrix.source-dir }}${{ matrix.solutionFile }}
2532
- name: Install ReSharper
26-
run: dotnet tool install -g JetBrains.ReSharper.GlobalTools
33+
run: dotnet tool install -g JetBrains.ReSharper.GlobalTools --version 2023.2.1
2734
- name: format all files with auto-formatter
28-
run: bash ./.github/scripts/format-all-dotnet-code.sh ./src/ YdbSdk.sln "Custom Cleanup"
35+
run: bash ./.github/scripts/format-all-dotnet-code.sh ${{ matrix.source-dir }} ${{ matrix.solutionFile }} "Custom Cleanup"
2936
- name: Check repository diff
3037
run: bash ./.github/scripts/check-work-copy-equals-to-committed.sh "auto-format broken"
3138

3239
inspection:
40+
strategy:
41+
matrix:
42+
solutionPath: ["./src/YdbSdk.sln", "./examples/src/YdbExamples.sln", "./slo/src/src.sln"]
3343
runs-on: ubuntu-latest
3444
name: Inspection
3545
steps:
@@ -40,11 +50,11 @@ jobs:
4050
with:
4151
dotnet-version: '6.0.x'
4252
- name: Restore
43-
run: dotnet restore ./src/YdbSdk.sln
53+
run: dotnet restore ${{ matrix.solutionPath }}
4454
- name: Inspect code
4555
uses: muno92/resharper_inspectcode@v1
4656
with:
47-
solutionPath: ./src/YdbSdk.sln
57+
solutionPath: ${{ matrix.solutionPath }}
4858
version: 2023.2.1
4959
include: |
5060
**.cs

.github/workflows/slo.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
on:
2+
push:
3+
branches: [main]
4+
pull_request:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
name: SLO
9+
10+
jobs:
11+
test-slo:
12+
concurrency:
13+
group: slo-${{ github.ref }}
14+
if: (!contains(github.event.pull_request.labels.*.name, 'no slo'))
15+
16+
runs-on: ubuntu-latest
17+
name: SLO test
18+
permissions:
19+
checks: write
20+
pull-requests: write
21+
contents: read
22+
issues: write
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v3
27+
if: env.DOCKER_REPO != null
28+
env:
29+
DOCKER_REPO: ${{ secrets.SLO_DOCKER_REPO }}
30+
31+
- name: Run SLO
32+
uses: ydb-platform/slo-tests@php-version
33+
if: env.DOCKER_REPO != null
34+
env:
35+
DOCKER_REPO: ${{ secrets.SLO_DOCKER_REPO }}
36+
with:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
KUBECONFIG_B64: ${{ secrets.SLO_KUBE_CONFIG }}
39+
AWS_CREDENTIALS_B64: ${{ secrets.SLO_AWS_CREDENTIALS }}
40+
AWS_CONFIG_B64: ${{ secrets.SLO_AWS_CONFIG }}
41+
DOCKER_USERNAME: ${{ secrets.SLO_DOCKER_USERNAME }}
42+
DOCKER_PASSWORD: ${{ secrets.SLO_DOCKER_PASSWORD }}
43+
DOCKER_REPO: ${{ secrets.SLO_DOCKER_REPO }}
44+
DOCKER_FOLDER: ${{ secrets.SLO_DOCKER_FOLDER }}
45+
s3_endpoint: ${{ secrets.SLO_S3_ENDPOINT }}
46+
s3_images_folder: ${{ vars.SLO_S3_IMAGES_FOLDER }}
47+
grafana_domain: ${{ vars.SLO_GRAFANA_DOMAIN }}
48+
# grafana_dashboard: ${{ vars.SLO_GRAFANA_DASHBOARD }}
49+
grafana_dashboard: dca60386-0d3d-43f5-a2af-5f3fd3e3b295
50+
grafana_dashboard_width: 2000
51+
grafana_dashboard_height: 2300
52+
ydb_version: 'newest'
53+
timeBetweenPhases: 30
54+
shutdownTime: 30
55+
56+
language_id0: 'dotnet'
57+
workload_path0: 'slo/src'
58+
language0: '.NET SDK'
59+
workload_build_context0: ../..
60+
workload_build_options0: -f Dockerfile
61+
62+
- uses: actions/upload-artifact@v3
63+
if: always() && env.DOCKER_REPO != null
64+
env:
65+
DOCKER_REPO: ${{ secrets.SLO_DOCKER_REPO }}
66+
with:
67+
name: slo-logs
68+
path: logs/

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## v0.1.5
2+
- Fix timeout error on create session
3+
- Fix transport error on delete session
4+
5+
## v0.1.4
6+
- Add exception throwing when results truncated
7+
- lint: add line feed at file end
8+
9+
## v0.1.3
110
- Add static auth
211
## v0.1.1
312
- Add static code analysis

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@ foreach (var row in resultSet.Rows)
9292

9393
## Examples
9494

95-
See **[ydb-dotnet-examples](https://github.com/ydb-platform/ydb-dotnet-examples)**.
95+
See **[examples folder](https://github.com/ydb-platform/ydb-dotnet-sdk/tree/main/examples)**

examples/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# YDB .NET SDK Examples
2+
3+
## Prerequisites
4+
.NET 6
5+
6+
## Running examples
7+
8+
1. Clone repository
9+
```bash
10+
git clone https://github.com/ydb-platform/ydb-dotnet-sdk.git
11+
```
12+
13+
2. Build solution
14+
```bash
15+
cd ydb-dotnet-sdk/examples/src
16+
dotnet build
17+
```
18+
19+
3. Run example
20+
```bash
21+
cd <ExampleName>
22+
dotnet run -e <Endpoint> -d <Database>
23+
```
24+
25+
## Provided examples
26+
27+
### BasicExample
28+
Demonstrates basic operations with YDB, including:
29+
* Driver initialization
30+
* Table client initialization
31+
* Table creation via SchemeQuery (DDL)
32+
* Data queries (OLTP) & transactions (read, modify)
33+
* Interactive transactions
34+
* ReadTable for streaming read of table contents
35+
* ScanQuery for streaming wide queries (OLAP)
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System;
2+
using System.Security.Cryptography.X509Certificates;
3+
using System.Threading.Tasks;
4+
using Microsoft.Extensions.Logging;
5+
using Ydb.Sdk.Auth;
6+
using Ydb.Sdk.Services.Table;
7+
8+
namespace Ydb.Sdk.Examples;
9+
10+
internal partial class BasicExample : TableExampleBase
11+
{
12+
private BasicExample(TableClient client, string database, string path)
13+
: base(client, database, path)
14+
{
15+
}
16+
17+
public static async Task Run(
18+
string endpoint,
19+
string database,
20+
ICredentialsProvider credentialsProvider,
21+
X509Certificate? customServerCertificate,
22+
string path,
23+
ILoggerFactory loggerFactory)
24+
{
25+
var config = new DriverConfig(
26+
endpoint: endpoint,
27+
database: database,
28+
credentials: credentialsProvider,
29+
customServerCertificate: customServerCertificate
30+
);
31+
32+
await using var driver = await Driver.CreateInitialized(
33+
config: config,
34+
loggerFactory: loggerFactory
35+
);
36+
37+
using var tableClient = new TableClient(driver, new TableClientConfig());
38+
39+
var example = new BasicExample(tableClient, database, path);
40+
41+
await example.SchemeQuery();
42+
await example.FillData();
43+
await example.SimpleSelect(1);
44+
await example.SimpleUpsert(10, "Coming soon", DateTime.UtcNow);
45+
await example.SimpleSelect(10);
46+
await example.InteractiveTx();
47+
await example.ReadTable();
48+
await example.ScanQuery(DateTime.Parse("2007-01-01"));
49+
}
50+
51+
private static ExecuteDataQuerySettings DefaultDataQuerySettings =>
52+
new()
53+
{
54+
// Indicates that client is no longer interested in the result of operation after the
55+
// specified duration starting from the moment when operation arrives at the server.
56+
// Status code TIMEOUT will be returned from server in case when operation result in
57+
// not available in the specified time period. This status code doesn't indicate the result
58+
// of operation, it might be completed or cancelled.
59+
OperationTimeout = TimeSpan.FromSeconds(1),
60+
61+
// Transport timeout from the moment operation was sent to server. It is useful in case
62+
// of possible network issues, to that query doesn't hang forever.
63+
// It is recommended to set this value to a larger value than OperationTimeout to give
64+
// server some time to issue a response.
65+
TransportTimeout = TimeSpan.FromSeconds(5),
66+
67+
// Keep query compilation result in query cache or not. Should be false for ad-hoc queries,
68+
// and true (default) for high-RPS queries.
69+
KeepInQueryCache = false
70+
};
71+
72+
private ExecuteDataQuerySettings DefaultCachedDataQuerySettings
73+
{
74+
get
75+
{
76+
var settings = DefaultDataQuerySettings;
77+
settings.KeepInQueryCache = true;
78+
return settings;
79+
}
80+
}
81+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
4+
<PropertyGroup>
5+
<OutputType>Exe</OutputType>
6+
<TargetFramework>net6.0</TargetFramework>
7+
<Nullable>enable</Nullable>
8+
<AssemblyName>Ydb.Sdk.Examples.BasicExample</AssemblyName>
9+
<RootNamespace>Ydb.Sdk.Examples</RootNamespace>
10+
</PropertyGroup>
11+
12+
<PropertyGroup>
13+
<RepositoryType>git</RepositoryType>
14+
<RepositoryUrl>https://github.com/ydb-platform/ydb-dotnet-examples</RepositoryUrl>
15+
<PackageProjectUrl>https://github.com/ydb-platform/ydb-dotnet-examples</PackageProjectUrl>
16+
<Company>YANDEX LLC</Company>
17+
</PropertyGroup>
18+
19+
<ItemGroup>
20+
<PackageReference Include="CommandLineParser" Version="2.8.0" />
21+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<ProjectReference Include="..\Common\Common.csproj" />
26+
</ItemGroup>
27+
28+
</Project>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
using Ydb.Sdk.Services.Table;
5+
using Ydb.Sdk.Value;
6+
7+
namespace Ydb.Sdk.Examples;
8+
9+
internal partial class BasicExample
10+
{
11+
private async Task SimpleSelect(ulong id)
12+
{
13+
var response = await Client.SessionExec(async session =>
14+
{
15+
var query = @$"
16+
PRAGMA TablePathPrefix('{BasePath}');
17+
18+
DECLARE $id AS Uint64;
19+
20+
SELECT
21+
series_id,
22+
title,
23+
release_date
24+
FROM series
25+
WHERE series_id = $id;
26+
";
27+
28+
return await session.ExecuteDataQuery(
29+
query: query,
30+
txControl: TxControl.BeginSerializableRW().Commit(),
31+
parameters: new Dictionary<string, YdbValue>
32+
{
33+
{ "$id", YdbValue.MakeUint64(id) }
34+
},
35+
settings: DefaultCachedDataQuerySettings
36+
);
37+
});
38+
39+
response.Status.EnsureSuccess();
40+
41+
var queryResponse = (ExecuteDataQueryResponse)response;
42+
var resultSet = queryResponse.Result.ResultSets[0];
43+
44+
Console.WriteLine($"> SimpleSelect, " +
45+
$"columns: {resultSet.Columns.Count}, " +
46+
$"rows: {resultSet.Rows.Count}, " +
47+
$"truncated: {resultSet.Truncated}");
48+
49+
foreach (var row in resultSet.Rows)
50+
{
51+
Console.WriteLine($"> Series, " +
52+
$"series_id: {(ulong?)row["series_id"]}, " +
53+
$"title: {(string?)row["title"]}, " +
54+
$"release_date: {(DateTime?)row["release_date"]}");
55+
}
56+
}
57+
58+
private async Task SimpleUpsert(ulong id, string title, DateTime date)
59+
{
60+
var response = await Client.SessionExec(async session =>
61+
{
62+
var query = @$"
63+
PRAGMA TablePathPrefix('{BasePath}');
64+
65+
DECLARE $id AS Uint64;
66+
DECLARE $title AS Utf8;
67+
DECLARE $release_date AS Date;
68+
69+
UPSERT INTO series (series_id, title, release_date) VALUES
70+
($id, $title, $release_date);
71+
";
72+
73+
return await session.ExecuteDataQuery(
74+
query: query,
75+
txControl: TxControl.BeginSerializableRW().Commit(),
76+
parameters: new Dictionary<string, YdbValue>
77+
{
78+
{ "$id", YdbValue.MakeUint64(id) },
79+
{ "$title", YdbValue.MakeUtf8(title) },
80+
{ "$release_date", YdbValue.MakeDate(date) }
81+
},
82+
settings: DefaultCachedDataQuerySettings
83+
);
84+
});
85+
86+
response.Status.EnsureSuccess();
87+
}
88+
}

0 commit comments

Comments
 (0)