mkql_check_args.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #include "mkql_check_args.h"
  2. #include <yql/essentials/minikql/mkql_node_builder.h>
  3. namespace NKikimr {
  4. namespace NMiniKQL {
  5. TBinaryFunctionArgsDesc CheckBinaryFunctionArgs(
  6. TType* left, TType* right,
  7. bool allowOptionalInput, bool requiresBooleanArgs)
  8. {
  9. TBinaryFunctionArgsDesc desc;
  10. const auto& leftType = UnpackOptional(left, desc.IsLeftOptional);
  11. MKQL_ENSURE(leftType->IsData(), "Expected data");
  12. const auto& rightType = UnpackOptional(right, desc.IsRightOptional);
  13. MKQL_ENSURE(rightType->IsData(), "Expected data");
  14. if (!allowOptionalInput) {
  15. MKQL_ENSURE(!desc.IsLeftOptional && !desc.IsRightOptional,
  16. "Optional are not expected here");
  17. }
  18. const auto& leftDataType = static_cast<const TDataType&>(*leftType);
  19. const auto& rightDataType = static_cast<const TDataType&>(*rightType);
  20. MKQL_ENSURE(leftDataType.GetSchemeType() == rightDataType.GetSchemeType(),
  21. "Mismatch data types");
  22. desc.SchemeType = leftDataType.GetSchemeType();
  23. if (requiresBooleanArgs) {
  24. MKQL_ENSURE(desc.SchemeType == NUdf::TDataType<bool>::Id, "Expected bool");
  25. }
  26. return desc;
  27. }
  28. }
  29. }