Skip to content

Commit cecee46

Browse files
authored
Supported ydb repo build (#299)
1 parent e4f06d5 commit cecee46

File tree

195 files changed

+9064
-3024
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

195 files changed

+9064
-3024
lines changed

cmake/common.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ function(_ydb_sdk_add_library Tgt)
198198
$<BUILD_INTERFACE:${YDB_SDK_BINARY_DIR}>
199199
$<BUILD_INTERFACE:${YDB_SDK_SOURCE_DIR}/include>
200200
)
201+
target_compile_definitions(${Tgt} ${includeMode}
202+
YDB_SDK_USE_STD_STRING
203+
)
201204
endfunction()
202205

203206
function(_ydb_sdk_validate_public_headers)

cmake/protos_public_headers.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ src/api/protos/ydb_export.pb.h
2020
src/api/protos/ydb_coordination.pb.h
2121
src/api/protos/ydb_status_codes.pb.h
2222
src/api/protos/draft/ydb_replication.pb.h
23-
src/library/yql/public/issue/protos/issue_severity.pb.h
23+
src/library/operation_id/protos/operation_id.pb.h
24+
src/library/yql_common/issue/protos/issue_severity.pb.h

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ add_subdirectory(secondary_index)
55
add_subdirectory(secondary_index_builtin)
66
add_subdirectory(topic_reader)
77
add_subdirectory(ttl)
8+
add_subdirectory(vector_index)

examples/basic_example/basic_example.cpp

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using namespace NYdb;
99
using namespace NYdb::NTable;
1010

