aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/minikql/computation/presort.h
blob: b8fc93333cf29990c619ab64415c034a003da018 (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
64
65
66
67
68
69
#pragma once

#include <yql/essentials/minikql/mkql_node.h>

#include <yql/essentials/public/udf/udf_value.h>

#include <util/generic/vector.h>

namespace NKikimr {
namespace NMiniKQL {

class TPresortCodec {
public:
    TPresortCodec() = default;

    struct TTypeInfo {
        NUdf::EDataSlot Slot;
        bool IsOptional;
        bool IsDesc;
    };

    void AddType(NUdf::EDataSlot slot, bool isOptional = false, bool isDesc = false);

protected:
    size_t Current = 0;
    TVector<TTypeInfo> Types;
};

class TPresortEncoder : public TPresortCodec {
public:
    TPresortEncoder() = default;

    void Start();
    void Start(TStringBuf prefix);
    void Encode(const NUdf::TUnboxedValuePod& value);
    TStringBuf Finish(); // user must copy

private:
    TVector<ui8> Output;
};

class TPresortDecoder : public TPresortCodec {
public:
    TPresortDecoder() = default;

    void Start(TStringBuf input);
    NUdf::TUnboxedValue Decode();
    void Finish();

private:
    TVector<ui8> Buffer;
    TStringBuf Input;
};

class THolderFactory;

class TGenericPresortEncoder {
public:
    TGenericPresortEncoder(TType* type);
    TStringBuf Encode(const NUdf::TUnboxedValue& value, bool desc); // user must copy
    NUdf::TUnboxedValue Decode(TStringBuf buf, bool desc, const THolderFactory& factory);
private:
    TType* Type;
    TVector<ui8> Output;
    TVector<ui8> Buffer;
};

} // NMiniKQL
} // NKikimr