Skip to content

Commit

Permalink
Refactored yql_common (TIssue & TDecimal) (#334)
Browse files Browse the repository at this point in the history
* Refactored yql_common (TIssue & TDecimal)

* Refactor protos includes
  • Loading branch information
Gazizonoki authored Nov 8, 2024
1 parent 240e2d9 commit 07141d3
Show file tree
Hide file tree
Showing 98 changed files with 876 additions and 2,305 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ if (YDB_SDK_EXAMPLES)
endif()

if (YDB_SDK_TESTS)
add_subdirectory(tests/unit)
add_subdirectory(tests/integration)
add_subdirectory(tests)
endif()

if (YDB_SDK_INSTALL)
Expand Down
6 changes: 1 addition & 5 deletions cmake/protos_public_headers.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
src/api/grpc/draft/ydb_datastreams_v1.grpc.pb.h
src/api/grpc/draft/ydb_datastreams_v1.pb.h
src/api/grpc/ydb_topic_v1.grpc.pb.h
src/api/grpc/ydb_topic_v1.pb.h
src/api/protos/annotations/validation.pb.h
src/api/protos/draft/datastreams.pb.h
Expand All @@ -19,6 +17,4 @@ src/api/protos/ydb_issue_message.pb.h
src/api/protos/ydb_export.pb.h
src/api/protos/ydb_coordination.pb.h
src/api/protos/ydb_status_codes.pb.h
src/api/protos/draft/ydb_replication.pb.h
src/library/operation_id/protos/operation_id.pb.h
src/library/yql_common/issue/protos/issue_severity.pb.h
src/api/protos/draft/ydb_replication.pb.h
2 changes: 1 addition & 1 deletion examples/basic_example/basic_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ void StreamQuerySelect(TQueryClient client) {
}
}
}
return TStatus(EStatus::SUCCESS, NYql::TIssues());
return TStatus(EStatus::SUCCESS, NYdb::NIssue::TIssues());
}));

}
Expand Down
2 changes: 1 addition & 1 deletion include/ydb-cpp-sdk/client/datastreams/datastreams.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <ydb-cpp-sdk/client/table/table.h>

#include <src/api/grpc/draft/ydb_datastreams_v1.grpc.pb.h>
#include <src/api/grpc/draft/ydb_datastreams_v1.pb.h>

