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

[API-274] SQL for Map ([API-617], [API-616], [API-431], [API-619], [API-620], [API-432], [API-659], [API-660], [API-661]) #475

Merged
merged 132 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
5544daf
[WIP]
alexb5dh Jun 24, 2021
121b2ea
Add options validation
alexb5dh Jun 29, 2021
b9d4a2b
Fix `HazelcastClient` construction
alexb5dh Jun 29, 2021
9e3cc9e
`SqlService` implementation update
alexb5dh Jun 30, 2021
e61d1c9
Update FIXME comments
alexb5dh Jul 1, 2021
63a56c0
Implement `SqlResult` enumeration
alexb5dh Jul 1, 2021
355a7dd
Merge remote-tracking branch 'hazelcast/master' into feature/sql-support
alexb5dh Jul 5, 2021
f331851
Add missing words to ReSharper dictionary
alexb5dh Jul 5, 2021
a87a58c
Implement missing codecs
alexb5dh Jul 5, 2021
e828f89
Remove SQL "reserved" codecs
alexb5dh Jul 6, 2021
6d1c079
Add missing docs, comments & update access modifiers
alexb5dh Jul 6, 2021
ad86650
Check column type for `CreateSqlColumnMetadata`
alexb5dh Jul 7, 2021
9112fda
Fix SQL tests init and cleanup
alexb5dh Jul 7, 2021
41dfe18
Get rid of `if #FALSE` in generated codecs
alexb5dh Jul 8, 2021
7b0ce54
Change `CPSubsystem` and `SqlService` initialization in client
alexb5dh Jul 8, 2021
502c6c4
Fixes
alexb5dh Jul 8, 2021
70ac532
Save error details for `HazelcastSqlException`
alexb5dh Jul 8, 2021
0414394
Formatting settings
alexb5dh Jul 8, 2021
3c07be9
Separate query and command methods, update `SqlResult`
alexb5dh Jul 9, 2021
79941ae
Interface for `SqlQueryResult`
alexb5dh Jul 10, 2021
24f2174
Tests cleanup
alexb5dh Jul 10, 2021
1140e74
Refactor `SqlQueryResult` disposing
alexb5dh Jul 10, 2021
13a9d6a
Update `SqlQueryResult`
alexb5dh Jul 10, 2021
665396f
Tests update
alexb5dh Jul 10, 2021
7ed18bf
Code cleanup
alexb5dh Jul 10, 2021
1a25f20
Summary for `ISqlQueryResult`
alexb5dh Jul 10, 2021
7baa028
Jet engine query test
alexb5dh Jul 10, 2021
bc84609
Naming update
alexb5dh Jul 15, 2021
c30c88a
Make `SqlResultType` internal
alexb5dh Jul 15, 2021
e309d15
Formatting
alexb5dh Jul 15, 2021
2157a6a
`OffsetDateTime` format fixes
alexb5dh Jul 15, 2021
3a6c745
Update date/time decoding tests
alexb5dh Jul 15, 2021
461f863
Cancellation token for `ExecuteCommandAsync`
alexb5dh Jul 15, 2021
d253fda
SQL service summary and simplifying extension method
alexb5dh Jul 21, 2021
062ba57
ReSharper formatting config update
alexb5dh Jul 21, 2021
76c6379
Deserialization tests and small tests fix
alexb5dh Jul 21, 2021
bbb3958
Basic querying examples
alexb5dh Jul 21, 2021
cfb9b3c
`BigDecimal` codec fix and optimization
alexb5dh Jul 21, 2021
58d09f2
FIXME comments for some type mapping issues
alexb5dh Jul 21, 2021
8d0740b
Implement custom date/time types and update tests
alexb5dh Jul 22, 2021
7c9583f
Fix `ByteExtensionsTests`
alexb5dh Jul 23, 2021
aecf29d
Code and typo cleanup
alexb5dh Jul 23, 2021
caf3919
`Write*` methods for SQL date/time types
alexb5dh Jul 25, 2021
86abab9
Merge branch 'master' of https://github.com/hazelcast/hazelcast-cshar…
alexb5dh Jul 26, 2021
ce5c578
Update `HLocalDate` format to use int for Year
alexb5dh Jul 26, 2021
14214fa
Summary update
alexb5dh Jul 27, 2021
9f959b7
Serializers for new date/time types
alexb5dh Jul 27, 2021
310f939
Update tests with parameters serialization
alexb5dh Jul 27, 2021
e71f708
Formatting settings update
alexb5dh Jul 27, 2021
f5d137f
Abstract `SqlResult` class
alexb5dh Jul 31, 2021
61c2d2d
`HBigDecimal` implementation
alexb5dh Aug 2, 2021
6bba07c
SQL data types conversion/parsing tests and fixes
alexb5dh Aug 2, 2021
ddf58f6
More data types tests and fixes
alexb5dh Aug 3, 2021
a084454
`HBigDecimal` default serializer and test update
alexb5dh Aug 3, 2021
c4241fc
Separate class for SQL command execution result
alexb5dh Aug 3, 2021
5b89af9
Make `SqlService` methods non-async
alexb5dh Aug 3, 2021
89b0538
Interface fix
alexb5dh Aug 4, 2021
679854e
Add using statements to basic queries example
alexb5dh Aug 4, 2021
b2716f2
Organize tests and fix Jet test
alexb5dh Aug 4, 2021
b95fefa
Fixes
alexb5dh Aug 5, 2021
65f1db5
Tests cleanup
alexb5dh Aug 5, 2021
876066b
More tests
alexb5dh Aug 5, 2021
ec97084
Update, Delete Jet tests
alexb5dh Aug 5, 2021
9917dc8
Cancellation example
alexb5dh Aug 5, 2021
c676c92
Merge remote-tracking branch 'hazelcast/master' into feature/sql-support
alexb5dh Aug 5, 2021
2c51b31
Summary fix
alexb5dh Aug 5, 2021
b561f94
Add missing `using`s in tests
alexb5dh Aug 6, 2021
16b7d2f
Test `IPortable` fields query
alexb5dh Aug 6, 2021
58ceff8
Support for lowercase T in `HLocalDateTime` string
alexb5dh Aug 6, 2021
5b418bd
[WIP] Documentation
alexb5dh Aug 6, 2021
68cb52b
Documentation fixes
alexb5dh Aug 9, 2021
f21e51c
Add ToC
alexb5dh Aug 9, 2021
c1bd7eb
Format tweaks
alexb5dh Aug 9, 2021
22e2e34
More details on querying
alexb5dh Aug 9, 2021
9bf8ee7
Code cleanup
alexb5dh Aug 9, 2021
709d3a2
Summary update
alexb5dh Aug 9, 2021
5f8f937
Switch to `GetConnectionForSql`
alexb5dh Aug 11, 2021
afabd5e
Fix missed lock for `GetConnectionForSql`
alexb5dh Aug 12, 2021
7a29c41
Add new types for SQL
alexb5dh Aug 16, 2021
51b8a09
Fix and more cases for `ByteExtensionsTests`
alexb5dh Aug 16, 2021
9a1d0ec
Fix and more cases for `ByteExtensionsTests`
alexb5dh Aug 16, 2021
540d5e9
Merge remote-tracking branch 'hazelcast/master' into feature/sql-support
alexb5dh Aug 19, 2021
40f9232
Merge remote-tracking branch 'hazelcast/master' into feature/sql-types
alexb5dh Aug 19, 2021
04231e7
Switch to hazelcast-all package
alexb5dh Aug 19, 2021
e654281
Update RC version to 0.8
alexb5dh Aug 19, 2021
80a9cd3
Merge branch 'feature/hazelcast-all-package' into feature/sql-support
alexb5dh Aug 19, 2021
f1a0948
Update server to 5.0-SNAPSHOT in hz script
alexb5dh Aug 19, 2021
762534c
Move jet-enabled config to resource files
alexb5dh Aug 19, 2021
9149f1f
Merge remote-tracking branch 'hazelcast/master' into feature/sql-types
alexb5dh Aug 19, 2021
c7133cc
`MemberVersion.ToString` fix
alexb5dh Aug 19, 2021
17d9703
Merge remote-tracking branch 'hazelcast/master' into feature/sql-support
alexb5dh Aug 19, 2021
f389a4b
Merge remote-tracking branch 'hazelcast/master' into feature/sql-types
alexb5dh Aug 19, 2021
c92c6aa
Merge remote-tracking branch 'hazelcast/master' into feature/sql-support
alexb5dh Aug 19, 2021
ad7450c
Implement `GetConnectionForSql`
alexb5dh Aug 20, 2021
b9ea5a0
Tests for `GetConnectionForSql` in "dummy" mode
alexb5dh Aug 20, 2021
82590cb
Tests for `FindMemberOfLargerSameVersionGroup`
alexb5dh Aug 20, 2021
79aa067
Move new types to `Models` namespaces instead of `Sql`
alexb5dh Aug 20, 2021
2697878
Merge remote-tracking branch 'hazelcast/master' into feature/sql-types
alexb5dh Aug 22, 2021
5f7b752
Merge branch 'feature/sql-connection' into feature/sql-support
alexb5dh Aug 22, 2021
5604e08
Merge branch 'feature/sql-types' into feature/sql-support
alexb5dh Aug 22, 2021
31b2baf
Add missing copyright
alexb5dh Aug 22, 2021
3b33604
Merge fixes
alexb5dh Aug 22, 2021
ab4241d
PR fixes
alexb5dh Aug 23, 2021
427f3fe
Merge remote-tracking branch 'hazelcast/master' into feature/sql-support
alexb5dh Aug 23, 2021
8590817
Move jet_enabled config to Tests project
alexb5dh Aug 24, 2021
80d89af
Update client-protocol version
alexb5dh Aug 24, 2021
30764d1
Remove synchronous `EnumerateOnce`
alexb5dh Aug 24, 2021
ba8e4bc
`SqlQueryResult` changes
alexb5dh Aug 24, 2021
1776f6c
Changes to SQL-connection methods
alexb5dh Aug 24, 2021
fa6dfec
Warning fix
alexb5dh Aug 25, 2021
bb7da81
Tests tweaks
alexb5dh Aug 25, 2021
e711099
Merge remote-tracking branch 'hazelcast/master' into feature/sql-support
alexb5dh Aug 25, 2021
4add8a9
Tests cleanup
alexb5dh Aug 25, 2021
cc2cbb0
Remove `EnumerateOnceAsync`, implement `IAsyncEnumerable` directly
alexb5dh Aug 25, 2021
eecaad0
Update query cancellation example
alexb5dh Aug 25, 2021
81d6e1c
Remove public `IAsyncEnumerator` implementation
alexb5dh Aug 25, 2021
a3bde31
Cleanup
alexb5dh Aug 25, 2021
1b8e49c
Add missing `CfAwait` calls
alexb5dh Aug 25, 2021
90beda3
Add example for LINQ over `ISqlQueryResult`
alexb5dh Aug 25, 2021
7401bb2
Test for cancellation via `ToListAsync` token
alexb5dh Aug 25, 2021
9f3e40d
Update documentation
alexb5dh Aug 25, 2021
4729535
Fix failing tests ?!
zpqrtbnk Aug 27, 2021
8f6e673
Add tests for async
zpqrtbnk Aug 30, 2021
59991cb
Experiment with the SQL API
zpqrtbnk Aug 30, 2021
c69bda9
Catch TaskCancelledException not OperationCancelledException
zpqrtbnk Aug 31, 2021
3c52680
Fix hz script for 5.0
zpqrtbnk Aug 31, 2021
2ade2d3
Code cleanup
alexb5dh Sep 1, 2021
0fc0091
Docs update
alexb5dh Sep 1, 2021
c34a938
Extension methods with cancellation
alexb5dh Sep 1, 2021
cfe08e6
Merge remote-tracking branch 'hazelcast/master' into feature/sql-support
alexb5dh Sep 2, 2021
2c1ead1
Merge branch 'master' into feature/sql-support
alexb5dh Sep 2, 2021
c33e82b
Tests fix
alexb5dh Sep 2, 2021
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: 2 additions & 0 deletions Hazelcast.Net.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<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/Naming/CSharpNaming/Abbreviations/=CN/@EntryIndexedValue">CN</s:String>
<s:Boolean x:Key="/Default/PatternsAndTemplates/Todo/TodoPatterns/=438E8320080FDC46904A18FD18FF4DCD/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/Todo/TodoPatterns/=438E8320080FDC46904A18FD18FF4DCD/Color/@EntryValue">207, 157, 50</s:String>
<s:Boolean x:Key="/Default/PatternsAndTemplates/Todo/TodoPatterns/=438E8320080FDC46904A18FD18FF4DCD/MatchComments/@EntryValue">True</s:Boolean>
Expand All @@ -13,6 +14,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=endianness/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=expirations/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=multicast/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=nano/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=partitioner/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=retryable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=hzconsole/@EntryIndexedValue">True</s:Boolean>
Expand Down
16 changes: 15 additions & 1 deletion src/Hazelcast.Net.Tests/Core/ByteExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,21 @@ public void ReadGuid()
Assert.That(bytes.ReadGuidL(2), Is.EqualTo(Guid.Empty));
}

