Skip to content

Commit 928ee4d

Browse files
committed
chore: add options for numRows and encoding
1 parent dd4ed73 commit 928ee4d

File tree

9 files changed

+35
-22
lines changed

9 files changed

+35
-22
lines changed

spannerlib/api/rows.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import (
1313
"google.golang.org/protobuf/types/known/structpb"
1414
)
1515

16+
type EncodeRowOption int32
17+
18+
const (
19+
EncodeRowOptionProto EncodeRowOption = iota
20+
)
21+
1622
func Metadata(poolId, connId, rowsId int64) (*spannerpb.ResultSetMetadata, error) {
1723
res, err := findRows(poolId, connId, rowsId)
1824
if err != nil {

spannerlib/dotnet-spannerlib/Google.Cloud.SpannerLib.Native/Google.Cloud.SpannerLib.Native.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<PackageId>Experimental.SpannerLib.Native</PackageId>
99
<Title>Experimental native library for Spanner</Title>
1010
<Authors />
11-
<Version>1.0.10</Version>
11+
<Version>1.0.11</Version>
1212
</PropertyGroup>
1313

1414
<ItemGroup>

spannerlib/dotnet-spannerlib/Google.Cloud.SpannerLib.Native/SpannerLib.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace Google.Cloud.SpannerLib.Native
88
public static class SpannerLib
99
{
1010
private const string SpannerLibName = "spannerlib";
11-
//private const string SpannerLibName = "/Users/loite/CLionProjects/spannerlib/cmake-build-release/libspannerlib.dylib";
1211

1312
[DllImport(SpannerLibName, EntryPoint = "Release")]
1413
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
@@ -61,7 +60,7 @@ internal static extern Message BufferWrite(long poolId, long connectionId, long
6160

6261
[DllImport(SpannerLibName, EntryPoint = "Next")]
6362
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
64-
internal static extern Message Next(long poolId, long connectionId, long rowsId);
63+
internal static extern Message Next(long poolId, long connectionId, long rowsId, int numRows, int encodeRowOption);
6564

6665
[DllImport(SpannerLibName, EntryPoint = "CloseRows")]
6766
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]

spannerlib/dotnet-spannerlib/Google.Cloud.SpannerLib.Native/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ mkdir -p libraries/any
55

66
# Clear all local nuget cache
77
dotnet nuget locals --clear all
8-
go build -o ../../spannerlib.so -buildmode=c-shared ../../shared_lib.go
9-
cp ../../spannerlib.so $DEST
8+
go build -o ../../shared/spannerlib.so -buildmode=c-shared ../../shared/shared_lib.go
9+
cp ../../shared/spannerlib.so $DEST
1010
dotnet pack
1111
dotnet nuget remove source local 2>/dev/null
1212
dotnet nuget add source "$PWD"/bin/Release --name local

spannerlib/dotnet-spannerlib/Google.Cloud.SpannerLib/GrpcLibSpanner.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ await stream.RequestStream.WriteAsync(new ConnectionStreamRequest
149149
return _lib.ResultSetStats(ToProto(rows));
150150
}
151151

152-
public ListValue? Next(Rows rows)
152+
public ListValue? Next(Rows rows, int numRows, ISpanner.RowEncoding encoding)
153153
{
154154
var row = _lib.Next(ToProto(rows));
155155
if (row.Values.Count == 0)
@@ -159,13 +159,13 @@ await stream.RequestStream.WriteAsync(new ConnectionStreamRequest
159159
return row;
160160
}
161161

162-
public async Task<ListValue?> NextAsync(Rows rows)
162+
public async Task<ListValue?> NextAsync(Rows rows, int numRows, ISpanner.RowEncoding encoding)
163163
{
164164
if (_streams.TryGetValue(rows.Connection.Id, out var stream))
165165
{
166166
return await NextStreaming(stream, rows);
167167
}
168-
return await Task.Run(() => Next(rows));
168+
return await Task.Run(() => Next(rows, numRows, encoding));
169169
}
170170

171171
private async Task<ListValue?> NextStreaming(AsyncDuplexStreamingCall<ConnectionStreamRequest, ConnectionStreamResponse> stream, Rows rows)

spannerlib/dotnet-spannerlib/Google.Cloud.SpannerLib/ISpanner.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ namespace Google.Cloud.SpannerLib;
66

77
public interface ISpanner
88
{
9+
public enum RowEncoding
10+
{
11+
Proto,
12+
}
13+
914
public Pool CreatePool(string dsn);
1015

1116
public void ClosePool(Pool pool);
@@ -34,9 +39,9 @@ public interface ISpanner
3439

3540
public ResultSetStats? Stats(Rows rows);
3641

37-
public ListValue? Next(Rows rows);
42+
public ListValue? Next(Rows rows, int numRows, RowEncoding encoding);
3843

39-
public Task<ListValue?> NextAsync(Rows rows);
44+
public Task<ListValue?> NextAsync(Rows rows, int numRows, RowEncoding encoding);
4045

4146
public void CloseRows(Rows rows);
4247

spannerlib/dotnet-spannerlib/Google.Cloud.SpannerLib/Rows.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public async Task InitMetadataAsync()
7070
{
7171
if (_stream == null)
7272
{
73-
var res = Spanner.Next(this);
73+
var res = Spanner.Next(this, 1, ISpanner.RowEncoding.Proto);
7474
if (res == null && !_stats.IsValueCreated)
7575
{
7676
// initialize stats.
@@ -95,7 +95,7 @@ public async Task InitMetadataAsync()
9595
{
9696
if (_stream == null)
9797
{
98-
return await Spanner.NextAsync(this);
98+
return await Spanner.NextAsync(this, 1, ISpanner.RowEncoding.Proto);
9999
}
100100
if (await _stream.ResponseStream.MoveNext())
101101
{

spannerlib/dotnet-spannerlib/Google.Cloud.SpannerLib/SharedLibSpanner.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,15 @@ public Task<long[]> ExecuteBatchAsync(Connection connection, ExecuteBatchDmlRequ
158158
return handler.Length == 0 ? null : ResultSetStats.Parser.ParseFrom(handler.Value());
159159
}
160160

161-
public ListValue? Next(Rows rows)
161+
public ListValue? Next(Rows rows, int numRows, ISpanner.RowEncoding encoding)
162162
{
163-
using var handler = ExecuteLibraryFunction(() => Native.SpannerLib.Next(rows.Connection.Pool.Id, rows.Connection.Id, rows.Id));
163+
using var handler = ExecuteLibraryFunction(() => Native.SpannerLib.Next(rows.Connection.Pool.Id, rows.Connection.Id, rows.Id, numRows, (int) encoding));
164164
return handler.Length == 0 ? null : ListValue.Parser.ParseFrom(handler.Value());
165165
}
166166

167-
public async Task<ListValue?> NextAsync(Rows rows)
167+
public async Task<ListValue?> NextAsync(Rows rows, int numRows, ISpanner.RowEncoding encoding)
168168
{
169-
return await Task.Run(() => Next(rows));
169+
return await Task.Run(() => Next(rows, numRows, encoding));
170170
}
171171

172172
public void CloseRows(Rows rows)

spannerlib/shared/shared_lib.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@ func pin(msg *lib.Message) (int64, int32, int64, int32, unsafe.Pointer) {
5454
}
5555

5656
// CreatePool creates a pool of database connections. A Pool is equivalent to a *sql.DB.
57+
// All connections that are created from a pool share the same underlying Spanner client.
5758
//
5859
//export CreatePool
5960
func CreatePool(dsn string) (int64, int32, int64, int32, unsafe.Pointer) {
6061
msg := lib.CreatePool(dsn)
6162
return pin(msg)
6263
}
6364

64-
// ClosePool closes a previously opened Pool.
65+
// ClosePool closes a previously opened Pool. All connections in the pool are also closed.
6566
//
6667
//export ClosePool
6768
func ClosePool(id int64) (int64, int32, int64, int32, unsafe.Pointer) {
@@ -81,6 +82,9 @@ func CreateConnection(poolId int64) (int64, int32, int64, int32, unsafe.Pointer)
8182
return pin(msg)
8283
}
8384

85+
// CloseConnection closes a previously opened connection and releases all resources
86+
// associated with the connection.
87+
//
8488
//export CloseConnection
8589
func CloseConnection(poolId, connId int64) (int64, int32, int64, int32, unsafe.Pointer) {
8690
msg := lib.CloseConnection(poolId, connId)
@@ -155,12 +159,11 @@ func ResultSetStats(poolId, connId, rowsId int64) (int64, int32, int64, int32, u
155159
// ListValue that contains all the columns of the row. The message is empty if there are
156160
// no more rows in the Rows object.
157161
//
158-
// TODO: Add support for:
159-
// 1. Fetching more than one row at a time.
160-
// 2. Specifying the return type (e.g. proto, struct, ...)
161-
//
162162
//export Next
163-
func Next(poolId, connId, rowsId int64) (int64, int32, int64, int32, unsafe.Pointer) {
163+
func Next(poolId, connId, rowsId int64, numRows int32, encodeRowOption int32) (int64, int32, int64, int32, unsafe.Pointer) {
164+
// TODO: Implement support for:
165+
// 1. Fetching more than one row at a time.
166+
// 2. Specifying the return type (e.g. proto, struct, ...)
164167
msg := lib.Next(poolId, connId, rowsId)
165168
return pin(msg)
166169
}

0 commit comments

Comments
 (0)