namespace NYdb::NDataStreams::V1 {

Expand Down
2 changes: 1 addition & 1 deletion include/ydb-cpp-sdk/client/discovery/discovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct TNodeInfo {

class TNodeRegistrationResult : public TStatus {
public:
TNodeRegistrationResult() : TStatus(EStatus::GENERIC_ERROR, NYql::TIssues()) {}
TNodeRegistrationResult() : TStatus(EStatus::GENERIC_ERROR, NYdb::NIssue::TIssues()) {}
TNodeRegistrationResult(TStatus&& status, const Ydb::Discovery::NodeRegistrationResult& proto);
uint32_t GetNodeId() const;
const std::string& GetDomainPath() const;
Expand Down
8 changes: 2 additions & 6 deletions include/ydb-cpp-sdk/client/draft/ydb_replication.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ namespace NYdb {
class TProtoAccessor;
}

namespace NYql {
class TIssues;
}

namespace NYdb::NReplication {

class TDescribeReplicationResult;
Expand Down Expand Up @@ -94,9 +90,9 @@ class TErrorState {
class TImpl;

public:
explicit TErrorState(NYql::TIssues&& issues);
explicit TErrorState(NYdb::NIssue::TIssues&& issues);

const NYql::TIssues& GetIssues() const;
const NYdb::NIssue::TIssues& GetIssues() const;

private:
std::shared_ptr<TImpl> Impl_;
Expand Down
4 changes: 0 additions & 4 deletions include/ydb-cpp-sdk/client/draft/ydb_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ namespace NYdb {
class TProtoAccessor;
}

namespace NYql {
class TIssues;
}

namespace NYdb::NView {

class TDescribeViewResult;
Expand Down
6 changes: 3 additions & 3 deletions include/ydb-cpp-sdk/client/types/status/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <ydb-cpp-sdk/client/types/fatal_error_handlers/handlers.h>
#include <ydb-cpp-sdk/client/types/ydb.h>

#include <ydb-cpp-sdk/library/yql_common/issue/yql_issue.h>
#include <ydb-cpp-sdk/library/issue/yql_issue.h>

#include <library/cpp/threading/future/future.h>

Expand All @@ -15,11 +15,11 @@ struct TPlainStatus;
//! Represents status of call
class TStatus {
public:
TStatus(EStatus statusCode, NYql::TIssues&& issues);
TStatus(EStatus statusCode, NYdb::NIssue::TIssues&& issues);
TStatus(TPlainStatus&& plain);

EStatus GetStatus() const;
const NYql::TIssues& GetIssues() const;
const NYdb::NIssue::TIssues& GetIssues() const;
bool IsSuccess() const;
bool IsTransportError() const;
const std::string& GetEndpoint() const;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include "yql_issue_id.h"

#include <util/generic/ptr.h>
#include <util/generic/yexception.h>
#include <util/stream/output.h>
Expand All @@ -13,11 +11,23 @@

#include <optional>
#include <vector>
#include <sstream>
#include <string>
#include <string_view>

namespace NYql {
namespace NYdb::NIssue {

using TIssueCode = uint32_t;
constexpr TIssueCode DEFAULT_ERROR = 0;
constexpr TIssueCode UNEXPECTED_ERROR = 1;

enum class ESeverity : uint32_t {
Fatal = 0,
Error = 1,
Warning = 2,
Info = 3,
};

std::string SeverityToString(ESeverity severity);

void SanitizeNonAscii(std::string& s);

Expand Down Expand Up @@ -56,37 +66,6 @@ struct TPosition {
}
};

class TTextWalker {
public:
TTextWalker(TPosition& position, bool utf8Aware)
: Position(position)
, Utf8Aware(utf8Aware)
, HaveCr(false)
, LfCount(0)
{
}

static inline bool IsUtf8Intermediate(char c) {
return (c & 0xC0) == 0x80;
}

template<typename T>
TTextWalker& Advance(const T& buf) {
for (char c : buf) {
Advance(c);
}
return *this;
}

TTextWalker& Advance(char c);

private:
TPosition& Position;
const bool Utf8Aware;
bool HaveCr;
uint32_t LfCount;
};

struct TRange {
TPosition Position;
TPosition EndPosition;
Expand Down Expand Up @@ -118,12 +97,12 @@ class TIssue;
using TIssuePtr = TIntrusivePtr<TIssue>;
class TIssue: public TThrRefBase {
std::vector<TIntrusivePtr<TIssue>> Children_;
TString Message;
std::string Message;
public:
TPosition Position;
TPosition EndPosition;
TIssueCode IssueCode = 0U;
ESeverity Severity = TSeverityIds::S_ERROR;
ESeverity Severity = ESeverity::Error;

TIssue() = default;

Expand Down Expand Up @@ -163,14 +142,7 @@ class TIssue: public TThrRefBase {
&& IssueCode == other.IssueCode;
}

ui64 Hash() const noexcept {
return CombineHashes(
CombineHashes(
(size_t)CombineHashes(IntHash(Position.Row), IntHash(Position.Column)),
std::hash<std::string>{}(Position.File)
),
(size_t)CombineHashes((size_t)IntHash(static_cast<int>(IssueCode)), std::hash<std::string>{}(Message)));
}
uint64_t Hash() const noexcept;

TIssue& SetCode(TIssueCode id, ESeverity severity) {
IssueCode = id;
Expand All @@ -197,7 +169,8 @@ class TIssue: public TThrRefBase {
}

TIssue& AddSubIssue(TIntrusivePtr<TIssue> issue) {
Severity = (ESeverity)std::min((uint32_t)issue->GetSeverity(), (uint32_t)Severity);
Severity = static_cast<ESeverity>(std::min(static_cast<uint32_t>(issue->GetSeverity()),
static_cast<uint32_t>(Severity)));
Children_.push_back(issue);
return *this;
}
Expand All @@ -215,7 +188,7 @@ class TIssue: public TThrRefBase {
}

// Unsafe method. Doesn't call SanitizeNonAscii(Message)
TString* MutableMessage() {
std::string* MutableMessage() {
return &Message;
}

Expand Down Expand Up @@ -359,20 +332,20 @@ std::optional<TPosition> TryParseTerminationMessage(std::string_view& message);
} // namespace NYql

template <>
void Out<NYql::TPosition>(IOutputStream& out, const NYql::TPosition& pos);
void Out<NYdb::NIssue::TPosition>(IOutputStream& out, const NYdb::NIssue::TPosition& pos);

template <>
void Out<NYql::TRange>(IOutputStream& out, const NYql::TRange& pos);
void Out<NYdb::NIssue::TRange>(IOutputStream& out, const NYdb::NIssue::TRange& pos);

template <>
void Out<NYql::TIssue>(IOutputStream& out, const NYql::TIssue& error);
void Out<NYdb::NIssue::TIssue>(IOutputStream& out, const NYdb::NIssue::TIssue& error);

template <>
void Out<NYql::TIssues>(IOutputStream& out, const NYql::TIssues& error);
void Out<NYdb::NIssue::TIssues>(IOutputStream& out, const NYdb::NIssue::TIssues& error);

template <>
struct THash<NYql::TIssue> {
inline size_t operator()(const NYql::TIssue& err) const {
struct THash<NYdb::NIssue::TIssue> {
inline size_t operator()(const NYdb::NIssue::TIssue& err) const {
return err.Hash();
}
};
14 changes: 0 additions & 14 deletions include/ydb-cpp-sdk/library/yql_common/issue/yql_issue_id.h

This file was deleted.

16 changes: 0 additions & 16 deletions include/ydb-cpp-sdk/library/yql_common/utils/utf8.h

This file was deleted.

6 changes: 3 additions & 3 deletions src/client/coordination/coordination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,8 @@ class TSessionContext : public TThrRefBase {
Ydb::StatusIds::StatusCode protoStatus,
const google::protobuf::RepeatedPtrField<Ydb::Issue::IssueMessage>& protoIssues) const
{
NYql::TIssues issues;
NYql::IssuesFromMessage(protoIssues, issues);
NYdb::NIssue::TIssues issues;
NYdb::NIssue::IssuesFromMessage(protoIssues, issues);
return TPlainStatus(static_cast<EStatus>(protoStatus), std::move(issues));
}

Expand All @@ -674,7 +674,7 @@ class TSessionContext : public TThrRefBase {
return TStatus(std::forward<TSource>(source));
}

TStatus MakeStatus(EStatus status, NYql::TIssues&& issues) const {
TStatus MakeStatus(EStatus status, NYdb::NIssue::TIssues&& issues) const {
return TStatus(TPlainStatus(status, std::move(issues)));
}

Expand Down
6 changes: 4 additions & 2 deletions src/client/datastreams/datastreams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
#include <src/client/impl/ydb_internal/make_request/make.h>
#undef INCLUDE_YDB_INTERNAL_H

#include <ydb-cpp-sdk/library/yql_common/issue/yql_issue.h>
#include <src/library/yql_common/issue/yql_issue_message.h>
#include <ydb-cpp-sdk/library/issue/yql_issue.h>
#include <src/library/issue/yql_issue_message.h>

#include <src/client/common_client/impl/client.h>

#include <src/api/grpc/draft/ydb_datastreams_v1.grpc.pb.h>

namespace NYdb::NDataStreams::V1 {

TPartitioningSettingsBuilder<TCreateStreamSettings> TCreateStreamSettings::BeginConfigurePartitioningSettings() {
Expand Down
19 changes: 9 additions & 10 deletions src/client/draft/ydb_replication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <src/client/impl/ydb_internal/make_request/make.h>
#undef INCLUDE_YDB_INTERNAL_H

#include <ydb-cpp-sdk/library/yql_common/issue/yql_issue.h>
#include <src/library/yql_common/issue/yql_issue_message.h>
#include <ydb-cpp-sdk/library/issue/yql_issue.h>
#include <src/library/issue/yql_issue_message.h>
#include <src/api/grpc/draft/ydb_replication_v1.grpc.pb.h>
#include <src/client/common_client/impl/client.h>
#include <ydb-cpp-sdk/client/proto/accessor.h>
Expand Down Expand Up @@ -93,27 +93,26 @@ const TStats& TRunningState::GetStats() const {

class TErrorState::TImpl {
public:
NYql::TIssues Issues;
NYdb::NIssue::TIssues Issues;

explicit TImpl(NYql::TIssues&& issues)
explicit TImpl(NYdb::NIssue::TIssues&& issues)
: Issues(std::move(issues))
{
}
};

TErrorState::TErrorState(NYql::TIssues&& issues)
TErrorState::TErrorState(NYdb::NIssue::TIssues&& issues)
: Impl_(std::make_shared<TImpl>(std::move(issues)))
{
}

const NYql::TIssues& TErrorState::GetIssues() const {
const NYdb::NIssue::TIssues& TErrorState::GetIssues() const {
return Impl_->Issues;
}

template <typename T>
NYql::TIssues IssuesFromMessage(const ::google::protobuf::RepeatedPtrField<T>& message) {
NYql::TIssues issues;
NYql::IssuesFromMessage<T>(message, issues);
NYdb::NIssue::TIssues IssuesFromMessage(const ::google::protobuf::RepeatedPtrField<Ydb::Issue::IssueMessage>& message) {
NYdb::NIssue::TIssues issues;
NYdb::NIssue::IssuesFromMessage(message, issues);
return issues;
}

Expand Down
4 changes: 2 additions & 2 deletions src/client/draft/ydb_scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class TYqlResultPartIterator::TReaderImpl {
self->Finished_ = true;
promise.SetValue({ TStatus(TPlainStatus(grpcStatus, self->Endpoint_)) });
} else {
NYql::TIssues issues;
NYql::IssuesFromMessage(self->Response_.issues(), issues);
NYdb::NIssue::TIssues issues;
NYdb::NIssue::IssuesFromMessage(self->Response_.issues(), issues);
EStatus clientStatus = static_cast<EStatus>(self->Response_.status());
TPlainStatus plainStatus{ clientStatus, std::move(issues), self->Endpoint_, {} };
TStatus status{ std::move(plainStatus) };
Expand Down
2 changes: 1 addition & 1 deletion src/client/federated_topic/impl/federated_read_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ std::vector<TReadSessionEvent::TEvent> TFederatedReadSessionImpl::GetEvents(bool
{
std::lock_guard guard(Lock);
if (Closing) {
return {NTopic::TSessionClosedEvent(FederationState->Status.GetStatus(), NYql::TIssues(FederationState->Status.GetIssues()))};
return {NTopic::TSessionClosedEvent(FederationState->Status.GetStatus(), NYdb::NIssue::TIssues(FederationState->Status.GetIssues()))};
}
// TODO!!! handle aborting or closing state
// via handler on SessionClosedEvent {
Expand Down
Loading

0 comments on commit 07141d3

Please sign in to comment.