-
Couldn't load subscription status.
- Fork 104
feat: expose query warnings #1882
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
base: master
Are you sure you want to change the base?
Changes from 5 commits
a13353e
5ab9123
4dcedbf
406087d
6e80cb7
64bdd88
c58d904
7ab9e1e
b2fc9cb
9225877
bac626c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package query | ||
|
|
||
| import ( | ||
| "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Issue" | ||
| "google.golang.org/grpc" | ||
|
|
||
| "github.com/ydb-platform/ydb-go-sdk/v3/internal/params" | ||
|
|
@@ -57,6 +58,10 @@ func WithStatsMode(mode options.StatsMode, callback func(Stats)) ExecuteOption { | |
| return options.WithStatsMode(mode, callback) | ||
| } | ||
|
|
||
| func WithIssuesHandler(callback func(issues []*Ydb_Issue.IssueMessage)) ExecuteOption { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need a description There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
| return options.WithIssuesHandler(callback) | ||
| } | ||
|
|
||
| // WithResponsePartLimitSizeBytes limit size of each part (data portion) in stream for query service resoponse | ||
| // it isn't limit total size of answer | ||
| func WithResponsePartLimitSizeBytes(size int64) ExecuteOption { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,7 @@ import ( | |||||||
|
|
||||||||
| "github.com/google/uuid" | ||||||||
| "github.com/stretchr/testify/require" | ||||||||
| "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Issue" | ||||||||
|
|
||||||||
| "github.com/ydb-platform/ydb-go-sdk/v3" | ||||||||
| "github.com/ydb-platform/ydb-go-sdk/v3/internal/decimal" | ||||||||
|
|
@@ -771,3 +772,82 @@ func TestIssue1785FillDecimalFields(t *testing.T) { | |||||||
| require.EqualValues(t, expectedVal, rd.DecimalVal) | ||||||||
| }) | ||||||||
| } | ||||||||
|
|
||||||||
| // https://github.com/ydb-platform/ydb-go-sdk/issues/1872 | ||||||||
| func TestIssue1872QueryWarning(t *testing.T) { | ||||||||
| ctx, cancel := context.WithCancel(xtest.Context(t)) | ||||||||
| defer cancel() | ||||||||
| db, err := ydb.Open(ctx, | ||||||||
| os.Getenv("YDB_CONNECTION_STRING"), | ||||||||
| ydb.WithAccessTokenCredentials(os.Getenv("YDB_ACCESS_TOKEN_CREDENTIALS")), | ||||||||
| ydb.WithTraceQuery( | ||||||||
| log.Query( | ||||||||
| log.Default(os.Stdout, | ||||||||
| log.WithLogQuery(), | ||||||||
| log.WithColoring(), | ||||||||
| log.WithMinLevel(log.INFO), | ||||||||
| ), | ||||||||
| trace.QueryEvents, | ||||||||
| ), | ||||||||
| ), | ||||||||
| ) | ||||||||
| require.NoError(t, err) | ||||||||
| _ = db.Query().Exec(ctx, | ||||||||
| `drop table TestIssue1872QueryWarning;`, | ||||||||
| ) | ||||||||
| err = db.Query().Exec(ctx, | ||||||||
| `create table TestIssue1872QueryWarning | ||||||||
| (Id uint64, Amount decimal(22,9) , primary key(Id));`, | ||||||||
| query.WithParameters( | ||||||||
| ydb.ParamsBuilder(). | ||||||||
| Param("$p1").Text("test1"). | ||||||||
| Build(), | ||||||||
| ), | ||||||||
| ) | ||||||||
| require.NoError(t, err) | ||||||||
|
|
||||||||
| t.Run("Query", func(t *testing.T) { | ||||||||
| var issueList []*Ydb_Issue.IssueMessage | ||||||||
| q := db.Query() | ||||||||
| result, err := q.Query(ctx, ` | ||||||||
| insert into TestIssue1872QueryWarning (Id, Amount) values (-3, Decimal("3.01",22,9)); | ||||||||
|
||||||||
| insert into TestIssue1872QueryWarning (Id, Amount) values (-5, Decimal("5.01",22,9)); | ||||||||
|
||||||||
| `, | ||||||||
| query.WithParameters( | ||||||||
| ydb.ParamsBuilder(). | ||||||||
| Param("$p1").Text("test"). | ||||||||
| Build(), | ||||||||
| ), | ||||||||
| query.WithSyntax(query.SyntaxYQL), | ||||||||
| query.WithIdempotent(), | ||||||||
| query.WithIssuesHandler(func(issues []*Ydb_Issue.IssueMessage) { | ||||||||
| issueList = issues | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can add asserts inside callback:
Suggested change
and other asserts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||||||||
| fmt.Printf("len=%d", len(issues)) | ||||||||
xelavopelk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
| }), | ||||||||
| ) | ||||||||
| require.NoError(t, err) | ||||||||
| require.Equal(t, 1, len(issueList)) | ||||||||
| require.Equal(t, "Type annotation", issueList[0].Message) | ||||||||
| require.Equal(t, 2, len(issueList[0].Issues)) | ||||||||
| require.Equal(t, "At function: KiWriteTable!", issueList[0].Issues[0].Message) | ||||||||
| require.Equal(t, | ||||||||
| "Failed to convert type: Struct<'Amount':Decimal(22,9),'Id':Int32> to Struct<'Amount':Decimal(22,9)?,'Id':Uint64?>", | ||||||||
| issueList[0].Issues[0].Issues[0].Message) | ||||||||
| fmt.Printf("%#v", result) | ||||||||
| }) | ||||||||
|
|
||||||||
| t.Run("Exec", func(t *testing.T) { | ||||||||
| var issueList []*Ydb_Issue.IssueMessage | ||||||||
| q := db.Query() | ||||||||
| err := q.Exec(ctx, ` | ||||||||
| insert into TestIssue1872QueryWarning (Id, Amount) values (-7, Decimal("37.01",22,9)); | ||||||||
| `, | ||||||||
| query.WithIssuesHandler(func(issues []*Ydb_Issue.IssueMessage) { | ||||||||
| issueList = issues | ||||||||
| fmt.Printf("len=%d", len(issues)) | ||||||||
xelavopelk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
| }), | ||||||||
| ) | ||||||||
| require.NoError(t, err) | ||||||||
| require.Equal(t, 1, len(issueList)) | ||||||||
| }) | ||||||||
| } | ||||||||
Uh oh!
There was an error while loading. Please reload this page.