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

Add exception throwing when results truncated #50

Merged
merged 6 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Restore
run: dotnet restore ./src/YdbSdk.sln
- name: Install ReSharper
run: dotnet tool install -g JetBrains.ReSharper.GlobalTools
run: dotnet tool install -g JetBrains.ReSharper.GlobalTools --version 2023.2.1
- name: format all files with auto-formatter
run: bash ./.github/scripts/format-all-dotnet-code.sh ./src/ YdbSdk.sln "Custom Cleanup"
- name: Check repository diff
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Add exception throwing when results truncated
- lint: add line feed at file end

## v0.1.3
Expand Down
9 changes: 9 additions & 0 deletions src/Ydb.Sdk/src/Services/Table/ExecuteDataQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Ydb.Sdk.Services.Table;
public class ExecuteDataQuerySettings : OperationRequestSettings
{
public bool KeepInQueryCache { get; set; } = true;
public bool AllowTruncated { get; set; }
}

public class ExecuteDataQueryResponse : ResponseWithResultBase<ExecuteDataQueryResponse.ResultData>
Expand Down Expand Up @@ -103,6 +104,10 @@ public async Task<ExecuteDataQueryResponse> ExecuteDataQuery(
if (status.IsSuccess && resultProto != null)
{
result = ExecuteDataQueryResponse.ResultData.FromProto(resultProto);
if (!settings.AllowTruncated && result.ResultSets.Any(set => set.Truncated))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need tests

{
throw new TruncateException();
}
}

return new ExecuteDataQueryResponse(status, txState, tx, result);
Expand All @@ -121,3 +126,7 @@ public async Task<ExecuteDataQueryResponse> ExecuteDataQuery(
return await ExecuteDataQuery(query, txControl, new Dictionary<string, YdbValue>(), settings);
}
}

public class TruncateException : Exception
{
}
79 changes: 79 additions & 0 deletions src/Ydb.Sdk/tests/Table/Truncated.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Xunit;
using Ydb.Sdk.Services.Table;
using Ydb.Sdk.Value;

namespace Ydb.Sdk.Tests.Table;

[Trait("Category", "Integration")]
public class Truncated
{
private readonly ILoggerFactory _loggerFactory;

private readonly DriverConfig _driverConfig = new(
endpoint: "grpc://localhost:2136",
database: "/local"
);

public Truncated()
{
_loggerFactory = Utils.GetLoggerFactory() ?? NullLoggerFactory.Instance;
}


[Fact]
public async Task NotAllowTruncated()
{
await using var driver = await Driver.CreateInitialized(_driverConfig, _loggerFactory);
using var tableClient = new TableClient(driver);


const string query = "SELECT * FROM AS_TABLE($data)";
var parameters = new Dictionary<string, YdbValue> { { "$data", MakeData(1001) } };

await Assert.ThrowsAsync<TruncateException>(async () => await tableClient.SessionExec(async session =>
await session.ExecuteDataQuery(
query: query,
parameters: parameters,
txControl: TxControl.BeginSerializableRW().Commit()
)
));
}

[Fact]
public async Task AllowTruncated()
{
await using var driver = await Driver.CreateInitialized(_driverConfig, _loggerFactory);
using var tableClient = new TableClient(driver);


const string query = "SELECT * FROM AS_TABLE($data)";
var parameters = new Dictionary<string, YdbValue> { { "$data", MakeData(1001) } };
var settings = new ExecuteDataQuerySettings { AllowTruncated = true };

var response = await tableClient.SessionExec(async session =>
await session.ExecuteDataQuery(
query: query,
parameters: parameters,
txControl: TxControl.BeginSerializableRW().Commit(),
settings: settings)
);

Assert.True(response.Status.IsSuccess);
}

private static YdbValue MakeData(int n)
{
return YdbValue.MakeList(
Enumerable.Range(0, n)
.Select(i => YdbValue.MakeStruct(
new Dictionary<string, YdbValue>
{
{ "id", (YdbValue)i }
}
))
.ToList()
);
}
}
8 changes: 8 additions & 0 deletions src/Ydb.Sdk/tests/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ internal static ServiceProvider GetServiceProvider()
var serviceProvider = GetServiceProvider();
return serviceProvider.GetService<ILoggerFactory>();
}

