Skip to content

Commit

Permalink
added example for explain query usning table service
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyasnikov committed May 15, 2024
1 parent f9d63e0 commit cd3bc77
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions table/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,34 @@ func Example_select() {
}
}

func Example_explainQuery() {
ctx := context.TODO()
db, err := ydb.Open(ctx, "grpc://localhost:2136/local")
if err != nil {
fmt.Printf("failed connect: %v", err)

return
}
defer db.Close(ctx) // cleanup resources

Check failure on line 73 in table/example_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/ydb-platform/ydb-go-sdk/v3) (gci)
err = db.Table().Do( // Do retry operation on errors with best effort
ctx, // context manage exiting from Do
func(ctx context.Context, s table.Session) (err error) { // retry operation
explanation, err := s.Explain(ctx, `SELECT 42 as id, "my string" as myStr`)
if err != nil {
return err // for auto-retry with driver
}

fmt.Printf("plan: %s\n\nAST: %s", explanation.Plan, explanation.AST)

return nil
},
table.WithIdempotent(),
)
if err != nil {
fmt.Printf("unexpected error: %v", err)
}
}

func Example_createTable() {
ctx := context.TODO()
db, err := ydb.Open(ctx, "grpc://localhost:2136/local")
Expand Down

0 comments on commit cd3bc77

Please sign in to comment.