hqllib.ipp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*##############################################################################
  2. Copyright (C) 2011 HPCC Systems.
  3. All rights reserved. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ############################################################################## */
  14. #ifndef __HQLLIB_IPP_
  15. #define __HQLLIB_IPP_
  16. #include "hqlhtcpp.ipp"
  17. #include "hqlecl.hpp"
  18. class HqlCppLibrary : public CInterface
  19. {
  20. public:
  21. HqlCppLibrary(HqlCppTranslator & _translator, IHqlExpression * libraryInterface, ClusterType _clusterType);
  22. unsigned numStreamedInputs() const { return streamedCount; }
  23. unsigned totalInputs() const { return inputMapper.numParameters(); }
  24. unsigned getInterfaceHash() const;
  25. unsigned queryOutputIndex(_ATOM name) const;
  26. IHqlExpression * queryParameter(unsigned i) { return &inputMapper.queryRealParameters().item(i); }
  27. protected:
  28. void extractOutputs();
  29. unsigned getHash(const HqlExprArray & values, unsigned crc) const;
  30. public:
  31. HqlCppTranslator & translator;
  32. LinkedHqlExpr libraryInterface;
  33. IHqlExpression * scopeExpr;
  34. ClusterType clusterType;
  35. unsigned streamedCount;
  36. LibraryInputMapper inputMapper;
  37. HqlExprArray outputs; // Only the names and types are significant, not the values
  38. bool allowStreamingInputs;
  39. };
  40. class HqlCppLibraryImplementation : public HqlCppLibrary
  41. {
  42. public:
  43. HqlCppLibraryImplementation(HqlCppTranslator & _translator, IHqlExpression * libraryInterface, IHqlExpression * libraryId, ClusterType _clusterType);
  44. void mapLogicalToImplementation(HqlExprArray & exprs, IHqlExpression * libraryExpr);
  45. unsigned numResultsUsed() { return numStreamedInputs() + outputs.ordinality(); }
  46. IHqlExpression * queryInputExpr(unsigned i) { return &inputExprs.item(i); }
  47. public:
  48. LinkedHqlExpr libraryId;
  49. HqlExprArray inputExprs;
  50. HqlExprArray logicalParams;
  51. };
  52. class HqlCppLibraryInstance : public CInterface
  53. {
  54. public:
  55. HqlCppLibraryInstance(HqlCppTranslator & _translator, IHqlExpression * libraryInstance, ClusterType _clusterType);
  56. unsigned numStreamedInputs() { return library->numStreamedInputs(); }
  57. unsigned numParameters() { return libraryFuncdef->queryChild(1)->numChildren(); }
  58. IHqlExpression * queryActual(unsigned i) { return instanceExpr->queryChild(i); }
  59. IHqlExpression * queryParameter(unsigned i) { return libraryFuncdef->queryChild(1)->queryChild(i); }
  60. public:
  61. Owned<HqlCppLibrary> library;
  62. LinkedHqlExpr instanceExpr;
  63. IHqlExpression * libraryFuncdef;
  64. };
  65. class ThorBoundLibraryActivity : public ThorBoundActivity
  66. {
  67. public:
  68. ThorBoundLibraryActivity(ABoundActivity * activity, IPropertyTree * _graphNode, HqlCppLibraryInstance * _libraryInstance)
  69. : ThorBoundActivity(activity->queryDataset(), activity->queryBound(), activity->queryActivityId(), activity->queryContainerId(), activity->queryGraphId(), activity->queryActivityKind())
  70. {
  71. graphNode.set(_graphNode);
  72. libraryInstance.set(_libraryInstance);
  73. }
  74. void noteOutputUsed(_ATOM name);
  75. public:
  76. Linked<IPropertyTree> graphNode;
  77. Linked<HqlCppLibraryInstance> libraryInstance;
  78. };
  79. #endif