11+
namespace {
12+
1113
class TYdbErrorException : public yexception {
1214
public:
1315
TYdbErrorException(const TStatus& status)
@@ -16,18 +18,34 @@ class TYdbErrorException : public yexception {
1618
TStatus Status;
1719
};
1820

19-
static void ThrowOnError(const TStatus& status) {
21+
void ThrowOnError(const TStatus& status) {
2022
if (!status.IsSuccess()) {
2123
throw TYdbErrorException(status) << status;
2224
}
2325
}
2426

25-
static void PrintStatus(const TStatus& status) {
27+
void PrintStatus(const TStatus& status) {
2628
std::cerr << "Status: " << ToString(status.GetStatus()) << std::endl;
2729
std::cerr << status.GetIssues().ToString();
2830
}
2931

30-
static std::string JoinPath(const std::string& basePath, const std::string& path) {
32+
template <class T>
33+
std::string OptionalToString(const std::optional<T>& opt) {
34+
if (opt.has_value()) {
35+
return std::to_string(opt.value());
36+
}
37+
return "(NULL)";
38+
}
39+
40+
template <>
41+
std::string OptionalToString<std::string>(const std::optional<std::string>& opt) {
42+
if (opt.has_value()) {
43+
return opt.value();
44+
}
45+
return "(NULL)";
46+
}
47+
48+
std::string JoinPath(const std::string& basePath, const std::string& path) {
3149
if (basePath.empty()) {
3250
return path;
3351
}
@@ -41,7 +59,7 @@ static std::string JoinPath(const std::string& basePath, const std::string& path
4159
///////////////////////////////////////////////////////////////////////////////
4260

4361
//! Creates sample tables with CrateTable API.
44-
static void CreateTables(TTableClient client, const std::string& path) {
62+
void CreateTables(TTableClient client, const std::string& path) {
4563
ThrowOnError(client.RetryOperationSync([path](TSession session) {
4664
auto seriesDesc = TTableBuilder()
4765
.AddNullableColumn("series_id", EPrimitiveType::Uint64)
@@ -83,7 +101,7 @@ static void CreateTables(TTableClient client, const std::string& path) {
83101
}
84102

85103
//! Describe existing table.
86-
static void DescribeTable(TTableClient client, const std::string& path, const std::string& name) {
104+
void DescribeTable(TTableClient client, const std::string& path, const std::string& name) {
87105
std::optional<TTableDescription> desc;
88106

89107
ThrowOnError(client.RetryOperationSync([path, name, &desc](TSession session) {
@@ -105,7 +123,7 @@ static void DescribeTable(TTableClient client, const std::string& path, const st
105123
///////////////////////////////////////////////////////////////////////////////
106124

107125
//! Fills sample tables with data in single parameterized data query.
108-
static TStatus FillTableDataTransaction(TSession session, const std::string& path) {
126+
TStatus FillTableDataTransaction(TSession session, const std::string& path) {
109127
auto query = std::format(R"(
110128
PRAGMA TablePathPrefix("{}");
111129
@@ -165,7 +183,7 @@ static TStatus FillTableDataTransaction(TSession session, const std::string& pat
165183
}
166184

167185
//! Shows basic usage of YDB data queries and transactions.
168-
static TStatus SelectSimpleTransaction(TSession session, const std::string& path,
186+
TStatus SelectSimpleTransaction(TSession session, const std::string& path,
169187
std::optional<TResultSet>& resultSet)
170188
{
171189
auto query = std::format(R"(
@@ -194,7 +212,7 @@ static TStatus SelectSimpleTransaction(TSession session, const std::string& path
194212
}
195213

196214
//! Shows basic usage of mutating operations.
197-
static TStatus UpsertSimpleTransaction(TSession session, const std::string& path) {
215+
TStatus UpsertSimpleTransaction(TSession session, const std::string& path) {
198216
auto query = std::format(R"(
199217
--!syntax_v1
200218
PRAGMA TablePathPrefix("{}");
@@ -208,7 +226,7 @@ static TStatus UpsertSimpleTransaction(TSession session, const std::string& path
208226
}
209227

210228
//! Shows usage of parameters in data queries.
211-
static TStatus SelectWithParamsTransaction(TSession session, const std::string& path,
229+
TStatus SelectWithParamsTransaction(TSession session, const std::string& path,
212230
uint64_t seriesId, uint64_t seasonId, std::optional<TResultSet>& resultSet)
213231
{
214232
auto query = std::format(R"(
@@ -248,7 +266,7 @@ static TStatus SelectWithParamsTransaction(TSession session, const std::string&
248266
}
249267

250268
//! Shows usage of prepared queries.
251-
static TStatus PreparedSelectTransaction(TSession session, const std::string& path,
269+
TStatus PreparedSelectTransaction(TSession session, const std::string& path,
252270
uint64_t seriesId, uint64_t seasonId, uint64_t episodeId, std::optional<TResultSet>& resultSet)
253271
{
254272
// Once prepared, query data is stored in the session and identified by QueryId.
@@ -301,7 +319,7 @@ static TStatus PreparedSelectTransaction(TSession session, const std::string& pa
301319
}
302320

303321
//! Shows usage of transactions consisting of multiple data queries with client logic between them.
304-
static TStatus MultiStepTransaction(TSession session, const std::string& path, uint64_t seriesId, uint64_t seasonId,
322+
TStatus MultiStepTransaction(TSession session, const std::string& path, uint64_t seriesId, uint64_t seasonId,
305323
std::optional<TResultSet>& resultSet)
306324
{
307325
auto query1 = std::format(R"(
@@ -394,7 +412,7 @@ static TStatus MultiStepTransaction(TSession session, const std::string& path, u
394412
// Show usage of explicit Begin/Commit transaction control calls.
395413
// In most cases it's better to use transaction control settings in ExecuteDataQuery calls instead
396414
// to avoid additional hops to YDB cluster and allow more efficient execution of queries.
397-
static TStatus ExplicitTclTransaction(TSession session, const std::string& path, const TInstant& airDate) {
415+
TStatus ExplicitTclTransaction(TSession session, const std::string& path, const TInstant& airDate) {
398416
auto beginResult = session.BeginTransaction(TTxSettings::SerializableRW()).GetValueSync();
399417
if (!beginResult.IsSuccess()) {
400418
return beginResult;
@@ -432,6 +450,8 @@ static TStatus ExplicitTclTransaction(TSession session, const std::string& path,
432450
return tx.Commit().GetValueSync();
433451
}
434452

453+
}
454+
435455
///////////////////////////////////////////////////////////////////////////////
436456

437457
void SelectSimple(TTableClient client, const std::string& path) {
@@ -443,9 +463,9 @@ void SelectSimple(TTableClient client, const std::string& path) {
443463
TResultSetParser parser(*resultSet);
444464
if (parser.TryNextRow()) {
445465
std::cout << "> SelectSimple:" << std::endl << "Series"
446-
<< ", Id: " << ToString(parser.ColumnParser("series_id").GetOptionalUint64())
447-
<< ", Title: " << ToString(parser.ColumnParser("title").GetOptionalUtf8())
448-
<< ", Release date: " << ToString(parser.ColumnParser("release_date").GetOptionalString())
466+
<< ", Id: " << OptionalToString(parser.ColumnParser("series_id").GetOptionalUint64())
467+
<< ", Title: " << OptionalToString(parser.ColumnParser("title").GetOptionalUtf8())
468+
<< ", Release date: " << OptionalToString(parser.ColumnParser("release_date").GetOptionalString())
449469
<< std::endl;
450470
}
451471
}
@@ -465,8 +485,8 @@ void SelectWithParams(TTableClient client, const std::string& path) {
465485
TResultSetParser parser(*resultSet);
466486
if (parser.TryNextRow()) {
467487
std::cout << "> SelectWithParams:" << std::endl << "Season"
468-
<< ", Title: " << ToString(parser.ColumnParser("season_title").GetOptionalUtf8())
469-
<< ", Series title: " << ToString(parser.ColumnParser("series_title").GetOptionalUtf8())
488+
<< ", Title: " << OptionalToString(parser.ColumnParser("season_title").GetOptionalUtf8())
489+
<< ", Series title: " << OptionalToString(parser.ColumnParser("series_title").GetOptionalUtf8())
470490
<< std::endl;
471491
}
472492
}
@@ -481,8 +501,8 @@ void PreparedSelect(TTableClient client, const std::string& path, uint32_t serie
481501
if (parser.TryNextRow()) {
482502
auto airDate = TInstant::Days(*parser.ColumnParser("air_date").GetOptionalUint64());
483503

484-
std::cout << "> PreparedSelect:" << std::endl << "Episode " << ToString(parser.ColumnParser("episode_id").GetOptionalUint64())
485-
<< ", Title: " << ToString(parser.ColumnParser("title").GetOptionalUtf8())
504+
std::cout << "> PreparedSelect:" << std::endl << "Episode " << OptionalToString(parser.ColumnParser("episode_id").GetOptionalUint64())
505+
<< ", Title: " << OptionalToString(parser.ColumnParser("title").GetOptionalUtf8())
486506
<< ", Air date: " << airDate.FormatLocalTime("%a %b %d, %Y")
487507
<< std::endl;
488508
}
@@ -499,9 +519,9 @@ void MultiStep(TTableClient client, const std::string& path) {
499519
while (parser.TryNextRow()) {
500520
auto airDate = TInstant::Days(*parser.ColumnParser("air_date").GetOptionalUint64());
501521

502-
std::cout << "Episode " << ToString(parser.ColumnParser("episode_id").GetOptionalUint64())
503-
<< ", Season: " << ToString(parser.ColumnParser("season_id").GetOptionalUint64())
504-
<< ", Title: " << ToString(parser.ColumnParser("title").GetOptionalUtf8())
522+
std::cout << "Episode " << OptionalToString(parser.ColumnParser("episode_id").GetOptionalUint64())
523+
<< ", Season: " << OptionalToString(parser.ColumnParser("season_id").GetOptionalUint64())
524+
<< ", Title: " << OptionalToString(parser.ColumnParser("title").GetOptionalUtf8())
505525
<< ", Air date: " << airDate.FormatLocalTime("%a %b %d, %Y")
506526
<< std::endl;
507527
}
@@ -561,10 +581,10 @@ void ScanQuerySelect(TTableClient client, const std::string& path) {
561581
TResultSetParser parser(rs);
562582
while (parser.TryNextRow()) {
563583
std::cout << "Season"
564-
<< ", SeriesId: " << ToString(parser.ColumnParser("series_id").GetOptionalUint64())
565-
<< ", SeasonId: " << ToString(parser.ColumnParser("season_id").GetOptionalUint64())
566-
<< ", Title: " << ToString(parser.ColumnParser("title").GetOptionalUtf8())
567-
<< ", Air date: " << ToString(parser.ColumnParser("first_aired").GetOptionalString())
584+
<< ", SeriesId: " << OptionalToString(parser.ColumnParser("series_id").GetOptionalUint64())
585+
<< ", SeasonId: " << OptionalToString(parser.ColumnParser("season_id").GetOptionalUint64())
586+
<< ", Title: " << OptionalToString(parser.ColumnParser("title").GetOptionalUtf8())
587+
<< ", Air date: " << OptionalToString(parser.ColumnParser("first_aired").GetOptionalString())
568588
<< std::endl;
569589
}
570590
}

examples/bulk_upsert_simple/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ void GetLogBatch(uint64_t logOffset, std::vector<TLogMessage>& logBatch) {
1818
logBatch.clear();
1919
for (size_t i = 0; i < BATCH_SIZE; ++i) {
2020
TLogMessage message;
21-
message.App = "App_" + ToString(logOffset % 10);
22-
message.Host = "192.168.0." + ToString(logOffset % 11);
21+
message.App = "App_" + std::to_string(logOffset % 10);
22+
message.Host = "192.168.0." + std::to_string(logOffset % 11);
2323
message.Timestamp = TInstant::Now() + TDuration::MilliSeconds(i % 1000);
2424
message.HttpCode = 200;
2525
message.Message = i % 2 ? "GET / HTTP/1.1" : "GET /images/logo.png HTTP/1.1";

examples/pagination/pagination.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <util/string/cast.h>
44

55
#include <filesystem>
6+
#include <format>
67

78
using namespace NYdb;
89
using namespace NYdb::NTable;
@@ -152,7 +153,7 @@ bool SelectPaging(TTableClient client, const std::string& path, uint64_t pageLim
152153
do {
153154
lastCity = parser.ColumnParser("city").GetOptionalUtf8().value();
154155
lastNumber = parser.ColumnParser("number").GetOptionalUint32().value();
155-
std::cout << lastCity << ", Школа №" << lastNumber << ", Адрес: " << ToString(parser.ColumnParser("address").GetOptionalUtf8()) << std::endl;
156+
std::cout << lastCity << ", Школа №" << lastNumber << ", Адрес: " << parser.ColumnParser("address").GetOptionalUtf8().value_or("(NULL)") << std::endl;
156157
} while (parser.TryNextRow());
157158
return true;
158159
}

examples/secondary_index/secondary_index.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include <library/cpp/getopt/last_getopt.h>
77

8+
#include <format>
9+
810
////////////////////////////////////////////////////////////////////////////////
911

1012
#define TABLE_SERIES "series"

examples/secondary_index_builtin/secondary_index.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <library/cpp/getopt/last_getopt.h>
1010

11+
#include <format>
12+
1113
#define TABLE_USERS "users"
1214
#define TABLE_SERIES "series"
1315

examples/ttl/ttl.cpp

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
11
#include "ttl.h"
22
#include "util.h"
33

4+
#include <format>
5+
46
using namespace NExample;
57
using namespace NYdb;
68
using namespace NYdb::NTable;
79

810
constexpr uint32_t DOC_TABLE_PARTITION_COUNT = 4;
911
constexpr uint32_t EXPIRATION_QUEUE_COUNT = 4;
1012

13+
namespace {
14+
15+
template <class T>
16+
std::string OptionalToString(const std::optional<T>& opt) {
17+
if (opt.has_value()) {
18+
return std::to_string(opt.value());
19+
}
20+
return "(NULL)";
21+
}
22+
23+
template <>
24+
std::string OptionalToString<std::string>(const std::optional<std::string>& opt) {
25+
if (opt.has_value()) {
26+
return opt.value();
27+
}
28+
return "(NULL)";
29+
}
30+
1131
//! Creates Documents table and multiple ExpirationQueue tables
12-
static void CreateTables(TTableClient client, const std::string& path) {
32+
void CreateTables(TTableClient client, const std::string& path) {
1333
// Documents table stores the contents of web pages.
1434
// The table is partitioned by hash(Url) in order to evenly distribute the load.
1535
ThrowOnError(client.RetryOperationSync([path](TSession session) {
@@ -48,7 +68,7 @@ static void CreateTables(TTableClient client, const std::string& path) {
4868
///////////////////////////////////////////////////////////////////////////////
4969

5070
//! Insert or replaces a document.
51-
static TStatus AddDocumentTransaction(TSession session, const std::string& path,
71+
TStatus AddDocumentTransaction(TSession session, const std::string& path,
5272
const std::string& url, const std::string& html, uint64_t timestamp)
5373
{
5474
// Add an entry to a random expiration queue in order to evenly distribute the load
@@ -88,7 +108,7 @@ static TStatus AddDocumentTransaction(TSession session, const std::string& path,
88108
}
89109

90110
//! Reads document contents.
91-
static TStatus ReadDocumentTransaction(TSession session, const std::string& path,
111+
TStatus ReadDocumentTransaction(TSession session, const std::string& path,
92112
const std::string& url, std::optional<TResultSet>& resultSet)
93113
{
94114
auto query = std::format(R"(
@@ -121,7 +141,7 @@ static TStatus ReadDocumentTransaction(TSession session, const std::string& path
121141
}
122142

123143
//! Reads a batch of entries from expiration queue
124-
static TStatus ReadExpiredBatchTransaction(TSession session, const std::string& path, const uint32_t queue,
144+
TStatus ReadExpiredBatchTransaction(TSession session, const std::string& path, const uint32_t queue,
125145
const uint64_t timestamp, const uint64_t prevTimestamp, const uint64_t prevDocId, std::optional<TResultSet>& resultSet)
126146
{
127147
auto query = std::format(R"(
@@ -177,7 +197,7 @@ static TStatus ReadExpiredBatchTransaction(TSession session, const std::string&
177197
}
178198

179199
//! Deletes an expired document
180-
static TStatus DeleteDocumentWithTimestamp(TSession session, const std::string& path, const uint32_t queue,
200+
TStatus DeleteDocumentWithTimestamp(TSession session, const std::string& path, const uint32_t queue,
181201
const uint64_t docId, const uint64_t timestamp)
182202
{
183203
auto query = std::format(R"(
@@ -206,6 +226,9 @@ static TStatus DeleteDocumentWithTimestamp(TSession session, const std::string&
206226

207227
return result;
208228
}
229+
230+
}
231+
209232
///////////////////////////////////////////////////////////////////////////////
210233

211234
void AddDocument(TTableClient client, const std::string& path, const std::string& url,
@@ -230,10 +253,10 @@ void ReadDocument(TTableClient client, const std::string& path, const std::strin
230253

231254
TResultSetParser parser(*resultSet);
232255
if (parser.TryNextRow()) {
233-
std::cout << " DocId: " << ToString(parser.ColumnParser("doc_id").GetOptionalUint64()) << std::endl
234-
<< " Url: " << ToString(parser.ColumnParser("url").GetOptionalUtf8()) << std::endl
235-
<< " Timestamp: " << ToString(parser.ColumnParser("timestamp").GetOptionalUint64()) << std::endl
236-
<< " Html: " << ToString(parser.ColumnParser("html").GetOptionalUtf8()) << std::endl;
256+
std::cout << " DocId: " << OptionalToString(parser.ColumnParser("doc_id").GetOptionalUint64()) << std::endl
257+
<< " Url: " << OptionalToString(parser.ColumnParser("url").GetOptionalUtf8()) << std::endl
258+
<< " Timestamp: " << OptionalToString(parser.ColumnParser("timestamp").GetOptionalUint64()) << std::endl
259+
<< " Html: " << OptionalToString(parser.ColumnParser("html").GetOptionalUtf8()) << std::endl;
237260
} else {
238261
std::cout << " Not found" << std::endl;
239262
}

examples/vector_index/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ add_executable(vector_index)
22

33
target_link_libraries(vector_index PUBLIC
44
yutil
5-
library-getopt
5+
getopt
66
YDB-CPP-SDK::Table
77
)
88

@@ -15,7 +15,7 @@ vcs_info(vector_index)
1515

1616
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64")
1717
target_link_libraries(vector_index PUBLIC
18-
library-cpuid_check
18+
cpuid_check
1919
)
2020
endif()
2121

examples/vector_index/vector_index.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <ydb-cpp-sdk/client/driver/driver.h>
44
#include <ydb-cpp-sdk/client/table/table.h>
55

6-
#include <src/library/getopt/last_getopt.h>
6+
#include <library/cpp/getopt/last_getopt.h>
77

88
enum class ECommand {
99
DropIndex,

0 commit comments

Comments
 (0)