sql_call_expr.h 2.4 KB

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