summaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/result.h
blob: 0b356ef5c2a52e4bc933e1faf8651941d0d3f108 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once

#include <yql/essentials/utils/yql_panic.h>

#include <expected>
#include <variant>

namespace NSQLTranslationV1 {

class TContext;

template <class TPtr>
class TNullable final: public TPtr {
public:
    // Every pointer is nullable
    // NOLINTNEXTLINE(google-explicit-constructor)
    TNullable(TPtr ptr)
        : TPtr(std::move(ptr))
    {
    }
};

template <class TPtr>
class TNonNull final: public TPtr {
public:
    explicit TNonNull(TPtr ptr)
        : TPtr(std::move(ptr))
    {
        YQL_ENSURE(*static_cast<TPtr*>(this));
    }

    operator bool() = delete;
};

enum class ESQLError {
    Basic,
    UnsupportedYqlSelect,
};

std::unexpected<ESQLError> UnsupportedYqlSelect(TContext& ctx, TStringBuf message);

template <class T>
using TSQLResult = std::expected<T, ESQLError>;

using TSQLStatus = TSQLResult<std::monostate>;

template <class T>
bool IsUnwrappable(const TSQLResult<T>& result) {
    return result || result.error() == ESQLError::Basic;
}

template <class T>
void EnsureUnwrappable(const TSQLResult<T>& result) {
    YQL_ENSURE(
        IsUnwrappable(result),
        "Expected "
            << "at most " << ESQLError::Basic << " error, "
            << "but got " << result.error());
}

bool Unwrap(TSQLStatus status);

} // namespace NSQLTranslationV1