sql_call_expr.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #pragma once
  2. #include "sql_translation.h"
  3. namespace NSQLTranslationV1 {
  4. TNodePtr BuildSqlCall(TContext& ctx, TPosition pos, const TString& module, const TString& name, const TVector<TNodePtr>& args,
  5. TNodePtr positionalArgs, TNodePtr namedArgs, TNodePtr customUserType, const TDeferredAtom& typeConfig, TNodePtr runConfig);
  6. using namespace NSQLv1Generated;
  7. class TSqlCallExpr: public TSqlTranslation {
  8. public:
  9. TSqlCallExpr(TContext& ctx, NSQLTranslation::ESqlMode mode)
  10. : TSqlTranslation(ctx, mode)
  11. {
  12. }
  13. TSqlCallExpr(const TSqlCallExpr& call, const TVector<TNodePtr>& args)
  14. : TSqlTranslation(call.Ctx, call.Mode)
  15. , Pos(call.Pos)
  16. , Func(call.Func)
  17. , Module(call.Module)
  18. , Node(call.Node)
  19. , Args(args)
  20. , AggMode(call.AggMode)
  21. , DistinctAllowed(call.DistinctAllowed)
  22. , UsingCallExpr(call.UsingCallExpr)
  23. , IsExternalCall(call.IsExternalCall)
  24. , CallConfig(call.CallConfig)
  25. {
  26. }
  27. void AllowDistinct() {
  28. DistinctAllowed = true;
  29. }
  30. void InitName(const TString& name);
  31. void InitExpr(const TNodePtr& expr);
  32. bool Init(const TRule_using_call_expr& node);
  33. bool Init(const TRule_value_constructor& node);
  34. bool Init(const TRule_invoke_expr& node);
  35. bool ConfigureExternalCall(const TRule_external_call_settings& node);
  36. void IncCounters();
  37. TNodePtr BuildUdf(bool forReduce);
  38. TNodePtr BuildCall();
  39. TPosition GetPos() const {
  40. return Pos;
  41. }
  42. const TVector<TNodePtr>& GetArgs() const {
  43. return Args;
  44. }
  45. void SetOverWindow() {
  46. YQL_ENSURE(AggMode == EAggregateMode::Normal);
  47. AggMode = EAggregateMode::OverWindow;
  48. }
  49. void SetOverWindowDistinct() {
  50. YQL_ENSURE(AggMode == EAggregateMode::Distinct);
  51. AggMode = EAggregateMode::OverWindowDistinct;
  52. }
  53. void SetIgnoreNulls() {
  54. Func += "_IgnoreNulls";
  55. }
  56. bool IsExternal() {
  57. return IsExternalCall;
  58. }
  59. private:
  60. bool ExtractCallParam(const TRule_external_call_param& node);
  61. bool FillArg(const TString& module, const TString& func, size_t& idx, const TRule_named_expr& node);
  62. bool FillArgs(const TRule_named_expr_list& node);
  63. private:
  64. TPosition Pos;
  65. TString Func;
  66. TString Module;
  67. TNodePtr Node;
  68. TVector<TNodePtr> Args;
  69. TVector<TNodePtr> PositionalArgs;
  70. TVector<TNodePtr> NamedArgs;
  71. EAggregateMode AggMode = EAggregateMode::Normal;
  72. TString WindowName;
  73. bool DistinctAllowed = false;
  74. bool UsingCallExpr = false;
  75. bool IsExternalCall = false;
  76. TFunctionConfig CallConfig;
  77. };
  78. } // namespace NSQLTranslationV1