From 8310f19cfffe4889057a9580464f39de0cc55d50 Mon Sep 17 00:00:00 2001 From: XmasApple Date: Thu, 5 Oct 2023 18:47:39 +0300 Subject: [PATCH] TableDescribe add protobuf wrappers --- src/Ydb.Sdk/src/Driver.cs | 2 + src/Ydb.Sdk/src/Services/Table/CopyTable.cs | 27 +-- src/Ydb.Sdk/src/Services/Table/CreateTable.cs | 127 +++++++++-- .../src/Services/Table/DescribeTable.cs | 143 ++++++++++-- .../Services/Table/DescribeTableOptions.cs | 28 +-- src/Ydb.Sdk/src/Services/Table/DropTable.cs | 2 +- src/Ydb.Sdk/src/Services/Table/ReadTable.cs | 2 +- src/Ydb.Sdk/src/Services/Table/RenameTable.cs | 29 ++- src/Ydb.Sdk/src/Services/Table/Shared.cs | 100 -------- .../Table/Shared/PartitioningSettings.cs | 47 ++++ .../Table/Shared/ReadReplicasSettings.cs | 62 +++++ .../src/Services/Table/Shared/SharedEnums.cs | 53 +++++ .../src/Services/Table/Shared/StoragePool.cs | 23 ++ .../Services/Table/Shared/StorageSettings.cs | 39 ++++ .../src/Services/Table/Shared/TtlSettings.cs | 169 ++++++++++++++ src/Ydb.Sdk/src/Services/Table/TableClient.cs | 2 + src/Ydb.Sdk/src/Value/YdbValue.cs | 6 + src/Ydb.Sdk/src/Value/YdbValueTypeBuilder.cs | 215 ++++++++++++++---- .../tests/TableService/TestCopyTable.cs | 10 +- .../tests/TableService/TestCreateTable.cs | 8 +- .../tests/TableService/TestDescribeTable.cs | 2 +- .../tests/TableService/TestDropTable.cs | 2 +- .../tests/TableService/TestRenameTable.cs | 4 +- 23 files changed, 866 insertions(+), 236 deletions(-) delete mode 100644 src/Ydb.Sdk/src/Services/Table/Shared.cs create mode 100644 src/Ydb.Sdk/src/Services/Table/Shared/PartitioningSettings.cs create mode 100644 src/Ydb.Sdk/src/Services/Table/Shared/ReadReplicasSettings.cs create mode 100644 src/Ydb.Sdk/src/Services/Table/Shared/SharedEnums.cs create mode 100644 src/Ydb.Sdk/src/Services/Table/Shared/StoragePool.cs create mode 100644 src/Ydb.Sdk/src/Services/Table/Shared/StorageSettings.cs create mode 100644 src/Ydb.Sdk/src/Services/Table/Shared/TtlSettings.cs diff --git a/src/Ydb.Sdk/src/Driver.cs b/src/Ydb.Sdk/src/Driver.cs index f818d30f..b94aeaf3 100644 --- a/src/Ydb.Sdk/src/Driver.cs +++ b/src/Ydb.Sdk/src/Driver.cs @@ -18,6 +18,8 @@ public class Driver : IDisposable, IAsyncDisposable private readonly string _sdkInfo; private readonly ChannelsCache _channels; private bool _disposed; + + internal string Database => _config.Database; public Driver(DriverConfig config, ILoggerFactory? loggerFactory = null) { diff --git a/src/Ydb.Sdk/src/Services/Table/CopyTable.cs b/src/Ydb.Sdk/src/Services/Table/CopyTable.cs index b0c03593..0a10d384 100644 --- a/src/Ydb.Sdk/src/Services/Table/CopyTable.cs +++ b/src/Ydb.Sdk/src/Services/Table/CopyTable.cs @@ -10,19 +10,19 @@ public class CopyTableItem public string DestinationPath { get; } public bool OmitIndexes { get; } - public CopyTableItem(string sourcePath, string destinationPath, bool omitIndexes = false) + public CopyTableItem(string sourcePath, string destinationPath, bool omitIndexes) { SourcePath = sourcePath; DestinationPath = destinationPath; OmitIndexes = omitIndexes; } - public Ydb.Table.CopyTableItem ToProto() + public Ydb.Table.CopyTableItem GetProto(TableClient tableClient) { return new Ydb.Table.CopyTableItem { - SourcePath = SourcePath, - DestinationPath = DestinationPath, + SourcePath = tableClient.MakeTablePath(SourcePath), + DestinationPath = tableClient.MakeTablePath(DestinationPath), OmitIndexes = OmitIndexes }; } @@ -52,20 +52,15 @@ internal CopyTablesResponse(Status status) : base(status) public partial class TableClient { - public async Task CopyTable(CopyTableItem item, CreateTableSettings? settings = null) - { - return await CopyTable(item.SourcePath, item.DestinationPath); - } - public async Task CopyTable(string sourcePath, string destinationPath, - CreateTableSettings? settings = null) + CopyTableSettings? settings = null) { - settings ??= new CreateTableSettings(); + settings ??= new CopyTableSettings(); var request = new CopyTableRequest { OperationParams = MakeOperationParams(settings), - SourcePath = sourcePath, - DestinationPath = destinationPath + SourcePath = MakeTablePath(sourcePath), + DestinationPath = MakeTablePath(destinationPath) }; try @@ -85,14 +80,14 @@ public async Task CopyTable(string sourcePath, string destina } public async Task CopyTables(List tableItems, - CreateTableSettings? settings = null) + CopyTablesSettings? settings = null) { - settings ??= new CreateTableSettings(); + settings ??= new CopyTablesSettings(); var request = new CopyTablesRequest { OperationParams = MakeOperationParams(settings), }; - request.Tables.AddRange(tableItems.Select(item => item.ToProto())); + request.Tables.AddRange(tableItems.Select(item => item.GetProto(this))); try { diff --git a/src/Ydb.Sdk/src/Services/Table/CreateTable.cs b/src/Ydb.Sdk/src/Services/Table/CreateTable.cs index 4160e2a7..e52ddf9c 100644 --- a/src/Ydb.Sdk/src/Services/Table/CreateTable.cs +++ b/src/Ydb.Sdk/src/Services/Table/CreateTable.cs @@ -4,6 +4,98 @@ namespace Ydb.Sdk.Services.Table; +public class Index +{ + public string Name { get; } + + public List Columns { get; } + + public Index(string name, params string[] columns) + { + Name = name; + Columns = columns.ToList(); + } + + public TableIndex GetTableIndex() + { + return new TableIndex + { + Name = Name, + IndexColumns = { Columns }, + GlobalIndex = new GlobalIndex() + }; + } +} + +public class ColumnFamily +{ + public string Name { get; } + + public StoragePool Data { get; } + + public Ydb.Table.ColumnFamily.Types.Compression Compression { get; } + + public FeatureFlagStatus KeepInMemory { get; } + + public ColumnFamily(string name, StoragePool data, + Ydb.Table.ColumnFamily.Types.Compression compression = Ydb.Table.ColumnFamily.Types.Compression.Unspecified, + FeatureFlagStatus keepInMemory = FeatureFlagStatus.Unspecified) + { + Compression = compression; + Name = name; + Data = data; + KeepInMemory = keepInMemory; + } + + internal ColumnFamily(Ydb.Table.ColumnFamily proto) + { + Compression = proto.Compression; + Name = proto.Name; + Data = new StoragePool(proto.Data); + KeepInMemory = proto.KeepInMemory.FromProto(); + } + + internal Ydb.Table.ColumnFamily GetProto() => + new() + { + Compression = Compression, + Name = Name, + Data = Data.GetProto(), + KeepInMemory = KeepInMemory.GetProto() + }; +} + +public class Column +{ + public string Name { get; } + + public Type Type { get; } + + public string? Family { get; } + + public Column(string name, Type type, string? family = null) + { + Name = name; + Type = type; + Family = family ?? ""; + } + + internal Column(ColumnMeta proto) + { + Name = proto.Name; + Type = proto.Type; + Family = proto.Family; + } + + internal ColumnMeta GetProto() => + new() + { + Name = Name, + Family = Family, + Type = Type + }; +} + public class CreateTableSettings : OperationRequestSettings { public List Columns { get; } = new(); @@ -16,7 +108,7 @@ public class CreateTableSettings : OperationRequestSettings public TtlSettings? TtlSettings { get; private set; } - public StorageSettings StorageSettings { get; private set; } = new(); + public StorageSettings? StorageSettings { get; private set; } public List ColumnFamilies { get; } = new(); @@ -26,13 +118,13 @@ public class CreateTableSettings : OperationRequestSettings public ulong? UniformPartitions { get; private set; } public ExplicitPartitions? PartitionAtKeys { get; private set; } - public PartitioningSettings PartitioningSettings { get; private set; } = new(); + public PartitioningSettings? PartitioningSettings { get; private set; } public string CompactionPolicy { get; private set; } = "default"; - public Ydb.FeatureFlag.Types.Status KeyBloomFilter { get; private set; } = FeatureFlag.Types.Status.Unspecified; + public FeatureFlagStatus KeyBloomFilter { get; private set; } = FeatureFlagStatus.Unspecified; - public ReadReplicasSettings ReadReplicasSettings { get; private set; } = new() { AnyAzReadReplicasCount = 1 }; + public ReadReplicasSettings? ReadReplicasSettings { get; private set; } public CreateTableSettings WithColumn(Column column) { @@ -76,7 +168,7 @@ public CreateTableSettings WithTtlSettings(TtlSettings ttlSettings) return this; } - public CreateTableSettings WithStorageSettings(StorageSettings storageSettings) + public CreateTableSettings WithStorageSettings(StorageSettings? storageSettings) { StorageSettings = storageSettings; return this; @@ -108,13 +200,7 @@ public CreateTableSettings WithAttributes(Dictionary attributes) public CreateTableSettings WithCompactionPolicy(CompactionPolicy compactionPolicy) { - CompactionPolicy = compactionPolicy switch - { - Table.CompactionPolicy.Default => "default", - Table.CompactionPolicy.SmallTable => "small_table", - Table.CompactionPolicy.LogTable => "log_table", - _ => throw new ArgumentOutOfRangeException(nameof(compactionPolicy), compactionPolicy, null) - }; + CompactionPolicy = compactionPolicy.GetString(); return this; } @@ -150,11 +236,6 @@ public CreateTableSettings WithKeyBloomFilter(FeatureFlag.Types.Status keyBloomF public CreateTableSettings WithReadReplicasSettings(ReadReplicasSettings readReplicasSettings) { - if (readReplicasSettings is { AnyAzReadReplicasCount: 0, PerAzReadReplicasCount: 0 }) - { - throw new ArgumentException("readReplicasCount should not be equal to zero"); - } - ReadReplicasSettings = readReplicasSettings; return this; } @@ -185,21 +266,21 @@ public async Task CreateTable(string tablePath, CreateTable var request = new CreateTableRequest { OperationParams = MakeOperationParams(settings), - Path = tablePath, + Path = MakeTablePath(tablePath), Columns = { settings.GetColumnsMeta() }, PrimaryKey = { settings.PrimaryKey }, Profile = settings.Profile, Indexes = { settings.GetTableIndexes() }, - StorageSettings = settings.StorageSettings, + StorageSettings = settings.StorageSettings?.GetProto(), ColumnFamilies = { settings.GetColumnFamilies() }, Attributes = { settings.Attributes }, CompactionPolicy = settings.CompactionPolicy, - PartitioningSettings = settings.PartitioningSettings, - KeyBloomFilter = settings.KeyBloomFilter, - ReadReplicasSettings = settings.ReadReplicasSettings, + PartitioningSettings = settings.PartitioningSettings?.GetProto(), + KeyBloomFilter = settings.KeyBloomFilter.GetProto(), + ReadReplicasSettings = settings.ReadReplicasSettings?.GetProto() }; if (settings.TtlSettings is not null) - request.TtlSettings = settings.TtlSettings; + request.TtlSettings = settings.TtlSettings.GetProto(); if (settings.UniformPartitions is not null) request.UniformPartitions = (ulong)settings.UniformPartitions; if (settings.PartitionAtKeys is not null) diff --git a/src/Ydb.Sdk/src/Services/Table/DescribeTable.cs b/src/Ydb.Sdk/src/Services/Table/DescribeTable.cs index e48784e5..54d00304 100644 --- a/src/Ydb.Sdk/src/Services/Table/DescribeTable.cs +++ b/src/Ydb.Sdk/src/Services/Table/DescribeTable.cs @@ -2,9 +2,108 @@ using Ydb.Sdk.Client; using Ydb.Table; using Ydb.Table.V1; +using Ydb.Sdk.Value; namespace Ydb.Sdk.Services.Table; +public class PartitionStats +{ + public ulong RowsEstimate { get; } + public ulong StoreSize { get; } + + internal PartitionStats(Ydb.Table.PartitionStats proto) + { + RowsEstimate = proto.RowsEstimate; + StoreSize = proto.StoreSize; + } +} + +public class TableStats +{ + public IReadOnlyList? PartitionStats { get; } + public ulong RowsEstimate { get; } + public ulong StoreSize { get; } + public ulong Partitions { get; } + public DateTime CreationTime { get; } + public DateTime ModificationTime { get; } + + internal TableStats(Ydb.Table.TableStats? proto) + { + if (proto == null) + { + return; + } + + PartitionStats = proto.PartitionStats.Select(partitionStats => new PartitionStats(partitionStats)).ToList(); + RowsEstimate = proto.RowsEstimate; + StoreSize = proto.StoreSize; + Partitions = proto.Partitions; + CreationTime = proto.CreationTime.ToDateTime(); + ModificationTime = proto.ModificationTime.ToDateTime(); + } +} + +public enum TableIndexDescriptionStatus +{ + Unspecified, + Ready, + Building +} + +public enum IndexType +{ + None, + GlobalIndex, + GlobalAsyncIndex +} + +public class TableIndexDescription +{ + public string Name { get; } + public IReadOnlyList IndexColumns { get; } + public TableIndexDescriptionStatus Status { get; } + public IReadOnlyList DataColumns { get; } + public ulong SizeBytes { get; } + + public IndexType IndexType { get; } + + internal TableIndexDescription(Ydb.Table.TableIndexDescription proto) + { + Name = proto.Name; + IndexColumns = proto.IndexColumns; + Status = TableIndexDescriptionStatusFromProto(proto.Status); + DataColumns = proto.DataColumns; + SizeBytes = proto.SizeBytes; + + IndexType = GlobalIndexTypeFromProto(proto.TypeCase); + } + + private static IndexType GlobalIndexTypeFromProto(Ydb.Table.TableIndexDescription.TypeOneofCase proto) + { + return proto switch + { + Ydb.Table.TableIndexDescription.TypeOneofCase.GlobalIndex => IndexType.GlobalIndex, + Ydb.Table.TableIndexDescription.TypeOneofCase.GlobalAsyncIndex => IndexType.GlobalAsyncIndex, + Ydb.Table.TableIndexDescription.TypeOneofCase.None => IndexType.None, + _ => throw new ArgumentOutOfRangeException() + }; + } + + private static TableIndexDescriptionStatus TableIndexDescriptionStatusFromProto( + Ydb.Table.TableIndexDescription.Types.Status proto) + { + { + return proto switch + { + Ydb.Table.TableIndexDescription.Types.Status.Unspecified => TableIndexDescriptionStatus.Unspecified, + Ydb.Table.TableIndexDescription.Types.Status.Ready => TableIndexDescriptionStatus.Ready, + Ydb.Table.TableIndexDescription.Types.Status.Building => TableIndexDescriptionStatus.Building, + _ => throw new ArgumentOutOfRangeException() + }; + } + } +} + public class DescribeTableSettings : OperationRequestSettings { public bool IncludeShardKeyBounds { get; private set; } @@ -39,23 +138,23 @@ internal DescribeTableResponse(Status status, ResultData? result = null) : base( public class ResultData { public Entry Self { get; } - - public List Columns { get; } - public List PrimaryKey { get; } - public List ShardKeyBounds { get; } - public List Indexes { get; } - public Ydb.Table.TableStats TableStats { get; } - public TtlSettings TtlSettings { get; } + public IReadOnlyList Columns { get; } + public IReadOnlyList PrimaryKey { get; } + public IReadOnlyList ShardKeyBounds { get; } + public IReadOnlyList Indexes { get; } + public TableStats TableStats { get; } + public TtlSettings? TtlSettings { get; } public StorageSettings StorageSettings { get; } - public List ColumnFamilies { get; } - public Dictionary Attributes { get; } + public IReadOnlyList ColumnFamilies { get; } + public IReadOnlyDictionary Attributes { get; } public PartitioningSettings PartitioningSettings { get; } - public Ydb.FeatureFlag.Types.Status KeyBloomFilter { get; } + public FeatureFlagStatus KeyBloomFilter { get; } public ReadReplicasSettings ReadReplicasSettings { get; } - public ResultData(Entry self, List columns, List primaryKey, List shardKeyBounds, - List indexes, Ydb.Table.TableStats tableStats, TtlSettings ttlSettings, - StorageSettings storageSettings, List columnFamilies, Dictionary attributes, + public ResultData(Entry self, IReadOnlyList columns, IReadOnlyList primaryKey, + IReadOnlyList shardKeyBounds, IReadOnlyList indexes, + TableStats tableStats, TtlSettings? ttlSettings, StorageSettings storageSettings, + IReadOnlyList columnFamilies, IReadOnlyDictionary attributes, PartitioningSettings partitioningSettings, FeatureFlag.Types.Status keyBloomFilter, ReadReplicasSettings readReplicasSettings) { @@ -70,7 +169,7 @@ public ResultData(Entry self, List columns, List primaryKey, Lis ColumnFamilies = columnFamilies; Attributes = attributes; PartitioningSettings = partitioningSettings; - KeyBloomFilter = keyBloomFilter; + KeyBloomFilter = keyBloomFilter.FromProto(); ReadReplicasSettings = readReplicasSettings; } @@ -80,16 +179,16 @@ internal static ResultData FromProto(DescribeTableResult resultProto) self: resultProto.Self, columns: resultProto.Columns.Select(proto => new Column(proto)).ToList(), primaryKey: resultProto.PrimaryKey.ToList(), - shardKeyBounds: resultProto.ShardKeyBounds.ToList(), - indexes: resultProto.Indexes.ToList(), - tableStats: resultProto.TableStats, - ttlSettings: resultProto.TtlSettings, - storageSettings: resultProto.StorageSettings, + shardKeyBounds: resultProto.ShardKeyBounds.Select(proto => new YdbValue(proto)).ToList(), + indexes: resultProto.Indexes.Select(proto => new TableIndexDescription(proto)).ToList(), + tableStats: new TableStats(resultProto.TableStats), + ttlSettings: TtlSettings.FromProto(resultProto.TtlSettings), + storageSettings: new StorageSettings(resultProto.StorageSettings), columnFamilies: resultProto.ColumnFamilies.Select(proto => new ColumnFamily(proto)).ToList(), attributes: new Dictionary(resultProto.Attributes), - partitioningSettings: resultProto.PartitioningSettings, + partitioningSettings: new PartitioningSettings(resultProto.PartitioningSettings), keyBloomFilter: resultProto.KeyBloomFilter, - readReplicasSettings: resultProto.ReadReplicasSettings + readReplicasSettings: new ReadReplicasSettings(resultProto.ReadReplicasSettings) ); } } @@ -103,7 +202,7 @@ public async Task DescribeTable(string tablePath, Describ var request = new DescribeTableRequest { OperationParams = MakeOperationParams(settings), - Path = tablePath, + Path = MakeTablePath(tablePath), IncludeShardKeyBounds = settings.IncludeShardKeyBounds, IncludeTableStats = settings.IncludeTableStats, IncludePartitionStats = settings.IncludePartitionStats, diff --git a/src/Ydb.Sdk/src/Services/Table/DescribeTableOptions.cs b/src/Ydb.Sdk/src/Services/Table/DescribeTableOptions.cs index de5a7550..359892cc 100644 --- a/src/Ydb.Sdk/src/Services/Table/DescribeTableOptions.cs +++ b/src/Ydb.Sdk/src/Services/Table/DescribeTableOptions.cs @@ -17,21 +17,21 @@ internal DescribeTableOptionsResponse(Status status, ResultData? result = null) public class ResultData { - public List TableProfilePresets { get; } - public List StoragePolicyPresets { get; } - public List CompactionPolicyPresets { get; } - public List PartitioningPolicyPresets { get; } - public List ExecutionPolicyPresets { get; } - public List ReplicationPolicyPresets { get; } - public List CachingPolicyPresets { get; } + public IReadOnlyList TableProfilePresets { get; } + public IReadOnlyList StoragePolicyPresets { get; } + public IReadOnlyList CompactionPolicyPresets { get; } + public IReadOnlyList PartitioningPolicyPresets { get; } + public IReadOnlyList ExecutionPolicyPresets { get; } + public IReadOnlyList ReplicationPolicyPresets { get; } + public IReadOnlyList CachingPolicyPresets { get; } - public ResultData(List tableProfilePresets, - List storagePolicyPresets, - List compactionPolicyPresets, - List partitioningPolicyPresets, - List executionPolicyPresets, - List replicationPolicyPresets, - List cachingPolicyPresets) + public ResultData(IReadOnlyList tableProfilePresets, + IReadOnlyList storagePolicyPresets, + IReadOnlyList compactionPolicyPresets, + IReadOnlyList partitioningPolicyPresets, + IReadOnlyList executionPolicyPresets, + IReadOnlyList replicationPolicyPresets, + IReadOnlyList cachingPolicyPresets) { TableProfilePresets = tableProfilePresets; StoragePolicyPresets = storagePolicyPresets; diff --git a/src/Ydb.Sdk/src/Services/Table/DropTable.cs b/src/Ydb.Sdk/src/Services/Table/DropTable.cs index fc900604..38b8eb44 100644 --- a/src/Ydb.Sdk/src/Services/Table/DropTable.cs +++ b/src/Ydb.Sdk/src/Services/Table/DropTable.cs @@ -23,7 +23,7 @@ public async Task DropTable(string tablePath, DropTableSettin var request = new DropTableRequest { OperationParams = MakeOperationParams(settings), - Path = tablePath + Path = MakeTablePath(tablePath) }; try diff --git a/src/Ydb.Sdk/src/Services/Table/ReadTable.cs b/src/Ydb.Sdk/src/Services/Table/ReadTable.cs index add041d9..3c855c04 100644 --- a/src/Ydb.Sdk/src/Services/Table/ReadTable.cs +++ b/src/Ydb.Sdk/src/Services/Table/ReadTable.cs @@ -69,7 +69,7 @@ public ReadTableStream ReadTable(string tablePath, ReadTableSettings? settings = var request = new ReadTableRequest { - Path = tablePath, + Path = MakeTablePath(tablePath), Columns = { settings.Columns }, RowLimit = settings.RowLimit, Ordered = settings.Ordered diff --git a/src/Ydb.Sdk/src/Services/Table/RenameTable.cs b/src/Ydb.Sdk/src/Services/Table/RenameTable.cs index be8aaab7..f4f8aa8a 100644 --- a/src/Ydb.Sdk/src/Services/Table/RenameTable.cs +++ b/src/Ydb.Sdk/src/Services/Table/RenameTable.cs @@ -4,6 +4,30 @@ namespace Ydb.Sdk.Services.Table; +public class RenameTableItem +{ + public string SourcePath { get; } + public string DestinationPath { get; } + public bool ReplaceDestination { get; } + + public RenameTableItem(string sourcePath, string destinationPath, bool replaceDestination) + { + SourcePath = sourcePath; + DestinationPath = destinationPath; + ReplaceDestination = replaceDestination; + } + + internal Ydb.Table.RenameTableItem GetProto(TableClient tableClient) + { + return new Ydb.Table.RenameTableItem + { + SourcePath = tableClient.MakeTablePath(SourcePath), + DestinationPath = tableClient.MakeTablePath(DestinationPath), + ReplaceDestination = ReplaceDestination + }; + } +} + public class RenameTablesSettings : OperationRequestSettings { public List RenameTableItems { get; } = new(); @@ -16,8 +40,7 @@ public RenameTablesSettings WithItems(params RenameTableItem[] renameTableItems) public RenameTablesSettings WithItem(string sourcePath, string destinationPath, bool replaceDestination) { - RenameTableItems.Add(new RenameTableItem - { SourcePath = sourcePath, DestinationPath = destinationPath, ReplaceDestination = replaceDestination }); + RenameTableItems.Add(new RenameTableItem(sourcePath, destinationPath, replaceDestination)); return this; } } @@ -35,7 +58,7 @@ public async Task RenameTable(RenameTablesSettings? setting { settings ??= new RenameTablesSettings(); var request = new RenameTablesRequest { OperationParams = MakeOperationParams(settings) }; - request.Tables.AddRange(settings.RenameTableItems); + request.Tables.AddRange(settings.RenameTableItems.Select(item => item.GetProto(this))); try { diff --git a/src/Ydb.Sdk/src/Services/Table/Shared.cs b/src/Ydb.Sdk/src/Services/Table/Shared.cs deleted file mode 100644 index 4b2c862f..00000000 --- a/src/Ydb.Sdk/src/Services/Table/Shared.cs +++ /dev/null @@ -1,100 +0,0 @@ -using Ydb.Table; - -namespace Ydb.Sdk.Services.Table; - -public class Column -{ - public string Name { get; } - - public Type Type { get; } - - public string? Family { get; } - - public Column(string name, Type type, string? family = null) - { - Name = name; - Type = type; - Family = family ?? ""; - } - - public Column(ColumnMeta proto) - { - Name = proto.Name; - Type = proto.Type; - Family = proto.Family; - } - - public ColumnMeta GetProto() => - new() - { - Name = Name, - Family = Family, - Type = Type - }; -} - -public class Index -{ - public string Name { get; } - - public List Columns { get; } - - public Index(string name, params string[] columns) - { - Name = name; - Columns = columns.ToList(); - } - - public TableIndex GetTableIndex() => - new() - { - Name = Name, - IndexColumns = { Columns }, - GlobalIndex = new GlobalIndex() - }; -} - -public class ColumnFamily -{ - public string Name { get; } - - public StoragePool Data { get; } - - public Ydb.Table.ColumnFamily.Types.Compression Compression { get; } - - public FeatureFlag.Types.Status KeepInMemory { get; } - - public ColumnFamily(string name, StoragePool data, - Ydb.Table.ColumnFamily.Types.Compression compression = Ydb.Table.ColumnFamily.Types.Compression.Unspecified, - FeatureFlag.Types.Status keepInMemory = FeatureFlag.Types.Status.Unspecified) - { - Compression = compression; - Name = name; - Data = data; - KeepInMemory = keepInMemory; - } - - public ColumnFamily(Ydb.Table.ColumnFamily proto) - { - Compression = proto.Compression; - Name = proto.Name; - Data = proto.Data; - KeepInMemory = proto.KeepInMemory; - } - - public Ydb.Table.ColumnFamily GetProto() => - new() - { - Compression = Compression, - Name = Name, - Data = Data, - KeepInMemory = KeepInMemory - }; -} - -public enum CompactionPolicy -{ - Default, - SmallTable, - LogTable -} \ No newline at end of file diff --git a/src/Ydb.Sdk/src/Services/Table/Shared/PartitioningSettings.cs b/src/Ydb.Sdk/src/Services/Table/Shared/PartitioningSettings.cs new file mode 100644 index 00000000..e552cf70 --- /dev/null +++ b/src/Ydb.Sdk/src/Services/Table/Shared/PartitioningSettings.cs @@ -0,0 +1,47 @@ +// ReSharper disable once CheckNamespace + +namespace Ydb.Sdk.Services.Table; + +public class PartitioningSettings +{ + public List PartitionBy { get; } + public FeatureFlagStatus PartitioningBySize { get; } + public ulong PartitionSizeMb { get; } + public FeatureFlagStatus PartitioningByLoad { get; } + public ulong MinPartitionsCount { get; } + public ulong MaxPartitionsCount { get; } + + public PartitioningSettings(List partitionBy, FeatureFlagStatus partitioningBySize, ulong partitionSizeMb, + FeatureFlagStatus partitioningByLoad, ulong minPartitionsCount, ulong maxPartitionsCount) + { + PartitionBy = partitionBy; + PartitioningBySize = partitioningBySize; + PartitionSizeMb = partitionSizeMb; + PartitioningByLoad = partitioningByLoad; + MinPartitionsCount = minPartitionsCount; + MaxPartitionsCount = maxPartitionsCount; + } + + public PartitioningSettings(Ydb.Table.PartitioningSettings proto) + { + PartitionBy = proto.PartitionBy.ToList(); + PartitioningBySize = proto.PartitioningBySize.FromProto(); + PartitionSizeMb = proto.PartitionSizeMb; + PartitioningByLoad = proto.PartitioningByLoad.FromProto(); + MinPartitionsCount = proto.MinPartitionsCount; + MaxPartitionsCount = proto.MaxPartitionsCount; + } + + public Ydb.Table.PartitioningSettings GetProto() + { + return new Ydb.Table.PartitioningSettings + { + PartitionBy = { PartitionBy }, + PartitioningBySize = PartitioningBySize.GetProto(), + PartitionSizeMb = PartitionSizeMb, + PartitioningByLoad = PartitioningByLoad.GetProto(), + MinPartitionsCount = MinPartitionsCount, + MaxPartitionsCount = MaxPartitionsCount + }; + } +} \ No newline at end of file diff --git a/src/Ydb.Sdk/src/Services/Table/Shared/ReadReplicasSettings.cs b/src/Ydb.Sdk/src/Services/Table/Shared/ReadReplicasSettings.cs new file mode 100644 index 00000000..51632d88 --- /dev/null +++ b/src/Ydb.Sdk/src/Services/Table/Shared/ReadReplicasSettings.cs @@ -0,0 +1,62 @@ +// ReSharper disable once CheckNamespace + +namespace Ydb.Sdk.Services.Table; + +public class ReadReplicasSettings +{ + public enum SettingsType + { + None, + PerAzReadReplicasCount, + AnyAzReadReplicasCount + } + + public SettingsType Type { get; } + public ulong Settings { get; } + + + public ReadReplicasSettings(SettingsType type, ulong settings) + { + Type = type; + Settings = settings; + } + + public ReadReplicasSettings(Ydb.Table.ReadReplicasSettings? proto) + { + if (proto is null) + { + return; + } + + switch (proto.SettingsCase) + { + case Ydb.Table.ReadReplicasSettings.SettingsOneofCase.None: + Type = SettingsType.None; + Settings = default; + break; + case Ydb.Table.ReadReplicasSettings.SettingsOneofCase.PerAzReadReplicasCount: + Type = SettingsType.PerAzReadReplicasCount; + Settings = proto.PerAzReadReplicasCount; + break; + case Ydb.Table.ReadReplicasSettings.SettingsOneofCase.AnyAzReadReplicasCount: + Type = SettingsType.AnyAzReadReplicasCount; + Settings = proto.AnyAzReadReplicasCount; + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + + public Ydb.Table.ReadReplicasSettings GetProto() + { + return Type switch + { + SettingsType.None => new Ydb.Table.ReadReplicasSettings(), + SettingsType.PerAzReadReplicasCount => new Ydb.Table.ReadReplicasSettings + { PerAzReadReplicasCount = Settings }, + SettingsType.AnyAzReadReplicasCount => new Ydb.Table.ReadReplicasSettings + { AnyAzReadReplicasCount = Settings }, + _ => throw new ArgumentOutOfRangeException() + }; + } +} \ No newline at end of file diff --git a/src/Ydb.Sdk/src/Services/Table/Shared/SharedEnums.cs b/src/Ydb.Sdk/src/Services/Table/Shared/SharedEnums.cs new file mode 100644 index 00000000..a927fcc3 --- /dev/null +++ b/src/Ydb.Sdk/src/Services/Table/Shared/SharedEnums.cs @@ -0,0 +1,53 @@ +// ReSharper disable once CheckNamespace + +namespace Ydb.Sdk.Services.Table; + +public enum CompactionPolicy +{ + Default, + SmallTable, + LogTable +} + +public enum FeatureFlagStatus +{ + Unspecified, + Enabled, + Disabled +} + +internal static class TableEnumConverter +{ + internal static string GetString(this CompactionPolicy compactionPolicy) + { + return compactionPolicy switch + { + CompactionPolicy.Default => "default", + CompactionPolicy.SmallTable => "small_table", + CompactionPolicy.LogTable => "log_table", + _ => throw new ArgumentOutOfRangeException(nameof(compactionPolicy), compactionPolicy, null) + }; + } + + internal static FeatureFlagStatus FromProto(this FeatureFlag.Types.Status proto) + { + return proto switch + { + FeatureFlag.Types.Status.Unspecified => FeatureFlagStatus.Unspecified, + FeatureFlag.Types.Status.Enabled => FeatureFlagStatus.Enabled, + FeatureFlag.Types.Status.Disabled => FeatureFlagStatus.Disabled, + _ => throw new ArgumentOutOfRangeException() + }; + } + + internal static FeatureFlag.Types.Status GetProto(this FeatureFlagStatus status) + { + return status switch + { + FeatureFlagStatus.Unspecified => FeatureFlag.Types.Status.Unspecified, + FeatureFlagStatus.Enabled => FeatureFlag.Types.Status.Enabled, + FeatureFlagStatus.Disabled => FeatureFlag.Types.Status.Disabled, + _ => throw new ArgumentOutOfRangeException(nameof(status), status, null) + }; + } +} \ No newline at end of file diff --git a/src/Ydb.Sdk/src/Services/Table/Shared/StoragePool.cs b/src/Ydb.Sdk/src/Services/Table/Shared/StoragePool.cs new file mode 100644 index 00000000..e0f09f02 --- /dev/null +++ b/src/Ydb.Sdk/src/Services/Table/Shared/StoragePool.cs @@ -0,0 +1,23 @@ +// ReSharper disable once CheckNamespace + +namespace Ydb.Sdk.Services.Table; + +public class StoragePool +{ + public string? Media { get; } + + public StoragePool(string media) + { + Media = media; + } + + public StoragePool(Ydb.Table.StoragePool? proto) + { + Media = proto?.Media; + } + + public Ydb.Table.StoragePool GetProto() + { + return new Ydb.Table.StoragePool { Media = Media }; + } +} \ No newline at end of file diff --git a/src/Ydb.Sdk/src/Services/Table/Shared/StorageSettings.cs b/src/Ydb.Sdk/src/Services/Table/Shared/StorageSettings.cs new file mode 100644 index 00000000..0818723f --- /dev/null +++ b/src/Ydb.Sdk/src/Services/Table/Shared/StorageSettings.cs @@ -0,0 +1,39 @@ +// ReSharper disable once CheckNamespace + +namespace Ydb.Sdk.Services.Table; + +public class StorageSettings +{ + public StoragePool TabletCommitLog0 { get; } + public StoragePool TabletCommitLog1 { get; } + public StoragePool External { get; } + public FeatureFlagStatus StoreExternalBlobs { get; } + + public StorageSettings(StoragePool tabletCommitLog0, StoragePool tabletCommitLog1, StoragePool external, + FeatureFlagStatus storeExternalBlobs) + { + TabletCommitLog0 = tabletCommitLog0; + TabletCommitLog1 = tabletCommitLog1; + External = external; + StoreExternalBlobs = storeExternalBlobs; + } + + public StorageSettings(Ydb.Table.StorageSettings proto) + { + TabletCommitLog0 = new StoragePool(proto.TabletCommitLog0); + TabletCommitLog1 = new StoragePool(proto.TabletCommitLog1); + External = new StoragePool(proto.External); + StoreExternalBlobs = proto.StoreExternalBlobs.FromProto(); + } + + public Ydb.Table.StorageSettings GetProto() + { + return new Ydb.Table.StorageSettings + { + TabletCommitLog0 = TabletCommitLog0.GetProto(), + TabletCommitLog1 = TabletCommitLog1.GetProto(), + External = External.GetProto(), + StoreExternalBlobs = StoreExternalBlobs.GetProto() + }; + } +} \ No newline at end of file diff --git a/src/Ydb.Sdk/src/Services/Table/Shared/TtlSettings.cs b/src/Ydb.Sdk/src/Services/Table/Shared/TtlSettings.cs new file mode 100644 index 00000000..e8132a68 --- /dev/null +++ b/src/Ydb.Sdk/src/Services/Table/Shared/TtlSettings.cs @@ -0,0 +1,169 @@ +// ReSharper disable once CheckNamespace + +namespace Ydb.Sdk.Services.Table; + +public class DateTypeColumnModeSettings +{ + public string ColumnName { get; } + public uint ExpireAfterSeconds { get; } + + public DateTypeColumnModeSettings(uint expireAfterSeconds, string columnName) + { + ExpireAfterSeconds = expireAfterSeconds; + ColumnName = columnName; + } + + public DateTypeColumnModeSettings(Ydb.Table.DateTypeColumnModeSettings proto) + { + ColumnName = proto.ColumnName; + ExpireAfterSeconds = proto.ExpireAfterSeconds; + } + + public Ydb.Table.DateTypeColumnModeSettings GetProto() + { + return new Ydb.Table.DateTypeColumnModeSettings + { + ColumnName = ColumnName, + ExpireAfterSeconds = ExpireAfterSeconds + }; + } +} + +public class ValueSinceUnixEpochModeSettings +{ + public enum Unit + { + Unspecified = 0, + Seconds = 1, + Milliseconds = 2, + Microseconds = 3, + Nanoseconds = 4 + } + + public string ColumnName { get; } + public Unit ColumnUnit { get; } + public uint ExpireAfterSeconds { get; } + + public ValueSinceUnixEpochModeSettings(string columnName, Unit columnUnit, uint expireAfterSeconds) + { + ColumnName = columnName; + ColumnUnit = columnUnit; + ExpireAfterSeconds = expireAfterSeconds; + } + + public ValueSinceUnixEpochModeSettings(Ydb.Table.ValueSinceUnixEpochModeSettings proto) + { + ColumnName = proto.ColumnName; + ColumnUnit = proto.ColumnUnit switch + { + Ydb.Table.ValueSinceUnixEpochModeSettings.Types.Unit.Unspecified => Unit.Unspecified, + Ydb.Table.ValueSinceUnixEpochModeSettings.Types.Unit.Seconds => Unit.Seconds, + Ydb.Table.ValueSinceUnixEpochModeSettings.Types.Unit.Milliseconds => Unit.Milliseconds, + Ydb.Table.ValueSinceUnixEpochModeSettings.Types.Unit.Microseconds => Unit.Microseconds, + Ydb.Table.ValueSinceUnixEpochModeSettings.Types.Unit.Nanoseconds => Unit.Nanoseconds, + _ => throw new ArgumentOutOfRangeException() + }; + ExpireAfterSeconds = proto.ExpireAfterSeconds; + } + + public Ydb.Table.ValueSinceUnixEpochModeSettings GetProto() + { + return new Ydb.Table.ValueSinceUnixEpochModeSettings + { + ColumnName = ColumnName, + ColumnUnit = GetProtoUnit(ColumnUnit), + ExpireAfterSeconds = ExpireAfterSeconds + }; + } + + private static Ydb.Table.ValueSinceUnixEpochModeSettings.Types.Unit GetProtoUnit(Unit unit) + { + return unit switch + { + Unit.Unspecified => Ydb.Table.ValueSinceUnixEpochModeSettings.Types.Unit.Unspecified, + Unit.Seconds => Ydb.Table.ValueSinceUnixEpochModeSettings.Types.Unit.Seconds, + Unit.Milliseconds => Ydb.Table.ValueSinceUnixEpochModeSettings.Types.Unit.Milliseconds, + Unit.Microseconds => Ydb.Table.ValueSinceUnixEpochModeSettings.Types.Unit.Microseconds, + Unit.Nanoseconds => Ydb.Table.ValueSinceUnixEpochModeSettings.Types.Unit.Nanoseconds, + _ => throw new ArgumentOutOfRangeException(nameof(unit), unit, null) + }; + } +} + +public class TtlSettingsMode +{ + public enum ModeType + { + None, + DateTypeColumn, + ValueSinceUnixEpoch + } + + public ModeType Type { get; private set; } + public DateTypeColumnModeSettings? DateTypeColumnModeSettings { get; private set; } = null; + public ValueSinceUnixEpochModeSettings? ValueSinceUnixEpochModeSettings { get; private set; } = null; + + public TtlSettingsMode(DateTypeColumnModeSettings settings) + { + Type = ModeType.DateTypeColumn; + DateTypeColumnModeSettings = settings; + } + + public TtlSettingsMode(ValueSinceUnixEpochModeSettings settings) + { + Type = ModeType.DateTypeColumn; + ValueSinceUnixEpochModeSettings = settings; + } +} + +public class TtlSettings +{ + public TtlSettingsMode Mode { get; } + public uint RunIntervalSeconds { get; } + + private TtlSettings(TtlSettingsMode mode, uint runIntervalSeconds) + { + Mode = mode; + RunIntervalSeconds = runIntervalSeconds; + } + + public static TtlSettings? FromProto(Ydb.Table.TtlSettings? proto) + { + if (proto is null) + return null; + return proto.ModeCase switch + { + Ydb.Table.TtlSettings.ModeOneofCase.DateTypeColumn => new TtlSettings( + new TtlSettingsMode(new DateTypeColumnModeSettings(proto.DateTypeColumn)), + proto.RunIntervalSeconds), + Ydb.Table.TtlSettings.ModeOneofCase.ValueSinceUnixEpoch => new TtlSettings( + new TtlSettingsMode(new ValueSinceUnixEpochModeSettings(proto.ValueSinceUnixEpoch)), + proto.RunIntervalSeconds), + Ydb.Table.TtlSettings.ModeOneofCase.None => null, + _ => throw new ArgumentOutOfRangeException() + }; + } + + public Ydb.Table.TtlSettings GetProto() + { + var proto = new Ydb.Table.TtlSettings + { + RunIntervalSeconds = RunIntervalSeconds + }; + switch (Mode.Type) + { + case TtlSettingsMode.ModeType.DateTypeColumn: + proto.DateTypeColumn = Mode.DateTypeColumnModeSettings?.GetProto(); + break; + case TtlSettingsMode.ModeType.ValueSinceUnixEpoch: + proto.ValueSinceUnixEpoch = Mode.ValueSinceUnixEpochModeSettings?.GetProto(); + break; + case TtlSettingsMode.ModeType.None: + break; + default: + throw new ArgumentOutOfRangeException(); + } + + return proto; + } +} \ No newline at end of file diff --git a/src/Ydb.Sdk/src/Services/Table/TableClient.cs b/src/Ydb.Sdk/src/Services/Table/TableClient.cs index 3ea510ad..43705d00 100644 --- a/src/Ydb.Sdk/src/Services/Table/TableClient.cs +++ b/src/Ydb.Sdk/src/Services/Table/TableClient.cs @@ -53,4 +53,6 @@ private void Dispose(bool disposing) _disposed = true; } + + internal string MakeTablePath(string path) => path.StartsWith('/') ? path : $"{Driver.Database}/{path}"; } \ No newline at end of file diff --git a/src/Ydb.Sdk/src/Value/YdbValue.cs b/src/Ydb.Sdk/src/Value/YdbValue.cs index 9dbcb686..80709eb1 100644 --- a/src/Ydb.Sdk/src/Value/YdbValue.cs +++ b/src/Ydb.Sdk/src/Value/YdbValue.cs @@ -60,6 +60,12 @@ internal YdbValue(Type type, Ydb.Value value) TypeId = GetYdbTypeId(type); } + internal YdbValue(TypedValue proto) + { + _protoType = proto.Type; + _protoValue = proto.Value; + } + public YdbTypeId TypeId { get; } public TypedValue GetProto() diff --git a/src/Ydb.Sdk/src/Value/YdbValueTypeBuilder.cs b/src/Ydb.Sdk/src/Value/YdbValueTypeBuilder.cs index 59fbe4a5..eb731542 100644 --- a/src/Ydb.Sdk/src/Value/YdbValueTypeBuilder.cs +++ b/src/Ydb.Sdk/src/Value/YdbValueTypeBuilder.cs @@ -2,45 +2,105 @@ namespace Ydb.Sdk.Value; public partial class YdbValue { - public static Type MakeBoolType() => MakePrimitiveType(Type.Types.PrimitiveTypeId.Bool); + public static Type MakeBoolType() + { + return MakePrimitiveType(Type.Types.PrimitiveTypeId.Bool); + } - public static Type MakeInt8Type() => MakePrimitiveType(Type.Types.PrimitiveTypeId.Int8); + public static Type MakeInt8Type() + { + return MakePrimitiveType(Type.Types.PrimitiveTypeId.Int8); + } - public static Type MakeUint8Type() => MakePrimitiveType(Type.Types.PrimitiveTypeId.Uint8); + public static Type MakeUint8Type() + { + return MakePrimitiveType(Type.Types.PrimitiveTypeId.Uint8); + } - public static Type MakeInt16Type() => MakePrimitiveType(Type.Types.PrimitiveTypeId.Int16); + public static Type MakeInt16Type() + { + return MakePrimitiveType(Type.Types.PrimitiveTypeId.Int16); + } - public static Type MakeUint16Type() => MakePrimitiveType(Type.Types.PrimitiveTypeId.Uint16); + public static Type MakeUint16Type() + { + return MakePrimitiveType(Type.Types.PrimitiveTypeId.Uint16); + } - public static Type MakeInt32Type() => MakePrimitiveType(Type.Types.PrimitiveTypeId.Int32); + public static Type MakeInt32Type() + { + return MakePrimitiveType(Type.Types.PrimitiveTypeId.Int32); + } - public static Type MakeUint32Type() => MakePrimitiveType(Type.Types.PrimitiveTypeId.Uint32); + public static Type MakeUint32Type() + { + return MakePrimitiveType(Type.Types.PrimitiveTypeId.Uint32); + } - public static Type MakeInt64Type() => MakePrimitiveType(Type.Types.PrimitiveTypeId.Int64); + public static Type MakeInt64Type() + { + return MakePrimitiveType(Type.Types.PrimitiveTypeId.Int64); + } - public static Type MakeUint64Type() => MakePrimitiveType(Type.Types.PrimitiveTypeId.Uint64); + public static Type MakeUint64Type() + { + return MakePrimitiveType(Type.Types.PrimitiveTypeId.Uint64); + } - public static Type MakeFloatType() => MakePrimitiveType(Type.Types.PrimitiveTypeId.Float); + public static Type MakeFloatType() + { + return MakePrimitiveType(Type.Types.PrimitiveTypeId.Float); + } - public static Type MakeDoubleType() => MakePrimitiveType(Type.Types.PrimitiveTypeId.Double); + public static Type MakeDoubleType() + { + return MakePrimitiveType(Type.Types.PrimitiveTypeId.Double); + } - public static Type MakeDateType() => MakePrimitiveType(Type.Types.PrimitiveTypeId.Date); + public static Type MakeDateType() + { + return MakePrimitiveType(Type.Types.PrimitiveTypeId.Date); + } - public static Type MakeDatetimeType() => MakePrimitiveType(Type.Types.PrimitiveTypeId.Datetime); + public static Type MakeDatetimeType() + { + return MakePrimitiveType(Type.Types.PrimitiveTypeId.Datetime); + } - public static Type MakeTimestampType() => MakePrimitiveType(Type.Types.PrimitiveTypeId.Timestamp); + public static Type MakeTimestampType() + { + return MakePrimitiveType(Type.Types.PrimitiveTypeId.Timestamp); + } - public static Type MakeIntervalType() => MakePrimitiveType(Type.Types.PrimitiveTypeId.Interval); + public static Type MakeIntervalType() + { + return MakePrimitiveType(Type.Types.PrimitiveTypeId.Interval); + } - public static Type MakeStringType() => MakePrimitiveType(Type.Types.PrimitiveTypeId.String); + public static Type MakeStringType() + { + return MakePrimitiveType(Type.Types.PrimitiveTypeId.String); + } - public static Type MakeUtf8Type() => MakePrimitiveType(Type.Types.PrimitiveTypeId.Utf8); + public static Type MakeUtf8Type() + { + return MakePrimitiveType(Type.Types.PrimitiveTypeId.Utf8); + } - public static Type MakeYsonType() => MakePrimitiveType(Type.Types.PrimitiveTypeId.Yson); + public static Type MakeYsonType() + { + return MakePrimitiveType(Type.Types.PrimitiveTypeId.Yson); + } - public static Type MakeJsonType() => MakePrimitiveType(Type.Types.PrimitiveTypeId.Json); + public static Type MakeJsonType() + { + return MakePrimitiveType(Type.Types.PrimitiveTypeId.Json); + } - public static Type MakeJsonDocumentType() => MakePrimitiveType(Type.Types.PrimitiveTypeId.JsonDocument); + public static Type MakeJsonDocumentType() + { + return MakePrimitiveType(Type.Types.PrimitiveTypeId.JsonDocument); + } public static Type MakeDecimalType(uint precision = 22, uint scale = 9) { @@ -50,9 +110,15 @@ public static Type MakeDecimalType(uint precision = 22, uint scale = 9) }; } - public static Type MakeOptionalType(Type baseType) => new() { OptionalType = new OptionalType { Item = baseType } }; + public static Type MakeOptionalType(Type baseType) + { + return new() { OptionalType = new OptionalType { Item = baseType } }; + } - public static Type MakeListType(Type baseType) => new() { ListType = new ListType { Item = baseType } }; + public static Type MakeListType(Type baseType) + { + return new() { ListType = new ListType { Item = baseType } }; + } public static Type MakeTupleType(IEnumerable baseTypes) { @@ -68,45 +134,108 @@ public static Type MakeStructType(IEnumerable structMembers) return type; } - public static Type MakeOptionalBoolType() => MakeOptionalType(MakeBoolType()); + public static Type MakeOptionalBoolType() + { + return MakeOptionalType(MakeBoolType()); + } - public static Type MakeOptionalInt8Type() => MakeOptionalType(MakeInt8Type()); + public static Type MakeOptionalInt8Type() + { + return MakeOptionalType(MakeInt8Type()); + } - public static Type MakeOptionalUint8Type() => MakeOptionalType(MakeUint8Type()); + public static Type MakeOptionalUint8Type() + { + return MakeOptionalType(MakeUint8Type()); + } - public static Type MakeOptionalInt16Type() => MakeOptionalType(MakeInt16Type()); + public static Type MakeOptionalInt16Type() + { + return MakeOptionalType(MakeInt16Type()); + } - public static Type MakeOptionalUint16Type() => MakeOptionalType(MakeUint16Type()); + public static Type MakeOptionalUint16Type() + { + return MakeOptionalType(MakeUint16Type()); + } - public static Type MakeOptionalInt32Type() => MakeOptionalType(MakeInt32Type()); + public static Type MakeOptionalInt32Type() + { + return MakeOptionalType(MakeInt32Type()); + } - public static Type MakeOptionalUint32Type() => MakeOptionalType(MakeUint32Type()); + public static Type MakeOptionalUint32Type() + { + return MakeOptionalType(MakeUint32Type()); + } - public static Type MakeOptionalInt64Type() => MakeOptionalType(MakeInt64Type()); + public static Type MakeOptionalInt64Type() + { + return MakeOptionalType(MakeInt64Type()); + } - public static Type MakeOptionalUint64Type() => MakeOptionalType(MakeUint64Type()); + public static Type MakeOptionalUint64Type() + { + return MakeOptionalType(MakeUint64Type()); + } - public static Type MakeOptionalFloatType() => MakeOptionalType(MakeFloatType()); + public static Type MakeOptionalFloatType() + { + return MakeOptionalType(MakeFloatType()); + } - public static Type MakeOptionalDoubleType() => MakeOptionalType(MakeDoubleType()); + public static Type MakeOptionalDoubleType() + { + return MakeOptionalType(MakeDoubleType()); + } - public static Type MakeOptionalDateType() => MakeOptionalType(MakeDateType()); + public static Type MakeOptionalDateType() + { + return MakeOptionalType(MakeDateType()); + } - public static Type MakeOptionalDatetimeType() => MakeOptionalType(MakeDatetimeType()); + public static Type MakeOptionalDatetimeType() + { + return MakeOptionalType(MakeDatetimeType()); + } - public static Type MakeOptionalTimestampType() => MakeOptionalType(MakeTimestampType()); + public static Type MakeOptionalTimestampType() + { + return MakeOptionalType(MakeTimestampType()); + } - public static Type MakeOptionalIntervalType() => MakeOptionalType(MakeIntervalType()); + public static Type MakeOptionalIntervalType() + { + return MakeOptionalType(MakeIntervalType()); + } - public static Type MakeOptionalStringType() => MakeOptionalType(MakeStringType()); + public static Type MakeOptionalStringType() + { + return MakeOptionalType(MakeStringType()); + } - public static Type MakeOptionalUtf8Type() => MakeOptionalType(MakeUtf8Type()); + public static Type MakeOptionalUtf8Type() + { + return MakeOptionalType(MakeUtf8Type()); + } - public static Type MakeOptionalYsonType() => MakeOptionalType(MakeYsonType()); + public static Type MakeOptionalYsonType() + { + return MakeOptionalType(MakeYsonType()); + } - public static Type MakeOptionalJsonType() => MakeOptionalType(MakeJsonType()); + public static Type MakeOptionalJsonType() + { + return MakeOptionalType(MakeJsonType()); + } - public static Type MakeOptionalJsonDocumentType() => MakeOptionalType(MakeJsonDocumentType()); + public static Type MakeOptionalJsonDocumentType() + { + return MakeOptionalType(MakeJsonDocumentType()); + } - public static Type MakeOptionalDecimalType() => MakeOptionalType(MakeDecimalType()); + public static Type MakeOptionalDecimalType() + { + return MakeOptionalType(MakeDecimalType()); + } } \ No newline at end of file diff --git a/src/Ydb.Sdk/tests/TableService/TestCopyTable.cs b/src/Ydb.Sdk/tests/TableService/TestCopyTable.cs index 2499f2fa..bd2e9ab8 100644 --- a/src/Ydb.Sdk/tests/TableService/TestCopyTable.cs +++ b/src/Ydb.Sdk/tests/TableService/TestCopyTable.cs @@ -5,7 +5,7 @@ namespace Ydb.Sdk.Tests.TableService; [Trait("Category", "Integration")] -public class TestCopyTable +public class TestCopyTable : IDisposable { // ReSharper disable once NotAccessedField.Local private readonly ITestOutputHelper _output; @@ -37,8 +37,8 @@ public void Dispose() [Fact] public async Task CopyTable() { - var source = $"/local/{Guid.NewGuid():n}"; - var dest = $"/local/{Guid.NewGuid():n}"; + var source = Guid.NewGuid().ToString("n"); + var dest = Guid.NewGuid().ToString("n"); await Shared.CreateSimpleTable(_tableClient, source); var response = await _tableClient.CopyTable(source, dest); @@ -54,14 +54,14 @@ public async Task CopyTables() var pairs = new List<(string, string)>(); for (var i = 0; i < 5; i++) { - pairs.Add(($"/local/{Guid.NewGuid():n}", $"/local/{Guid.NewGuid():n}")); + pairs.Add((Guid.NewGuid().ToString("n"), Guid.NewGuid().ToString("n"))); } var items = new List(); foreach (var (source, dest) in pairs) { await Shared.CreateSimpleTable(_tableClient, source); - items.Add(new CopyTableItem(source, dest)); + items.Add(new CopyTableItem(source, dest, false)); } var response = await _tableClient.CopyTables(items); diff --git a/src/Ydb.Sdk/tests/TableService/TestCreateTable.cs b/src/Ydb.Sdk/tests/TableService/TestCreateTable.cs index 346bdebc..f0bf34bf 100644 --- a/src/Ydb.Sdk/tests/TableService/TestCreateTable.cs +++ b/src/Ydb.Sdk/tests/TableService/TestCreateTable.cs @@ -37,7 +37,7 @@ public void Dispose() [Fact] public async Task CreateWithoutColumns() { - var tablePath = $"/local/{Guid.NewGuid():n}"; + var tablePath = Guid.NewGuid().ToString("n"); var response = await _tableClient.CreateTable(tablePath); Assert.Equal(StatusCode.BadRequest, response.Status.StatusCode); } @@ -45,7 +45,7 @@ public async Task CreateWithoutColumns() [Fact] public async Task CreateWithColumns() { - var tablePath = $"/local/{Guid.NewGuid():n}"; + var tablePath = Guid.NewGuid().ToString("n"); var settings = new CreateTableSettings() .WithColumn(new Services.Table.Column("a", new Type { TypeId = Type.Types.PrimitiveTypeId.Uint64 })); @@ -56,7 +56,7 @@ public async Task CreateWithColumns() [Fact] public async Task CreateWithWrongPrimaryKey() { - var tablePath = $"/local/{Guid.NewGuid():n}"; + var tablePath = Guid.NewGuid().ToString("n"); var settings = new CreateTableSettings() .WithColumn(new Services.Table.Column("a", new Type { TypeId = Type.Types.PrimitiveTypeId.Uint64 })) .WithPrimaryKeys("a", "b"); @@ -68,7 +68,7 @@ public async Task CreateWithWrongPrimaryKey() [Fact] public async Task CreateWithPrimaryKey() { - var tablePath = $"/local/{Guid.NewGuid():n}"; + var tablePath = Guid.NewGuid().ToString("n"); var settings = new CreateTableSettings() .WithColumn(new Services.Table.Column("a", new Type { TypeId = Type.Types.PrimitiveTypeId.Uint64 })) .WithPrimaryKeys("a"); diff --git a/src/Ydb.Sdk/tests/TableService/TestDescribeTable.cs b/src/Ydb.Sdk/tests/TableService/TestDescribeTable.cs index dfefb139..929f0140 100644 --- a/src/Ydb.Sdk/tests/TableService/TestDescribeTable.cs +++ b/src/Ydb.Sdk/tests/TableService/TestDescribeTable.cs @@ -46,7 +46,7 @@ public async Task DescribeNotExisting() [Fact] public async Task CreateAndDescribe() { - var tablePath = $"/local/{Guid.NewGuid():n}"; + var tablePath = Guid.NewGuid().ToString("n"); await Shared.CreateSimpleTable(_tableClient, tablePath); diff --git a/src/Ydb.Sdk/tests/TableService/TestDropTable.cs b/src/Ydb.Sdk/tests/TableService/TestDropTable.cs index 6a9f9e30..559629d8 100644 --- a/src/Ydb.Sdk/tests/TableService/TestDropTable.cs +++ b/src/Ydb.Sdk/tests/TableService/TestDropTable.cs @@ -44,7 +44,7 @@ public async Task DropNotExisting() [Fact] public async Task CreateAndDrop() { - var tablePath = $"/local/{Guid.NewGuid():n}"; + var tablePath = Guid.NewGuid().ToString("n"); await Shared.CreateSimpleTable(_tableClient, tablePath); diff --git a/src/Ydb.Sdk/tests/TableService/TestRenameTable.cs b/src/Ydb.Sdk/tests/TableService/TestRenameTable.cs index 0102f470..72ae5972 100644 --- a/src/Ydb.Sdk/tests/TableService/TestRenameTable.cs +++ b/src/Ydb.Sdk/tests/TableService/TestRenameTable.cs @@ -45,8 +45,8 @@ public async Task RenameNotExisting() [Fact] public async Task Rename() { - var sourcePath = $"/local/{Guid.NewGuid():n}"; - var destPath = $"/local/{Guid.NewGuid():n}"; + var sourcePath = Guid.NewGuid().ToString("n"); + var destPath = Guid.NewGuid().ToString("n"); await Shared.CreateSimpleTable(_tableClient, sourcePath);