ECLFunction.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2014 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef ECLFUNCTION_HPP_
  14. #define ECLFUNCTION_HPP_
  15. #include "ws_sql.hpp"
  16. #include "ws_sql_esp.ipp"
  17. #define AGGREGATE_FUNCTION_TYPE 1
  18. #define CONTENT_MODIFIER_FUNCTION_TYPE 2
  19. #define COUNT_FUNCTION "COUNT"
  20. #define MAX_FUNCTION "MAX"
  21. #define MIN_FUNCTION "MIN"
  22. #define SUM_FUNCTION "SUM"
  23. #define AVG_FUNCTION "AVG"
  24. #define UPPER_FUNCTION "UPPER"
  25. #define LOWER_FUNCTION "LOWER"
  26. struct ECLFunctionDefCfg
  27. {
  28. const char * name;
  29. bool acceptsWildCard;
  30. const char * returnType;
  31. bool acceptsMultipleInputs;
  32. bool acceptsEmptyInput;
  33. int functionType;
  34. const char * eclFunctionName;
  35. bool returnsSameAsArgumentType;
  36. ECLFunctionDefCfg()
  37. {
  38. name = "";
  39. acceptsWildCard = false;
  40. returnType = "";
  41. acceptsMultipleInputs = false;
  42. acceptsEmptyInput = false;
  43. functionType = -1;
  44. eclFunctionName = "";
  45. returnsSameAsArgumentType = false;
  46. }
  47. ECLFunctionDefCfg( const char * n, bool awc, const char * rt, bool ami, bool aei, int ft, const char * efn, bool rsaat)
  48. {
  49. name = n;
  50. acceptsWildCard = awc;
  51. returnType = rt;
  52. acceptsMultipleInputs = ami;
  53. acceptsEmptyInput = aei;
  54. functionType = ft;
  55. eclFunctionName = efn;
  56. returnsSameAsArgumentType = rsaat;
  57. }
  58. };
  59. /*
  60. typedef enum ECLFunctionDefs_
  61. {
  62. UnknownECLFunc = -1,
  63. CountECLFunc = 0,
  64. MaxECLFunc = 1,
  65. MinECLFunc = 2,
  66. SumECLFunc = 3,
  67. AvgECLFunc = 4,
  68. UpperECLFunc = 5,
  69. LowerECLFunc = 6,
  70. ECLFuncMax = 7
  71. } EclFunctionDef;
  72. */
  73. class ECLFunctions
  74. {
  75. public:
  76. ECLFunctions();
  77. virtual ~ECLFunctions();
  78. static void init();
  79. static ECLFunctionDefCfg getEclFuntionDef(const char * funcname)
  80. {
  81. if (!funcsinited)
  82. {
  83. init();
  84. }
  85. if (funcname && strlen(funcname)>0)
  86. {
  87. StringBuffer fnnameupper(funcname);
  88. if (eclfuncstable.count(fnnameupper.toUpperCase().str()))
  89. return eclfuncstable.find(fnnameupper.toUpperCase().str())->second;
  90. }
  91. throw MakeStringException(-1, "Invalid ECL function: %s", funcname);
  92. }
  93. static bool funcsinited;
  94. static std::map<std::string,ECLFunctionDefCfg> eclfuncstable;
  95. };
  96. #endif /* ECLFUNCTION_HPP_ */