3
3
4
4
#include < ydb/public/sdk/cpp/client/ydb_driver/driver.h>
5
5
#include < ydb/public/sdk/cpp/client/ydb_table/table.h>
6
+ #include < ydb/public/sdk/cpp/client/ydb_proto/accessor.h>
6
7
#include < ydb/public/sdk/cpp/client/draft/ydb_scripting.h>
7
- #include < ydb/public/lib/yson_value/ydb_yson_value.h>
8
- #include < library/cpp/yson/writer.h>
9
8
10
9
#include < library/cpp/threading/local_executor/local_executor.h>
11
10
@@ -14,18 +13,7 @@ using namespace NYdb::NTable;
14
13
15
14
namespace {
16
15
17
- TString ReformatYson (const TString& yson) {
18
- TStringStream ysonInput (yson);
19
- TStringStream output;
20
- NYson::ReformatYsonStream (&ysonInput, &output, NYson::EYsonFormat::Text);
21
- return output.Str ();
22
- }
23
-
24
- void CompareYson (const TString& expected, const TString& actual) {
25
- UNIT_ASSERT_NO_DIFF (ReformatYson (expected), ReformatYson (actual));
26
- }
27
-
28
- ui64 DoRead (TSession& s, const TString& table, ui64 expectedRows, const TString& expectedContent) {
16
+ std::pair<ui64, Ydb::ResultSet> DoRead (TSession& s, const TString& table) {
29
17
auto res = s.ExecuteDataQuery (
30
18
Sprintf (" SELECT * FROM `/local/%s`; SELECT COUNT(*) AS __count FROM `/local/%s`;" ,
31
19
table.data (), table.data ()), TTxControl::BeginTx ().CommitTx ()).GetValueSync ();
@@ -34,23 +22,17 @@ ui64 DoRead(TSession& s, const TString& table, ui64 expectedRows, const TString&
34
22
UNIT_ASSERT (rs.TryNextRow ());
35
23
auto count = rs.ColumnParser (" __count" ).GetUint64 ();
36
24
37
- if (count == expectedRows) {
38
- auto yson = NYdb::FormatResultSetYson (res.GetResultSet (0 ));
39
-
40
- CompareYson (expectedContent, yson);
41
- }
42
-
43
- return count;
25
+ const auto proto = NYdb::TProtoAccessor::GetProto (res.GetResultSet (0 ));
26
+ return {count, proto};
44
27
}
45
28
46
29
} // namespace
47
30
48
31
Y_UNIT_TEST_SUITE (Replication)
49
32
{
50
- Y_UNIT_TEST (UuidValue )
33
+ Y_UNIT_TEST (Types )
51
34
{
52
35
TString connectionString = GetEnv (" YDB_ENDPOINT" ) + " /?database=" + GetEnv (" YDB_DATABASE" );
53
- Cerr << connectionString << Endl;
54
36
auto config = TDriverConfig (connectionString);
55
37
auto driver = TDriver (config);
56
38
auto tableClient = TTableClient (driver);
@@ -60,8 +42,9 @@ Y_UNIT_TEST_SUITE(Replication)
60
42
auto res = session.ExecuteSchemeQuery (R"(
61
43
CREATE TABLE `/local/ProducerUuidValue` (
62
44
Key Uint32,
63
- Value1 Uuid,
64
- Value2 Uuid NOT NULL,
45
+ v01 Uuid,
46
+ v02 Uuid NOT NULL,
47
+ v03 Double,
65
48
PRIMARY KEY (Key)
66
49
);
67
50
)" ).GetValueSync ();
@@ -74,11 +57,12 @@ Y_UNIT_TEST_SUITE(Replication)
74
57
auto s = sessionResult.GetSession ();
75
58
76
59
{
77
- const TString query = " UPSERT INTO ProducerUuidValue (Key, Value1, Value2 ) VALUES"
60
+ const TString query = " UPSERT INTO ProducerUuidValue (Key,v01,v02,v03 ) VALUES"
78
61
" (1, "
79
62
" CAST(\" 5b99a330-04ef-4f1a-9b64-ba6d5f44ea01\" as Uuid), "
80
- " UNWRAP(CAST(\" 5b99a330-04ef-4f1a-9b64-ba6d5f44ea02\" as Uuid)"
81
- " ));" ;
63
+ " UNWRAP(CAST(\" 5b99a330-04ef-4f1a-9b64-ba6d5f44ea02\" as Uuid)), "
64
+ " CAST(\" 311111111113.222222223\" as Double) "
65
+ " );" ;
82
66
auto res = s.ExecuteDataQuery (query, TTxControl::BeginTx ().CommitTx ()).GetValueSync ();
83
67
UNIT_ASSERT_C (res.IsSuccess (), res.GetIssues ().ToString ());
84
68
}
@@ -104,9 +88,22 @@ Y_UNIT_TEST_SUITE(Replication)
104
88
UNIT_ASSERT_C (sessionResult.IsSuccess (), sessionResult.GetIssues ().ToString ());
105
89
106
90
auto s = sessionResult.GetSession ();
107
- const TString expected = R"( [[[1u];["5b99a330-04ef-4f1a-9b64-ba6d5f44ea01"];"5b99a330-04ef-4f1a-9b64-ba6d5f44ea02"]])" ;
91
+ TUuidValue expectedV1 (" 5b99a330-04ef-4f1a-9b64-ba6d5f44ea01" );
92
+ TUuidValue expectedV2 (" 5b99a330-04ef-4f1a-9b64-ba6d5f44ea02" );
93
+ double expectedV3 = 311111111113.222222223 ;
108
94
ui32 attempt = 10 ;
109
- while (1 != DoRead (s, " ConsumerUuidValue" , 1 , expected) && --attempt) {
95
+ while (--attempt) {
96
+ auto res = DoRead (s, " ConsumerUuidValue" );
97
+ if (res.first == 1 ) {
98
+ const Ydb::ResultSet& proto = res.second ;
99
+ UNIT_ASSERT_VALUES_EQUAL (proto.rows (0 ).items (0 ).uint32_value (), 1 );
100
+ UNIT_ASSERT_VALUES_EQUAL (proto.rows (0 ).items (1 ).low_128 (), expectedV1.Buf_ .Halfs [0 ]);
101
+ UNIT_ASSERT_VALUES_EQUAL (proto.rows (0 ).items (1 ).high_128 (), expectedV1.Buf_ .Halfs [1 ]);
102
+ UNIT_ASSERT_VALUES_EQUAL (proto.rows (0 ).items (2 ).low_128 (), expectedV2.Buf_ .Halfs [0 ]);
103
+ UNIT_ASSERT_VALUES_EQUAL (proto.rows (0 ).items (2 ).high_128 (), expectedV2.Buf_ .Halfs [1 ]);
104
+ UNIT_ASSERT_DOUBLES_EQUAL (proto.rows (0 ).items (3 ).double_value (), expectedV3, 0.0001 );
105
+ break ;
106
+ }
110
107
Sleep (TDuration::Seconds (1 ));
111
108
}
112
109
0 commit comments