@@ -66,28 +66,37 @@ func Example_explainQuery() {
6666 ctx := context .TODO ()
6767 db , err := ydb .Open (ctx , "grpc://localhost:2136/local" )
6868 if err != nil {
69- fmt .Printf ("failed connect: %v" , err )
70-
71- return
69+ panic (err )
7270 }
73- defer db .Close (ctx ) // cleanup resources
71+ defer db .Close (ctx ) // cleanup resources
72+ var (
73+ plan string
74+ ast string
75+ )
7476 err = db .Table ().Do ( // Do retry operation on errors with best effort
7577 ctx , // context manage exiting from Do
7678 func (ctx context.Context , s table.Session ) (err error ) { // retry operation
77- explanation , err := s .Explain (ctx , `SELECT 42 as id, "my string" as myStr` )
79+ explanation , err := s .Explain (ctx , `
80+ DECLARE $id AS Optional<Uint64>;
81+ DECLARE $myStr AS Optional<Text>;
82+ SELECT $id AS id, $myStr AS myStr;
83+ ` )
7884 if err != nil {
7985 return err // for auto-retry with driver
8086 }
8187
82- fmt . Printf ( " plan: %s \n \n AST: %s" , explanation .Plan , explanation .AST )
88+ plan , ast = explanation .Plan , explanation .AST
8389
8490 return nil
8591 },
8692 table .WithIdempotent (),
8793 )
8894 if err != nil {
89- fmt . Printf ( "unexpected error: %v" , err )
95+ panic ( err )
9096 }
97+
98+ fmt .Printf ("Plan: %s\n " , plan )
99+ fmt .Printf ("AST: %s\n " , ast )
91100}
92101
93102func Example_createTable () {
0 commit comments