internal static async Task<ExecuteSchemeQueryResponse> CreateSimpleTable(
TableClient tableClient, string tableName, string columnName = "key")
{
return await ExecuteSchemeQuery(
tableClient,
query: $"CREATE TABLE {tableName} ({columnName} Uint64, PRIMARY KEY ({columnName}))");
}
}
11 changes: 6 additions & 5 deletions src/YdbSdk.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml"
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=Custom_0020Cleanup/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="Custom Cleanup"&gt;&lt;CppCodeStyleCleanupDescriptor ArrangeBraces="True" ArrangeAuto="True" ArrangeFunctionDeclarations="True" ArrangeNestedNamespaces="True" ArrangeTypeAliases="True" ArrangeCVQualifiers="True" ArrangeSlashesInIncludeDirectives="True" ArrangeOverridingFunctions="True" SortIncludeDirectives="True" SortMemberInitializers="True" /&gt;&lt;CppReformatCode&gt;True&lt;/CppReformatCode&gt;&lt;CSCodeStyleAttributes ArrangeVarStyle="True" ArrangeTypeAccessModifier="True" ArrangeTypeMemberAccessModifier="True" SortModifiers="True" AddMissingParentheses="True" ArrangeAttributes="True" ArrangeCodeBodyStyle="True" ArrangeTrailingCommas="True" ArrangeObjectCreation="True" ArrangeDefaultValue="True" RemoveRedundantParentheses="True" ArrangeNamespaces="True" /&gt;&lt;FSReformatCode&gt;True&lt;/FSReformatCode&gt;&lt;ShaderLabReformatCode&gt;True&lt;/ShaderLabReformatCode&gt;&lt;Xaml.RedundantFreezeAttribute&gt;True&lt;/Xaml.RedundantFreezeAttribute&gt;&lt;Xaml.RemoveRedundantModifiersAttribute&gt;True&lt;/Xaml.RemoveRedundantModifiersAttribute&gt;&lt;Xaml.RemoveRedundantNameAttribute&gt;True&lt;/Xaml.RemoveRedundantNameAttribute&gt;&lt;Xaml.RemoveRedundantResource&gt;True&lt;/Xaml.RemoveRedundantResource&gt;&lt;Xaml.RemoveRedundantCollectionProperty&gt;True&lt;/Xaml.RemoveRedundantCollectionProperty&gt;&lt;Xaml.RemoveRedundantAttachedPropertySetter&gt;True&lt;/Xaml.RemoveRedundantAttachedPropertySetter&gt;&lt;Xaml.RemoveRedundantStyledValue&gt;True&lt;/Xaml.RemoveRedundantStyledValue&gt;&lt;Xaml.RemoveRedundantNamespaceAlias&gt;True&lt;/Xaml.RemoveRedundantNamespaceAlias&gt;&lt;Xaml.RemoveForbiddenResourceName&gt;True&lt;/Xaml.RemoveForbiddenResourceName&gt;&lt;Xaml.RemoveRedundantGridDefinitionsAttribute&gt;True&lt;/Xaml.RemoveRedundantGridDefinitionsAttribute&gt;&lt;Xaml.RemoveRedundantUpdateSourceTriggerAttribute&gt;True&lt;/Xaml.RemoveRedundantUpdateSourceTriggerAttribute&gt;&lt;Xaml.RemoveRedundantBindingModeAttribute&gt;True&lt;/Xaml.RemoveRedundantBindingModeAttribute&gt;&lt;Xaml.RemoveRedundantGridSpanAttribut&gt;True&lt;/Xaml.RemoveRedundantGridSpanAttribut&gt;&lt;XMLReformatCode&gt;True&lt;/XMLReformatCode&gt;&lt;CSArrangeQualifiers&gt;True&lt;/CSArrangeQualifiers&gt;&lt;CSFixBuiltinTypeReferences&gt;True&lt;/CSFixBuiltinTypeReferences&gt;&lt;HtmlReformatCode&gt;True&lt;/HtmlReformatCode&gt;&lt;VBReformatCode&gt;True&lt;/VBReformatCode&gt;&lt;CSReformatCode&gt;True&lt;/CSReformatCode&gt;&lt;FormatAttributeQuoteDescriptor&gt;True&lt;/FormatAttributeQuoteDescriptor&gt;&lt;IDEA_SETTINGS&gt;&amp;lt;profile version="1.0"&amp;gt;
&amp;lt;option name="myName" value="Custom Cleanup" /&amp;gt;
&amp;lt;inspection_tool class="ES6ShorthandObjectProperty" enabled="false" level="INFORMATION" enabled_by_default="false" /&amp;gt;
Expand Down Expand Up @@ -70,4 +67,8 @@
&amp;lt;Reformat&amp;gt;true&amp;lt;/Reformat&amp;gt;
&amp;lt;/Language&amp;gt;
&amp;lt;/profile&amp;gt;&lt;/RIDER_SETTINGS&gt;&lt;CSUseAutoProperty&gt;True&lt;/CSUseAutoProperty&gt;&lt;CSMakeFieldReadonly&gt;True&lt;/CSMakeFieldReadonly&gt;&lt;CSMakeAutoPropertyGetOnly&gt;True&lt;/CSMakeAutoPropertyGetOnly&gt;&lt;RemoveCodeRedundancies&gt;True&lt;/RemoveCodeRedundancies&gt;&lt;CSOptimizeUsings&gt;&lt;OptimizeUsings&gt;True&lt;/OptimizeUsings&gt;&lt;/CSOptimizeUsings&gt;&lt;CSShortenReferences&gt;True&lt;/CSShortenReferences&gt;&lt;/Profile&gt;</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/LINE_FEED_AT_FILE_END/@EntryValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/LINE_FEED_AT_FILE_END/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>