[Test]
[TestCase(new byte[]{0, 0xE5, 0x07, 0x07, 0x1E}, 1, "2021-07-30")]
public void ReadLocalDate(byte[] bytes, int position, string expected)
{
Assert.AreEqual(expected, bytes.ReadLocalDate(position));
}

[Test]
[TestCase(new byte[]{0, 0x0C, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 1, "12:17:16")]
[TestCase(new byte[]{0, 0x15, 0x3B, 0x38, 0x4E, 0x61, 0xBC, 0x00}, 1, "21:59:56.012345678")]
public void ReadLocalTime(byte[] bytes, int position, string expected)
{
Assert.AreEqual(expected, bytes.ReadLocalTime(position));
}

alexb5dh marked this conversation as resolved.
Show resolved Hide resolved
[Test]
public void ValidateUtf8()
{
Expand All @@ -431,7 +446,6 @@ public void ValidateUtf8()
Assert.That(Encoding.UTF8.GetString(encodingBytes), Is.EqualTo(s));
}


[Test]
public void FillSpan()
{
Expand Down
42 changes: 42 additions & 0 deletions src/Hazelcast.Net.Tests/Sql/SqlResultTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Threading.Tasks;
using Hazelcast.Sql;
using NUnit.Framework;

namespace Hazelcast.Tests.Sql
{
[TestFixture]
public class SqlResultTests: SqlTestBase
{
[Test]
public async Task EnumerateThrowsAfterClose()
{
var sqlService = await Client.GetSqlServiceAsync();

var result = await sqlService.ExecuteAsync($"SELECT * FROM {MapName}");
await result.DisposeAsync();

Assert.Throws<ObjectDisposedException>(() => result.EnumerateOnce());
}

[Test]
[TestCase(1)]
[TestCase(2)]
[TestCase(.5)]
[TestCase(.33)]
public async Task Enumerate(double pageSizeRatio)
{
var sqlService = await Client.GetSqlServiceAsync();

var result = await sqlService.ExecuteAsync($"SELECT * FROM {MapName}",
options: new SqlStatementOptions { CursorBufferSize = (int)(MapValues.Count * pageSizeRatio) }
);

Assert.DoesNotThrowAsync(async () =>
{
await foreach (var row in result.EnumerateOnceAsync())
GC.KeepAlive(row);
});
}
}
}
68 changes: 68 additions & 0 deletions src/Hazelcast.Net.Tests/Sql/SqlServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;

namespace Hazelcast.Tests.Sql
{
[TestFixture]
public class SqlServiceTests: SqlTestBase
{
[Test]
public async Task Execute()
{
var sql = await Client.GetSqlServiceAsync();
var result = await sql.ExecuteAsync($"SELECT * FROM {MapName}");

var expectedValues = MapValues;
var resultValues = result.EnumerateOnce().ToDictionary(r => r.GetKey<string>(), r => r.GetValue<int>());

CollectionAssert.AreEquivalent(expectedValues, resultValues);
}

[Test]
[TestCase(0)]
[TestCase(1)]
[TestCase(5)]
[TestCase(100)]
public async Task ExecuteWithIntParameter(int minValue)
{
var sql = await Client.GetSqlServiceAsync();
var result = await sql.ExecuteAsync($"SELECT * FROM {MapName} WHERE this >= ?", new object[] { minValue });

var expectedValues = MapValues.Where(p => p.Value >= minValue);
var resultValues = result.EnumerateOnce().ToDictionary(r => r.GetKey<string>(), r => r.GetValue<int>());

CollectionAssert.AreEquivalent(expectedValues, resultValues);
}

[Test]
[TestCase("0")]
[TestCase("1")]
[TestCase("5")]
[TestCase("100")]
public async Task ExecuteWithStringParameter(string key)
{
var sql = await Client.GetSqlServiceAsync();
var result = await sql.ExecuteAsync($"SELECT * FROM {MapName} WHERE __key == ?", new object[] { key });

var expectedValues = MapValues.Where(p => p.Key == key);
var resultValues = result.EnumerateOnce().ToDictionary(r => r.GetKey<string>(), r => r.GetValue<int>());

CollectionAssert.AreEquivalent(expectedValues, resultValues);
}

[OneTimeSetUp]
public async Task InitAll()
{
var map = await Client.GetMapAsync<string, int>(MapName);
await map.SetAllAsync(MapValues);
}

[OneTimeTearDown]
public async Task DisposeAll()
{
var map = await Client.GetMapAsync<string, int>(MapName);
await map.ClearAsync();
}
}
}
30 changes: 30 additions & 0 deletions src/Hazelcast.Net.Tests/Sql/SqlTestBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Hazelcast.Testing;
using NUnit.Framework;

namespace Hazelcast.Tests.Sql
{
public class SqlTestBase : SingleMemberClientRemoteTestBase
{
protected const string MapName = "MyMap";

protected readonly Dictionary<string, int> MapValues = Enumerable.Range(1, 5)
.ToDictionary(i => $"{i}", i => i);

[OneTimeSetUp]
private async Task InitAll()
{
var map = await Client.GetMapAsync<string, int>(MapName);
await map.SetAllAsync(MapValues);
}

[OneTimeTearDown]
private async Task DisposeAll()
{
var map = await Client.GetMapAsync<string, int>(MapName);
await map.ClearAsync();
}
}
}
9 changes: 9 additions & 0 deletions src/Hazelcast.Net/Core/BytesExtensions.Protocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,21 @@ public static void WriteGuidL(this byte[] bytes, int position, Guid value)
public static void WriteByteL(this byte[] bytes, int position, byte value)
=> bytes.WriteByte(position, value);

public static short ReadShortL(this byte[] bytes, int position)
=> bytes.ReadShort(position, Endianness.LittleEndian);

public static long ReadLongL(this byte[] bytes, int position)
=> bytes.ReadLong(position, Endianness.LittleEndian);

public static int ReadIntL(this byte[] bytes, int position)
=> bytes.ReadInt(position, Endianness.LittleEndian);

public static float ReadFloatL(this byte[] bytes, int position)
=> bytes.ReadFloat(position, Endianness.LittleEndian);

public static double ReadDoubleL(this byte[] bytes, int position)
=> bytes.ReadDouble(position, Endianness.LittleEndian);

public static bool ReadBoolL(this byte[] bytes, int position)
=> bytes.ReadBool(position);

Expand Down
41 changes: 41 additions & 0 deletions src/Hazelcast.Net/Core/BytesExtensions.ReadFromByteArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,48 @@ public static long ReadLong(this byte[] bytes, int position, Endianness endianne
}
}

public static string ReadLocalDate(this byte[] bytes, int position)
{
var year = bytes.ReadShortL(position);
var month = bytes.ReadByte(position + SizeOfShort);
var date = bytes.ReadByte(position + SizeOfShort + SizeOfByte);

return $"{year:D4}-{month:D2}-{date:D2}";
}

public static string ReadLocalTime(this byte[] bytes, int position)
{
var hour = bytes.ReadByte(position);
var minute = bytes.ReadByte(position + SizeOfByte);
var second = bytes.ReadByte(position + SizeOfByte * 2);
var nano = bytes.ReadIntL(position + SizeOfByte * 3);

return nano == 0
? $"{hour:D2}:{minute:D2}:{second:D2}"
: $"{hour:D2}:{minute:D2}:{second:D2}.{nano:D9}";
}

public static string ReadLocalDateTime(this byte[] bytes, int position)
{
var date = ReadLocalDate(bytes, position);
var time = ReadLocalTime(bytes, position + SizeOfLocalDate);
return $"{date}T{time}";
}

public static string ReadOffsetDateTime(this byte[] bytes, int position)
{
var localDateTime = ReadLocalDate(bytes, position);
var offsetSeconds = ReadIntL(bytes, position + SizeOfLocalDateTime);

var offsetMinutes = Math.Abs(offsetSeconds / 60);
if (offsetMinutes == 0)
return localDateTime + 'Z';

var offsetModifier = offsetSeconds < 0 ? '-' : '+';
var offsetHours = offsetMinutes / 60;
offsetMinutes %= 60;
return $"{localDateTime}{offsetModifier}{offsetHours}:{offsetMinutes}";
}

/// <summary>
/// Reads a <see cref="float"/> value from an array of bytes.
Expand Down
20 changes: 20 additions & 0 deletions src/Hazelcast.Net/Core/BytesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,26 @@ internal static partial class BytesExtensions
/// </summary>
public const int SizeOfGuid = (1 + 16) * SizeOfByte;

/// <summary>
/// Gets the size of a Java LocalDate value in arrays or sequences of bytes.
/// </summary>
public const int SizeOfLocalDate = SizeOfShort + SizeOfByte * 2;

/// <summary>
/// Gets the size of a Java LocalTime value in arrays or sequences of bytes.
/// </summary>
public const int SizeOfLocalTime = SizeOfInt + SizeOfByte * 3;

/// <summary>
/// Gets the size of a Java LocalDateTime value in arrays or sequences of bytes.
/// </summary>
public const int SizeOfLocalDateTime = SizeOfLocalDate + SizeOfLocalTime;

/// <summary>
/// Gets the size of a Java OffsetDateTime value in arrays or sequences of bytes.
/// </summary>
public const int SizeOfOffsetDateTime = SizeOfLocalDateTime + SizeOfInt;

/// <summary>
/// Copies a sequence of <typeparamref name="T"/> to a span of <typeparamref name="T"/>.
/// </summary>
Expand Down
31 changes: 31 additions & 0 deletions src/Hazelcast.Net/Core/CollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Hazelcast.Serialization.Collections;

namespace Hazelcast.Core
{
Expand All @@ -33,5 +35,34 @@ internal static class CollectionExtensions
if (source == null) throw new ArgumentNullException(nameof(source));
return source.Remove(new KeyValuePair<TKey, TValue>(key, value));
}

/// <summary>
/// Creates a new array and copies all data from <paramref name="array"/> starting from <paramref name="startIncl"/> and up to <paramref name="endExcl"/> indices.
/// </summary>
/// <remarks>
/// Similar to Array.prototype.slice method in JavaScript.
/// </remarks>
public static T[] Slice<T>(this T[] array, long startIncl, long endExcl)
{
var res = new T[endExcl - startIncl];
Array.Copy(
sourceArray: array, sourceIndex: startIncl,
destinationArray: res, destinationIndex: 0, length: res.Length
);

return res;
}

/// <summary>
/// Returns read-only wrapper for <paramref name="list"/>
/// or <paramref name="list"/> itself if it already implements <see cref="IReadOnlyList{T}"/>.
/// </summary>
public static IReadOnlyList<T> AsReadOnly<T>(this IList<T> list) => list as IReadOnlyList<T> ?? new ReadOnlyCollection<T>(list);

/// <summary>
/// Returns read-only wrapper for <paramref name="list"/> where each element is returned as <see cref="object"/> with boxing performed if needed
/// or <paramref name="list"/> itself if it already implements <see cref="IReadOnlyList{T}"/> (T is <see cref="object"/>).
/// </summary>
public static IReadOnlyList<object> AsReadOnlyObjectList<T>(this IList<T> list) => list as IReadOnlyList<object> ?? new ReadOnlyObjectList<T>(list);
}
}
11 changes: 11 additions & 0 deletions src/Hazelcast.Net/Core/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,16 @@ public static IEnumerable<(T1, T2, T3, T4)> Combine<T1, T2, T3, T4>(this (IEnume
/// <returns>A <see cref="Dictionary{TKey,TValue}"/> that contains values provided by <paramref name="source"/>.</returns>
public static IDictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IEnumerable<(TKey Key, TValue Value)> source)
=> source.ToDictionary(x => x.Key, x => x.Value);

/// <summary>
/// Enumerates <paramref name="source"/> to a new <see cref="List{T}"/> starting from <paramref name="initialCapacity"/> size.
/// This allows to avoid or minimize list resizing if number of elements if known fully or approximately.
/// </summary>
public static List<T> ToList<T>(this IEnumerable<T> source, int initialCapacity)
{
var list = new List<T>(initialCapacity);
list.AddRange(source);
return list;
}
}
}
11 changes: 11 additions & 0 deletions src/Hazelcast.Net/HazelcastClient.Objects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Threading.Tasks;
using Hazelcast.Clustering;
using Hazelcast.Core;
using Hazelcast.CP;
using Hazelcast.DistributedObjects;
using Hazelcast.DistributedObjects.Impl;
using Hazelcast.Serialization;
using Hazelcast.Sql;
using Microsoft.Extensions.Logging;

namespace Hazelcast
Expand All @@ -28,6 +30,9 @@ internal partial class HazelcastClient // Distributed Objects
private readonly ISequence<long> _lockReferenceIdSequence = new Int64Sequence();
private ICPSubsystem _cpSubsystem;

// FIXME [Oleksii] discuss if lazy is needed
alexb5dh marked this conversation as resolved.
Show resolved Hide resolved
private readonly Lazy<ISqlService> _sqlServiceLazy;

/// <summary>
/// Gets the CP subsystem.
/// </summary>
Expand Down Expand Up @@ -189,5 +194,11 @@ Task<IHRingBuffer<T>> GetRingBufferAsync<T>(string name)
return await task.CfAwait();
#endif
}

/// <inheritdoc />
public Task<ISqlService> GetSqlServiceAsync()
{
return Task.FromResult(_sqlServiceLazy.Value);
}
}
}
Loading