mkql_node_builder.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #pragma once
  2. #include "defs.h"
  3. #include "mkql_node.h"
  4. namespace NKikimr {
  5. namespace NMiniKQL {
  6. TDataLiteral* BuildDataLiteral(const NUdf::TStringRef& data, NUdf::TDataTypeId type, const TTypeEnvironment& env);
  7. inline TDataLiteral* BuildDataLiteral(const NUdf::TStringRef& data, NUdf::EDataSlot slot, const TTypeEnvironment& env) {
  8. return BuildDataLiteral(data, NUdf::GetDataTypeInfo(slot).TypeId, env);
  9. }
  10. TDataLiteral* BuildDataLiteral(const NUdf::TUnboxedValuePod& value, NUdf::TDataTypeId type, const TTypeEnvironment& env);
  11. inline TDataLiteral* BuildDataLiteral(const NUdf::TUnboxedValuePod& value, NUdf::EDataSlot slot, const TTypeEnvironment& env) {
  12. return BuildDataLiteral(value, NUdf::GetDataTypeInfo(slot).TypeId, env);
  13. }
  14. TOptionalLiteral* BuildOptionalLiteral(TRuntimeNode value, const TTypeEnvironment& env);
  15. TOptionalLiteral* BuildEmptyOptionalLiteral(TType* itemType, const TTypeEnvironment& env);
  16. TOptionalLiteral* BuildEmptyOptionalDataLiteral(NUdf::TDataTypeId schemeType, const TTypeEnvironment& env);
  17. TType* UnpackOptional(TRuntimeNode data, bool& isOptional);
  18. TType* UnpackOptional(TType* type, bool& isOptional);
  19. TDataType* UnpackOptionalData(TRuntimeNode data, bool& isOptional);
  20. TDataType* UnpackOptionalData(TType* type, bool& isOptional);
  21. TBlockType::EShape GetResultShape(const TVector<TType*>& types);
  22. class TTupleLiteralBuilder {
  23. public:
  24. TTupleLiteralBuilder(const TTypeEnvironment& env);
  25. TTupleLiteralBuilder(const TTupleLiteralBuilder&) = default;
  26. TTupleLiteralBuilder& operator=(const TTupleLiteralBuilder&) = default;
  27. void Reserve(ui32 size);
  28. TTupleLiteralBuilder& Add(TRuntimeNode value);
  29. TTupleLiteral* Build();
  30. void Clear();
  31. private:
  32. const TTypeEnvironment& Env;
  33. TVector<TType*> Types;
  34. TVector<TRuntimeNode> Values;
  35. };
  36. class TStructTypeBuilder {
  37. public:
  38. TStructTypeBuilder(const TTypeEnvironment& env);
  39. TStructTypeBuilder(const TStructTypeBuilder&) = default;
  40. TStructTypeBuilder& operator=(const TStructTypeBuilder&) = default;
  41. void Reserve(ui32 size);
  42. TStructTypeBuilder& Add(const TStringBuf& name, TType* type, ui32* index = nullptr);
  43. TStructType* Build();
  44. void FillIndexes();
  45. void Clear();
  46. private:
  47. const TTypeEnvironment* Env;
  48. TVector<TStructMember> Members;
  49. };
  50. class TListLiteralBuilder {
  51. public:
  52. TListLiteralBuilder(const TTypeEnvironment& env, TType* type);
  53. TListLiteralBuilder(const TListLiteralBuilder&) = default;
  54. TListLiteralBuilder& operator=(const TListLiteralBuilder&) = default;
  55. TListLiteralBuilder& Add(TRuntimeNode item);
  56. TListLiteral* Build();
  57. void Clear();
  58. private:
  59. const TTypeEnvironment* Env;
  60. TType* Type;
  61. TVector<TRuntimeNode> Items;
  62. };
  63. class TStructLiteralBuilder {
  64. public:
  65. TStructLiteralBuilder(const TTypeEnvironment& env);
  66. TStructLiteralBuilder(const TStructLiteralBuilder&) = default;
  67. TStructLiteralBuilder& operator=(const TStructLiteralBuilder&) = default;
  68. void Reserve(ui32 size);
  69. TStructLiteralBuilder& Add(const TStringBuf& name, TRuntimeNode value);
  70. TStructLiteral* Build();
  71. void Clear();
  72. private:
  73. const TTypeEnvironment* Env;
  74. TVector<TStructMember> Members;
  75. TVector<TRuntimeNode> Values;
  76. };
  77. class TDictLiteralBuilder {
  78. public:
  79. TDictLiteralBuilder(const TTypeEnvironment& env, TType* keyType, TType* payloadType);
  80. TDictLiteralBuilder(const TDictLiteralBuilder&) = default;
  81. TDictLiteralBuilder& operator=(const TDictLiteralBuilder&) = default;
  82. void Reserve(ui32 size);
  83. TDictLiteralBuilder& Add(TRuntimeNode key, TRuntimeNode payload);
  84. TDictLiteral* Build();
  85. void Clear();
  86. private:
  87. const TTypeEnvironment* Env;
  88. TType* KeyType;
  89. TType* PayloadType;
  90. TVector<std::pair<TRuntimeNode, TRuntimeNode>> Items;
  91. };
  92. class TCallableTypeBuilder {
  93. public:
  94. TCallableTypeBuilder(const TTypeEnvironment& env, const TStringBuf& name, TType* returnType);
  95. TCallableTypeBuilder(const TCallableTypeBuilder&) = default;
  96. TCallableTypeBuilder& operator=(const TCallableTypeBuilder&) = default;
  97. void Reserve(ui32 size);
  98. TCallableTypeBuilder& Add(TType* time);
  99. TCallableTypeBuilder& SetArgumentName(const TStringBuf& name);
  100. TCallableTypeBuilder& SetArgumentFlags(ui64 flags);
  101. TCallableTypeBuilder& SetOptionalArgs(ui32 count);
  102. TCallableTypeBuilder& SetPayload(const TStringBuf& data);
  103. TCallableType* Build();
  104. void Clear();
  105. private:
  106. const TTypeEnvironment* Env;
  107. TInternName Name;
  108. TType* ReturnType;
  109. TVector<TType*> Arguments;
  110. ui32 OptionalArgsCount;
  111. TVector<TStringBuf> ArgNames;
  112. TVector<ui64> ArgFlags;
  113. TStringBuf FuncPayload;
  114. bool HasPayload;
  115. };
  116. class TCallableBuilder {
  117. public:
  118. TCallableBuilder(const TTypeEnvironment& env, const TStringBuf& name, TType* returnType,
  119. bool disableMerge = false);
  120. TCallableBuilder(const TCallableBuilder&) = default;
  121. TCallableBuilder& operator=(const TCallableBuilder&) = default;
  122. void Reserve(ui32 size);
  123. TCallableBuilder& Add(TRuntimeNode input);
  124. TCallableBuilder& SetArgumentName(const TStringBuf& name);
  125. TCallableBuilder& SetArgumentFlags(ui64 flags);
  126. TCallableBuilder& SetOptionalArgs(ui32 count);
  127. TCallableBuilder& SetTypePayload(const TStringBuf& data);
  128. TCallable* Build();
  129. void Clear();
  130. private:
  131. const TTypeEnvironment* Env;
  132. TInternName Name;
  133. TType* ReturnType;
  134. bool DisableMerge;
  135. TVector<TType*> Arguments;
  136. TVector<TRuntimeNode> Inputs;
  137. ui32 OptionalArgsCount;
  138. TVector<TStringBuf> ArgNames;
  139. TVector<ui64> ArgFlags;
  140. TStringBuf FuncPayload;
  141. bool HasPayload;
  142. };
  143. }
  144. }