-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added
table.options.WithIgnoreTruncated
option for `session.Execu…
…te` method * Added `table.result.ErrTruncated` error for check it with `errors.Is()` outside of `ydb-go-sdk`
- Loading branch information
1 parent
66a967f
commit 5c10c95
Showing
7 changed files
with
170 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package result | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
var ErrTruncated = errors.New("truncated result") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
//go:build integration | ||
// +build integration | ||
|
||
package integration | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/ydb-platform/ydb-go-sdk/v3/table" | ||
"github.com/ydb-platform/ydb-go-sdk/v3/table/options" | ||
"github.com/ydb-platform/ydb-go-sdk/v3/table/result" | ||
"github.com/ydb-platform/ydb-go-sdk/v3/table/types" | ||
) | ||
|
||
// https://github.com/ydb-platform/ydb-go-sdk/issues/798 | ||
func TestIssue798TruncatedError(t *testing.T) { | ||
const rowsLimit = 1000 | ||
var ( | ||
scope = newScope(t) | ||
driver = scope.Driver() | ||
tablePath = scope.TablePath() | ||
) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
// upsert rows | ||
{ | ||
rows := make([]types.Value, rowsLimit) | ||
for i := range rows { | ||
rows[i] = types.StructValue( | ||
types.StructFieldValue("id", types.Int64Value(int64(i))), | ||
types.StructFieldValue("val", types.TextValue(strconv.Itoa(i))), | ||
) | ||
} | ||
err := driver.Table().Do(ctx, func(ctx context.Context, s table.Session) error { | ||
return s.BulkUpsert(ctx, tablePath, types.ListValue(rows...)) | ||
}, table.WithIdempotent()) | ||
scope.Require.NoError(err) | ||
} | ||
|
||
// select rows without truncated error | ||
{ | ||
err := driver.Table().Do(ctx, func(ctx context.Context, s table.Session) error { | ||
_, results, err := s.Execute(ctx, | ||
table.DefaultTxControl(), | ||
fmt.Sprintf("SELECT * FROM `%s`;", tablePath), | ||
nil, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
if err = results.NextResultSetErr(ctx); err != nil { | ||
return fmt.Errorf("no result sets: %w", err) | ||
} | ||
if results.CurrentResultSet().RowCount() != rowsLimit { | ||
return fmt.Errorf("unexpected rows count: %d", results.CurrentResultSet().RowCount()) | ||
} | ||
return results.Err() | ||
}, table.WithIdempotent()) | ||
scope.Require.NoError(err) | ||
} | ||
|
||
// upsert 1 row for get 1001 rows and truncated error | ||
{ | ||
err := driver.Table().Do(ctx, func(ctx context.Context, s table.Session) error { | ||
return s.BulkUpsert(ctx, tablePath, types.ListValue(types.StructValue( | ||
types.StructFieldValue("id", types.Int64Value(rowsLimit)), | ||
types.StructFieldValue("val", types.TextValue(strconv.Itoa(rowsLimit))), | ||
))) | ||
}, table.WithIdempotent()) | ||
scope.Require.NoError(err) | ||
} | ||
|
||
// select all rows with truncated error | ||
{ | ||
err := driver.Table().Do(ctx, func(ctx context.Context, s table.Session) error { | ||
_, results, err := s.Execute(ctx, | ||
table.DefaultTxControl(), | ||
fmt.Sprintf("SELECT * FROM `%s`;", tablePath), | ||
nil, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
if err = results.NextResultSetErr(ctx); err != nil { | ||
return fmt.Errorf("no result sets: %w", err) | ||
} | ||
if results.CurrentResultSet().RowCount() != rowsLimit { | ||
return fmt.Errorf("unexpected rows count: %d", results.CurrentResultSet().RowCount()) | ||
} | ||
return results.Err() // expected | ||
}, table.WithIdempotent()) | ||
scope.Require.ErrorIs(err, result.ErrTruncated) | ||
} | ||
|
||
// select all rows with truncated error | ||
{ | ||
err := driver.Table().Do(ctx, func(ctx context.Context, s table.Session) error { | ||
_, results, err := s.Execute(ctx, | ||
table.DefaultTxControl(), | ||
fmt.Sprintf("SELECT * FROM `%s`;", tablePath), | ||
nil, | ||
options.WithIgnoreTruncated(), | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
if err = results.NextResultSetErr(ctx); err != nil { | ||
return fmt.Errorf("no result sets: %w", err) | ||
} | ||
if results.CurrentResultSet().RowCount() != rowsLimit { | ||
return fmt.Errorf("unexpected rows count: %d", results.CurrentResultSet().RowCount()) | ||
} | ||
return results.Err() // expected | ||
}, table.WithIdempotent()) | ||
scope.Require.NoError(err) | ||
} | ||
} |