aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/minikql/comp_nodes/mkql_check_args.cpp
blob: 279b03252456c889ec596be201a986f27518b0ad (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
#include "mkql_check_args.h"
#include <yql/essentials/minikql/mkql_node_builder.h>

namespace NKikimr {
namespace NMiniKQL {

TBinaryFunctionArgsDesc CheckBinaryFunctionArgs(
        TType* left, TType* right,
        bool allowOptionalInput, bool requiresBooleanArgs)
{
    TBinaryFunctionArgsDesc desc;
    const auto& leftType = UnpackOptional(left, desc.IsLeftOptional);
    MKQL_ENSURE(leftType->IsData(), "Expected data");

    const auto& rightType = UnpackOptional(right, desc.IsRightOptional);
    MKQL_ENSURE(rightType->IsData(), "Expected data");

    if (!allowOptionalInput) {
        MKQL_ENSURE(!desc.IsLeftOptional && !desc.IsRightOptional,
                    "Optional are not expected here");
    }

    const auto& leftDataType = static_cast<const TDataType&>(*leftType);
    const auto& rightDataType = static_cast<const TDataType&>(*rightType);
    MKQL_ENSURE(leftDataType.GetSchemeType() == rightDataType.GetSchemeType(),
                "Mismatch data types");

    desc.SchemeType = leftDataType.GetSchemeType();
    if (requiresBooleanArgs) {
        MKQL_ENSURE(desc.SchemeType == NUdf::TDataType<bool>::Id, "Expected bool");
    }
    return desc;
}

}
}