From ab5f0dfe5e614c9b06d1ce68c9bfd72d92cf54af Mon Sep 17 00:00:00 2001 From: Vitaly Isaev Date: Fri, 18 Oct 2024 09:02:10 +0000 Subject: [PATCH 1/5] YQ-3730: test SELECT with filters via Query Service --- tests/integration/query_execute_test.go | 61 +++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/tests/integration/query_execute_test.go b/tests/integration/query_execute_test.go index dd7583240..799fc970b 100644 --- a/tests/integration/query_execute_test.go +++ b/tests/integration/query_execute_test.go @@ -409,3 +409,64 @@ func TestIssue1456TooManyUnknownTransactions(t *testing.T) { wg.Wait() }) } + +// https://github.com/ydb-platform/ydb-go-sdk/issues/1506 +func TestIssue1506TypedNullPushdown(t *testing.T) { + if version.Lt(os.Getenv("YDB_VERSION"), "24.1") { + t.Skip("query service not allowed in YDB version '" + os.Getenv("YDB_VERSION") + "'") + } + + 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")), + ) + require.NoError(t, err) + + tableName := path.Join(db.Name(), t.Name(), "test") + + err = db.Query().Exec(ctx, "DROP TABLE IF EXISTS `"+tableName+"`;") + require.NoError(t, err) + + err = db.Query().Exec(ctx, `CREATE TABLE `+"`"+tableName+"`"+` ( + id Int32 NOT NULL, + col1 String NOT NULL, + col2 Int32, + PRIMARY KEY(id) + )`, + ) + require.NoError(t, err) + + err = db.Query().Exec(ctx, ` INSERT INTO `+"`"+tableName+"`"+` (id, col1, col2) VALUES + (1, "a", 10), + (2, "b", NULL); + `) + require.NoError(t, err) + + err = db.Query().Do(context.Background(), func(ctx context.Context, s query.Session) error { + // The resulting query should be like: + // + // query -> `SELECT * FROM table WHERE col2 = ?` + // args -> [NULL] + queryText := `DECLARE $p0 AS Optional; + SELECT * FROM ` + "`" + tableName + "`" + ` + WHERE col2 = $p0;` + + fmt.Println(queryText) + + paramsBuilder := ydb.ParamsBuilder() + paramsBuilder = paramsBuilder.Param("$p0").BeginOptional().Int32((*int32)(nil)).EndOptional() + + result, err := s.Query(ctx, fmt.Sprintf(queryText, tableName), query.WithParameters(paramsBuilder.Build())) + require.NoError(t, err, err.Error()) + require.NotNil(t, result) + + // TODO: check result emptyness; no lines should be returned. + + return nil + }) + + require.NoError(t, err, err.Error()) +} From aa0d87a017c56921da397b7f77901419f6f2246a Mon Sep 17 00:00:00 2001 From: Vitaly Isaev Date: Fri, 18 Oct 2024 14:36:28 +0300 Subject: [PATCH 2/5] YQ-3730: fix test --- tests/integration/query_execute_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/query_execute_test.go b/tests/integration/query_execute_test.go index 799fc970b..98d5d3786 100644 --- a/tests/integration/query_execute_test.go +++ b/tests/integration/query_execute_test.go @@ -459,8 +459,8 @@ func TestIssue1506TypedNullPushdown(t *testing.T) { paramsBuilder := ydb.ParamsBuilder() paramsBuilder = paramsBuilder.Param("$p0").BeginOptional().Int32((*int32)(nil)).EndOptional() - result, err := s.Query(ctx, fmt.Sprintf(queryText, tableName), query.WithParameters(paramsBuilder.Build())) - require.NoError(t, err, err.Error()) + result, err := s.Query(ctx, queryText, query.WithParameters(paramsBuilder.Build())) + require.NoError(t, err) require.NotNil(t, result) // TODO: check result emptyness; no lines should be returned. From 40f712d6542c9994b0a933a2cac19fef56bc5514 Mon Sep 17 00:00:00 2001 From: Timofey Koolin Date: Tue, 22 Oct 2024 11:08:49 +0300 Subject: [PATCH 3/5] fix optional param --- internal/params/optional.go | 2 +- internal/params/optional_test.go | 411 ++++----------------- tests/integration/query_execute_test.go | 61 --- tests/integration/query_regression_test.go | 38 ++ 4 files changed, 120 insertions(+), 392 deletions(-) diff --git a/internal/params/optional.go b/internal/params/optional.go index 94aa7188b..8be04b1a6 100644 --- a/internal/params/optional.go +++ b/internal/params/optional.go @@ -21,7 +21,7 @@ func (b *optionalBuilder) EndOptional() Builder { b.opt.parent.params = append(b.opt.parent.params, &Parameter{ parent: b.opt.parent, name: b.opt.name, - value: value.OptionalValue(b.opt.value), + value: b.opt.value, }) return b.opt.parent diff --git a/internal/params/optional_test.go b/internal/params/optional_test.go index f199742ce..cc9a50104 100644 --- a/internal/params/optional_test.go +++ b/internal/params/optional_test.go @@ -29,21 +29,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT64}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT64}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_Uint64Value{ - Uint64Value: 123, - }, - }, + Value: &Ydb.Value_Uint64Value{ + Uint64Value: 123, }, }, }, @@ -54,21 +44,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT64}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT64}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_Int64Value{ - Int64Value: 123, - }, - }, + Value: &Ydb.Value_Int64Value{ + Int64Value: 123, }, }, }, @@ -79,21 +59,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT32}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT32}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_Uint32Value{ - Uint32Value: 123, - }, - }, + Value: &Ydb.Value_Uint32Value{ + Uint32Value: 123, }, }, }, @@ -104,21 +74,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT32}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT32}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_Int32Value{ - Int32Value: 123, - }, - }, + Value: &Ydb.Value_Int32Value{ + Int32Value: 123, }, }, }, @@ -129,21 +89,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT16}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT16}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_Uint32Value{ - Uint32Value: 123, - }, - }, + Value: &Ydb.Value_Uint32Value{ + Uint32Value: 123, }, }, }, @@ -154,21 +104,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT16}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT16}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_Int32Value{ - Int32Value: 123, - }, - }, + Value: &Ydb.Value_Int32Value{ + Int32Value: 123, }, }, }, @@ -179,21 +119,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT8}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT8}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_Uint32Value{ - Uint32Value: 123, - }, - }, + Value: &Ydb.Value_Uint32Value{ + Uint32Value: 123, }, }, }, @@ -204,21 +134,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT8}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT8}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_Int32Value{ - Int32Value: 123, - }, - }, + Value: &Ydb.Value_Int32Value{ + Int32Value: 123, }, }, }, @@ -229,21 +149,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_BOOL}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_BOOL}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_BoolValue{ - BoolValue: true, - }, - }, + Value: &Ydb.Value_BoolValue{ + BoolValue: true, }, }, }, @@ -254,21 +164,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UTF8}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UTF8}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_TextValue{ - TextValue: "test", - }, - }, + Value: &Ydb.Value_TextValue{ + TextValue: "test", }, }, }, @@ -279,21 +179,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_STRING}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_STRING}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_BytesValue{ - BytesValue: []byte("test"), - }, - }, + Value: &Ydb.Value_BytesValue{ + BytesValue: []byte("test"), }, }, }, @@ -304,21 +194,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_FLOAT}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_FLOAT}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_FloatValue{ - FloatValue: float32(123), - }, - }, + Value: &Ydb.Value_FloatValue{ + FloatValue: float32(123), }, }, }, @@ -329,21 +209,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DOUBLE}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DOUBLE}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_DoubleValue{ - DoubleValue: float64(123), - }, - }, + Value: &Ydb.Value_DoubleValue{ + DoubleValue: float64(123), }, }, }, @@ -354,21 +224,12 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INTERVAL}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INTERVAL}, }, + Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_Int64Value{ - Int64Value: 1000000, - }, - }, + Value: &Ydb.Value_Int64Value{ + Int64Value: 1000000, }, }, }, @@ -379,21 +240,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DATETIME}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DATETIME}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_Uint32Value{ - Uint32Value: 123456789, - }, - }, + Value: &Ydb.Value_Uint32Value{ + Uint32Value: 123456789, }, }, }, @@ -404,21 +255,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DATE}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DATE}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_Uint32Value{ - Uint32Value: 1428, - }, - }, + Value: &Ydb.Value_Uint32Value{ + Uint32Value: 1428, }, }, }, @@ -429,21 +270,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TIMESTAMP}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TIMESTAMP}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_Uint64Value{ - Uint64Value: 123456789000000, - }, - }, + Value: &Ydb.Value_Uint64Value{ + Uint64Value: 123456789000000, }, }, }, @@ -454,27 +285,17 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_DecimalType{ - DecimalType: &Ydb.DecimalType{ - Precision: 22, - Scale: 9, - }, - }, - }, + Type: &Ydb.Type_DecimalType{ + DecimalType: &Ydb.DecimalType{ + Precision: 22, + Scale: 9, }, }, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - High_128: 72623859790382856, - Value: &Ydb.Value_Low_128{ - Low_128: 648519454493508870, - }, - }, + High_128: 72623859790382856, + Value: &Ydb.Value_Low_128{ + Low_128: 648519454493508870, }, }, }, @@ -485,21 +306,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_JSON}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_JSON}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_TextValue{ - TextValue: `{"a": 1,"b": "B"}`, - }, - }, + Value: &Ydb.Value_TextValue{ + TextValue: `{"a": 1,"b": "B"}`, }, }, }, @@ -510,21 +321,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_JSON_DOCUMENT}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_JSON_DOCUMENT}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_TextValue{ - TextValue: `{"a": 1,"b": "B"}`, - }, - }, + Value: &Ydb.Value_TextValue{ + TextValue: `{"a": 1,"b": "B"}`, }, }, }, @@ -535,21 +336,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_YSON}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_YSON}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_BytesValue{ - BytesValue: []byte(`{"a": 1,"b": "B"}`), - }, - }, + Value: &Ydb.Value_BytesValue{ + BytesValue: []byte(`{"a": 1,"b": "B"}`), }, }, }, @@ -560,23 +351,13 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_Low_128{ - Low_128: 651345242494996240, - }, - High_128: 72623859790382856, - }, + Value: &Ydb.Value_Low_128{ + Low_128: 651345242494996240, }, + High_128: 72623859790382856, }, }, }, @@ -586,21 +367,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_DATETIME}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_DATETIME}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_TextValue{ - TextValue: "1973-11-29T21:33:09Z", - }, - }, + Value: &Ydb.Value_TextValue{ + TextValue: "1973-11-29T21:33:09Z", }, }, }, @@ -611,21 +382,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_DATE}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_DATE}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_TextValue{ - TextValue: "1973-11-29", - }, - }, + Value: &Ydb.Value_TextValue{ + TextValue: "1973-11-29", }, }, }, @@ -636,21 +397,11 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_TIMESTAMP}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_TIMESTAMP}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_TextValue{ - TextValue: "1973-11-29T21:33:09.000000Z", - }, - }, + Value: &Ydb.Value_TextValue{ + TextValue: "1973-11-29T21:33:09.000000Z", }, }, }, diff --git a/tests/integration/query_execute_test.go b/tests/integration/query_execute_test.go index 98d5d3786..dd7583240 100644 --- a/tests/integration/query_execute_test.go +++ b/tests/integration/query_execute_test.go @@ -409,64 +409,3 @@ func TestIssue1456TooManyUnknownTransactions(t *testing.T) { wg.Wait() }) } - -// https://github.com/ydb-platform/ydb-go-sdk/issues/1506 -func TestIssue1506TypedNullPushdown(t *testing.T) { - if version.Lt(os.Getenv("YDB_VERSION"), "24.1") { - t.Skip("query service not allowed in YDB version '" + os.Getenv("YDB_VERSION") + "'") - } - - 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")), - ) - require.NoError(t, err) - - tableName := path.Join(db.Name(), t.Name(), "test") - - err = db.Query().Exec(ctx, "DROP TABLE IF EXISTS `"+tableName+"`;") - require.NoError(t, err) - - err = db.Query().Exec(ctx, `CREATE TABLE `+"`"+tableName+"`"+` ( - id Int32 NOT NULL, - col1 String NOT NULL, - col2 Int32, - PRIMARY KEY(id) - )`, - ) - require.NoError(t, err) - - err = db.Query().Exec(ctx, ` INSERT INTO `+"`"+tableName+"`"+` (id, col1, col2) VALUES - (1, "a", 10), - (2, "b", NULL); - `) - require.NoError(t, err) - - err = db.Query().Do(context.Background(), func(ctx context.Context, s query.Session) error { - // The resulting query should be like: - // - // query -> `SELECT * FROM table WHERE col2 = ?` - // args -> [NULL] - queryText := `DECLARE $p0 AS Optional; - SELECT * FROM ` + "`" + tableName + "`" + ` - WHERE col2 = $p0;` - - fmt.Println(queryText) - - paramsBuilder := ydb.ParamsBuilder() - paramsBuilder = paramsBuilder.Param("$p0").BeginOptional().Int32((*int32)(nil)).EndOptional() - - result, err := s.Query(ctx, queryText, query.WithParameters(paramsBuilder.Build())) - require.NoError(t, err) - require.NotNil(t, result) - - // TODO: check result emptyness; no lines should be returned. - - return nil - }) - - require.NoError(t, err, err.Error()) -} diff --git a/tests/integration/query_regression_test.go b/tests/integration/query_regression_test.go index 84d228f3c..dc05a7a16 100644 --- a/tests/integration/query_regression_test.go +++ b/tests/integration/query_regression_test.go @@ -4,6 +4,7 @@ package integration import ( + "os" "testing" "github.com/google/uuid" @@ -11,6 +12,7 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3" "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/tx" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/version" "github.com/ydb-platform/ydb-go-sdk/v3/query" ) @@ -133,3 +135,39 @@ SELECT $val`, require.Equal(t, id, resUUID) }) } + +// https://github.com/ydb-platform/ydb-go-sdk/issues/1506 +func TestIssue1506TypedNullPushdown(t *testing.T) { + if version.Lt(os.Getenv("YDB_VERSION"), "24.1") { + t.Skip("query service not allowed in YDB version '" + os.Getenv("YDB_VERSION") + "'") + } + + scope := newScope(t) + ctx := scope.Ctx + db := scope.Driver() + + val := int64(123) + row, err := db.Query().QueryRow(ctx, ` +DECLARE $arg1 AS Int64?; +DECLARE $arg2 AS Int64?; + +SELECT CAST($arg1 AS Utf8) AS v1, CAST($arg2 AS Utf8) AS v2 +`, query.WithParameters( + ydb.ParamsBuilder(). + Param("$arg1").BeginOptional().Int64(nil).EndOptional(). + Param("$arg2").BeginOptional().Int64(&val).EndOptional(). + Build(), + ), + ) + require.NoError(t, err) + + var res struct { + V1 *string `sql:"v1"` + V2 *string `sql:"v2"` + } + err = row.ScanStruct(&res) + require.NoError(t, err) + + require.Nil(t, res.V1) + require.Equal(t, "123", *res.V2) +} From bf274a78d597b0dcf4f70a49406fa432ad99a02b Mon Sep 17 00:00:00 2001 From: Timofey Koolin Date: Tue, 22 Oct 2024 11:15:35 +0300 Subject: [PATCH 4/5] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ba8f817d..9d1e82f78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +* Fixed send optional arguments to the server with `ydb.ParamsBuilder` * Added `db.Topic().DescribeTopicConsumer()` method for displaying consumer information * Marked as deprecated options `ydb.WithDatabase(database)` and `ydb.WithEndpoint(endpoint)` From 85ba858772803636f89f2bdb1fecc87b9a2f6a76 Mon Sep 17 00:00:00 2001 From: Timofey Koolin Date: Wed, 23 Oct 2024 15:30:10 +0300 Subject: [PATCH 5/5] fix uuid optional wrapping --- internal/params/optional_test.go | 36 +++++++------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/internal/params/optional_test.go b/internal/params/optional_test.go index 0e064dcfc..c677d27e3 100644 --- a/internal/params/optional_test.go +++ b/internal/params/optional_test.go @@ -368,23 +368,13 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_Low_128{ - Low_128: 506660481424032516, - }, - High_128: 1157159078456920585, - }, + Value: &Ydb.Value_Low_128{ + Low_128: 506660481424032516, }, + High_128: 1157159078456920585, }, }, }, @@ -394,23 +384,13 @@ func TestOptional(t *testing.T) { expected: expected{ Type: &Ydb.Type{ - Type: &Ydb.Type_OptionalType{ - OptionalType: &Ydb.OptionalType{ - Item: &Ydb.Type{ - Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID}, - }, - }, - }, + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID}, }, Value: &Ydb.Value{ - Value: &Ydb.Value_NestedValue{ - NestedValue: &Ydb.Value{ - Value: &Ydb.Value_Low_128{ - Low_128: 651345242494996240, - }, - High_128: 72623859790382856, - }, + Value: &Ydb.Value_Low_128{ + Low_128: 651345242494996240, }, + High_128: 72623859790382856, }, }, },