Skip to content

Commit

Permalink
* Fixed error Empty query text using prepared statements and `ydb.W…
Browse files Browse the repository at this point in the history
…ithExecuteDataQueryOverQueryClient(true)` option

* Prepared statements always send query text on Execute call from now (previous behaviour - send query ID)
  • Loading branch information
asmyasnikov committed Feb 6, 2025
1 parent 6464f7d commit dca11b0
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Fixed error `Empty query text` using prepared statements and `ydb.WithExecuteDataQueryOverQueryClient(true)` option
* Prepared statements always send query text on Execute call from now (previous behaviour - send query ID)
* Prevented create decoder instance until start read a message from topics

## v3.99.4
Expand Down
2 changes: 1 addition & 1 deletion internal/table/data_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (q preparedQuery) YQL() string {

func (q preparedQuery) toYDB(a *allocator.Allocator) *Ydb_Table.Query {
query := a.TableQuery()
query.Query = a.TableQueryID(q.id)
query.Query = a.TableQueryYqlText(q.sql)

return query
}
Expand Down
59 changes: 59 additions & 0 deletions tests/integration/table_regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"

"github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/scanner"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
"github.com/ydb-platform/ydb-go-sdk/v3/table"
Expand Down Expand Up @@ -514,3 +515,61 @@ func (c *customTestUnmarshalUUIDTyped) UnmarshalYDB(raw scanner.RawValue) error
func (c *customTestUnmarshalUUIDTyped) String() string {
return string(*c)
}

func TestRegressionIssue1636(t *testing.T) {
for _, tt := range []struct {
name string
executeDataQueryOverQueryService bool
}{
{
name: "ydb.WithExecuteDataQueryOverQueryClient(false)",
executeDataQueryOverQueryService: false,
},
{
name: "ydb.WithExecuteDataQueryOverQueryClient(true)",
executeDataQueryOverQueryService: true,
},
} {
t.Run(tt.name, func(t *testing.T) {
var (
scope = newScope(t)
driver = scope.Driver(ydb.WithExecuteDataQueryOverQueryClient(tt.executeDataQueryOverQueryService))
)
err := driver.Table().Do(scope.Ctx, func(ctx context.Context, s table.Session) error {
stmt, err := s.Prepare(ctx, `
DECLARE $val AS Uint64;
SELECT $val;
`)
if err != nil {
return fmt.Errorf("prepare failed: %w", err)
}
_, r, err := stmt.Execute(ctx, table.DefaultTxControl(),
table.NewQueryParameters(table.ValueParam("$val", types.Uint64Value(123))),
)
if err != nil {
return fmt.Errorf("prepared statement execute failed: %w", err)
}

if !r.NextResultSet(ctx) {
return fmt.Errorf("no result set: %w", r.Err())
}

if !r.NextRow() {
return fmt.Errorf("no row: %w", r.Err())
}

var v uint64
if err := r.Scan(&v); err != nil {
return fmt.Errorf("scan failed: %w", err)
}

if v != 123 {
return fmt.Errorf("unexpected value: %d", v)
}

return r.Err()
})
require.NoError(t, err)
})
}
}

0 comments on commit dca11b0

Please sign in to comment.